forked from ms609/citation-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
78 lines (69 loc) · 2.46 KB
/
category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
set_time_limit(120);
@session_start(['read_and_close' => true]);
require_once 'html_headers.php';
require_once 'setup.php';
const GET_IS_OKAY = [
'CS1 maint: PMC format',
'CS1 maint: date format',
'CS1 maint: MR format',
'CS1 maint: bibcode',
'CS1 maint: PMC embargo expired',
'CS1 maint: extra punctuation',
'CS1 maint: unflagged free DOI',
'Articles with missing Cite arXiv inputs',
'CS1 errors: DOI',
'CS1 errors: dates',
'CS1 errors: extra text: edition',
'CS1 errors: extra text: issue',
'CS1 errors: extra text: pages',
'CS1 errors: extra text: volume',
'CS1 errors: chapter ignored',
'CS1 errors: invisible characters',
];
$api = new WikipediaBot();
$category = '';
if (is_string(@$_POST["cat"])) $category = trim($_POST["cat"]);
if (strtolower(substr($category, 0, 9)) === 'category:') $category = trim(substr($category, 9));
if ($category === '' && isset($_GET["cat"])) {
$try = trim(urldecode((string) $_GET["cat"]));
if (in_array($try, GET_IS_OKAY, true)) $category = $try;
}
bot_html_header();
check_blocked();
$edit_summary_end = "| Suggested by " . $api->get_the_user() . " | [[Category:$category]] | #UCB_Category ";
if ($category) {
$pages_in_category = WikipediaBot::category_members($category);
if (empty($pages_in_category)) {
report_warning('Category appears to be empty');
bot_html_footer();
exit;
}
$pages_in_category = array_unique($pages_in_category); // Paranoid
shuffle($pages_in_category);
$total = count($pages_in_category);
if ($total > intval(MAX_PAGES / 4)) {
report_warning( 'Category is huge (' . (string) $total . ') Cancelling run. Pick a smaller category (maximum size is ' . (string) intval(MAX_PAGES / 4) . '). Listen to Obi-Wan Kenobi: You want to go home and rethink your life.');
echo "\n\n";
foreach ($pages_in_category as $page_title) {
echo echoable((string) $page_title) . "\n";
}
echo "\n\n";
bot_html_footer();
exit;
}
unset($total, $category);
edit_a_list_of_pages($pages_in_category, $api, $edit_summary_end);
} else {
if (isset($_POST["cat"])) {
report_warning("Invalid category on the webform.");
} elseif (isset($_GET["cat"])) {
report_warning("You must specify the category using the webform. Got: " . echoable($_GET["cat"]));
} else {
report_warning("Nothing requested -- OR -- category got lost during initial authorization.");
}
bot_html_footer();
}
exit;
?>