Skip to content

Commit

Permalink
clean up (#4620)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlazerMann committed May 18, 2024
1 parent eae5821 commit 507caaf
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 78 deletions.
2 changes: 1 addition & 1 deletion WikipediaBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public static function resultsGood(?object $result): bool {
public static function category_members(string $cat): array {
$list = [];
$vars = [
"cmtitle" => "Category:$cat", // Don't urlencode.
"cmtitle" => "Category:{$cat}", // Don't urlencode.
"action" => "query",
"cmlimit" => "500",
"list" => "categorymembers",
Expand Down
2 changes: 1 addition & 1 deletion expandFns.php
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ function throttle(): void {
}
if ($time_since_last_write < $min_interval) {
$time_to_pause = (int) floor($min_interval - $time_since_last_write); // @codeCoverageIgnore
report_info("Throttling: waiting $time_to_pause seconds..."); // @codeCoverageIgnore
report_info("Throttling: waiting {$time_to_pause} seconds..."); // @codeCoverageIgnore
sleep($time_to_pause); // @codeCoverageIgnore
}
$last_write_time = time();
Expand Down
3 changes: 1 addition & 2 deletions generate_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
set_time_limit(120);

// usage: https://citations.toolforge.org/generate_template.php?doi=<DOI> and such

require_once 'html_headers.php';
// We do not include html_headers.php, since this should be cachable

echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Make a Template</title></head><body><main><pre>';

Expand Down
4 changes: 2 additions & 2 deletions gitpull.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Git Pull</title></head><body><main><pre>';

clearstatcache();
if (@mkdir('git_pull.lock', 0700)) {
if (mkdir('git_pull.lock', 0700)) {
/** @psalm-suppress ForbiddenCode */
echo htmlspecialchars((string) shell_exec("(/usr/bin/git fetch --all; /usr/bin/git reset --hard origin/master) 2>&1"), ENT_QUOTES);
rmdir('git_pull.lock');
} else {
sleep(2);
echo 'try again';
echo 'Please try again';
}
echo '</pre></main></body></html>';
?>
12 changes: 6 additions & 6 deletions html_headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

@header('Cache-Control: no-store, private');
@header('Content-type: text/html; charset=utf-8');
@header('Expires: 0');
@header('Pragma: no-cache');
@header('X-Accel-Buffering: no');
@header('X-Accel-Expires: 0');
header('Cache-Control: no-store, private');
header('Content-type: text/html; charset=utf-8');
header('Expires: 0');
header('Pragma: no-cache');
header('X-Accel-Buffering: no');
header('X-Accel-Expires: 0');
8 changes: 4 additions & 4 deletions kill_big_job.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

ob_implicit_flush(true);
set_time_limit(120);
@session_start(['read_and_close' => true]);
session_start(['read_and_close' => true]);

require_once 'html_headers.php';
require_once 'big_jobs.php';

if (!isset($_SESSION['citation_bot_user_id'])) {
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>You are not logged in</pre></main></body></html>';
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>You are not logged in</pre></main></body></html>';
} elseif (!big_jobs_kill()) {
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>No exiting large job found</pre></main></body></html>';
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>No exiting large job found</pre></main></body></html>';
} else {
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>Existing large job flagged for stopping</pre></main></body></html>';
echo '<!DOCTYPE html><html lang="en" dir="ltr"><head><title>Killing the big job</title></head><body><main><pre>Existing large job flagged for stopping</pre></main></body></html>';
}
?>
36 changes: 18 additions & 18 deletions linked_pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set_time_limit(120);

@session_start(['read_and_close' => true]);
session_start(['read_and_close' => true]);

require_once 'html_headers.php';
require_once 'setup.php';
Expand All @@ -16,40 +16,40 @@
check_blocked();

if (is_string(@$_POST['linkpage'])) {
$page_name = $_POST['linkpage'];
$page_name = $_POST['linkpage'];
} else {
report_warning(' Error in passing of linked page name ');
bot_html_footer();
exit;
report_warning(' Error in passing of linked page name ');
bot_html_footer();
exit;
}

$page_name = str_replace(' ', '_', trim($page_name));
if ($page_name === '') {
report_warning('Nothing requested on webform -- OR -- page name got lost during initial authorization ');
bot_html_footer();
exit;
report_warning('Nothing requested on webform -- OR -- page name got lost during initial authorization ');
bot_html_footer();
exit;
} elseif (substr($page_name, 0, 5) !== 'User:' && !in_array($api->get_the_user(), ['Headbomb', 'AManWithNoPlan'], true)) { // Do not let people run willy-nilly
report_warning('API only intended for User generated pages for fixing specific issues ');
bot_html_footer();
exit;
report_warning('API only intended for User generated pages for fixing specific issues ');
bot_html_footer();
exit;
}

$edit_summary_end = "| Suggested by " . $api->get_the_user() . " | Linked from $page_name | #UCB_webform_linked ";
$edit_summary_end = "| Suggested by " . $api->get_the_user() . " | Linked from {$page_name} | #UCB_webform_linked ";

$json = WikipediaBot::get_links($page_name);
unset($page_name);

if ($json === '') {
report_warning(' Error getting page list');
bot_html_footer();
exit;
report_warning(' Error getting page list');
bot_html_footer();
exit;
}
$array = @json_decode($json, true);
unset($json);
if ($array === false || !isset($array['parse']['links']) || !is_array($array['parse']['links'])) {
report_warning(' Error interpreting page list - perhaps page requested does not even exist');
bot_html_footer();
exit;
report_warning(' Error interpreting page list - perhaps page requested does not even exist');
bot_html_footer();
exit;
}
$links = $array['parse']['links']; // @phan-suppress-current-line PhanTypeArraySuspiciousNullable
unset($array);
Expand Down
88 changes: 44 additions & 44 deletions process_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,70 @@
declare(strict_types=1);

set_time_limit(120);
@session_start(['read_and_close' => true]);
session_start(['read_and_close' => true]);

require_once 'html_headers.php';
require_once 'setup.php';

$api = new WikipediaBot();

if (HTML_OUTPUT) {
bot_html_header();
$edit_summary_end = "| Suggested by " . $api->get_the_user() . " ";
bot_html_header();
$edit_summary_end = "| Suggested by " . $api->get_the_user() . " ";
} else {
$edit_summary_end = ""; // Command line edits as the person
$edit_summary_end = ""; // Command line edits as the person
}

check_blocked();

if (isset($argv[1])) {
$pages = $argv[1];
if (in_array($pages, ['page_list.txt', 'page_list2.txt'])) {
$pages = trim((string) @file_get_contents($pages));
}
$pages = $argv[1];
if (in_array($pages, ['page_list.txt', 'page_list2.txt'])) {
$pages = trim((string) @file_get_contents($pages));
}
} elseif (isset($_GET["page"])) {
$pages = $_GET["page"];
if (!is_string($pages)) {
report_warning('Non-string found in GET for page.');
$pages = '';
}
if (strpos($pages, '|') !== false) {
report_warning('Use the webform for multiple pages.');
$pages = '';
}
$pages = $_GET["page"];
if (!is_string($pages)) {
report_warning('Non-string found in GET for page.');
$pages = '';
}
if (strpos($pages, '|') !== false) {
report_warning('Use the webform for multiple pages.');
$pages = '';
}
} elseif (isset($_POST["page"])) {
$pages = $_POST["page"];
if (!is_string($pages)) {
report_warning('Non-string found in POST for page.');
$pages = '';
}
$pages = $_POST["page"];
if (!is_string($pages)) {
report_warning('Non-string found in POST for page.');
$pages = '';
}
} else {
report_warning('Nothing requested -- OR -- pages got lost during initial authorization ');
$pages = '';
report_warning('Nothing requested -- OR -- pages got lost during initial authorization ');
$pages = '';
}

if (isset($_REQUEST["edit"]) && $_REQUEST["edit"]) {
if ($_REQUEST["edit"] === 'automated_tools') {
$edit_summary_end .= "| #UCB_automated_tools ";
} elseif ($_REQUEST["edit"] === 'toolbar') {
$edit_summary_end .= "| #UCB_toolbar ";
} elseif ($_REQUEST["edit"] === 'webform') {
$edit_summary_end .= "| #UCB_webform ";
} elseif ($_REQUEST["edit"] === 'Headbomb') {
$edit_summary_end .= "| #UCB_Headbomb ";
} elseif ($_REQUEST["edit"] === 'Smith609') {
$edit_summary_end .= "| #UCB_Smith609 ";
} elseif ($_REQUEST["edit"] === 'arXiv') {
$edit_summary_end .= "| #UCB_arXiv ";
} else {
$edit_summary_end .= "| #UCB_Other ";
}
if ($_REQUEST["edit"] === 'automated_tools') {
$edit_summary_end .= "| #UCB_automated_tools ";
} elseif ($_REQUEST["edit"] === 'toolbar') {
$edit_summary_end .= "| #UCB_toolbar ";
} elseif ($_REQUEST["edit"] === 'webform') {
$edit_summary_end .= "| #UCB_webform ";
} elseif ($_REQUEST["edit"] === 'Headbomb') {
$edit_summary_end .= "| #UCB_Headbomb ";
} elseif ($_REQUEST["edit"] === 'Smith609') {
$edit_summary_end .= "| #UCB_Smith609 ";
} elseif ($_REQUEST["edit"] === 'arXiv') {
$edit_summary_end .= "| #UCB_arXiv ";
} else {
$edit_summary_end .= "| #UCB_Other ";
}
} else {
if (HTML_OUTPUT) {
$edit_summary_end .= "| #UCB_webform ";
} else {
$edit_summary_end .= "| #UCB_CommandLine ";
}
if (HTML_OUTPUT) {
$edit_summary_end .= "| #UCB_webform ";
} else {
$edit_summary_end .= "| #UCB_CommandLine ";
}
}

$pages_to_do = array_unique(explode('|', $pages));
Expand Down

0 comments on commit 507caaf

Please sign in to comment.