Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page protection #3663

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public function get_text_from(string $title, WikipediaBot $api) : bool {
report_warning("Could not even get the page title."); // @codeCoverageIgnore
return FALSE; // @codeCoverageIgnore
}

if (isset($details->protection) && !empty($details->protection)) {
$the_protections = (array) $details->protection;
foreach ($the_protections as $protects) {
if (isset($protects->type) && (string) $protects->type === "edit" && isset($protects->level)) {
$the_level = (string) $protects->level;
if (in_array($the_level, ["autoconfirmed", "extendedconfirmed"])) {
; // We are good
} elseif (in_array($the_level, ["sysop", "templateeditor"])) {
report_warning("Page is protected.");
return FALSE;
} else {
report_minor_error("Unexpected protection status: " . $the_level);
}
}
}
}

$this->title = (string) $details->title;
$this->lastrevid = (int) $details->lastrevid ;

Expand Down Expand Up @@ -568,12 +586,6 @@ protected function announce_page() : void {
}

protected function allow_bots() : bool {
if (preg_match('~\{\{pp-full\}\}~i', $this->text)) { // NO ONE can edit this page
return FALSE;
}
if (preg_match('~\{\{pp *(?:|\|.+)\}\}~i', $this->text)) { // Only admins can edit this page
return FALSE;
}
// from https://en.wikipedia.org/wiki/Template:Bots
$bot_username = '(?:Citation|DOI)[ _]bot';
if (preg_match('~\{\{(nobots|bots\|allow=none|bots\|deny=all|bots\|optout=all|bots\|deny=.*?'.$bot_username.'.*?)\}\}~iS',$this->text)) {
Expand Down
10 changes: 0 additions & 10 deletions tests/phpunit/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ public function testNobots2() : void {
$this->assertSame(FALSE, $page->write($api, "Testing bot write function"));
});
}

public function testNobots3() : void {
$this->requires_secrets(function() : void {
$api = new WikipediaBot();
$text = '{{cite thesis|url=https://mathscinet.ams.org/mathscinet-getitem?mr=1234}}{{pp-full}}';
$page = $this->process_page($text);
$this->assertSame($text, $page->parsed_text());
$this->assertSame(FALSE, $page->write($api, "Testing bot write function"));
});
}

public function testEmptyPage() : void {
foreach (['', ' ', " \n ", ' move along, nothing to see here ', ' move along, nothing to see here {{}} ', ' }}}}{{{{ ', '{{{{}}', '{{{{ }}', '{{{{}}}}}}}}'] as $text) {
Expand Down