diff --git a/Page.php b/Page.php index c1d47b3afc..d1baffbadd 100644 --- a/Page.php +++ b/Page.php @@ -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 ; @@ -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)) { diff --git a/tests/phpunit/PageTest.php b/tests/phpunit/PageTest.php index 48883d6ee3..f2dc7a2dd2 100644 --- a/tests/phpunit/PageTest.php +++ b/tests/phpunit/PageTest.php @@ -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) {