/** * @dataProvider provide_checkExclusion * @covers ::checkExclusion * @param $expected * @param $text * @param null $pgUsername * @param null $optout */ public function test_checkExclusion($expected, $text, $pgUsername = null, $optout = null) { $this->assertSame($expected, checkExclusion($this->getMockWiki(), $text, $pgUsername, $optout)); }
/** * Performs nobots checking, new message checking, etc * * @param string $action Name of action. * @param null|string $title Name of page to check for nobots * @param null $pageidp * @throws AssertFailure * @throws EditError * @throws LoggedOut * @throws MWAPIError * @access public */ public function preEditChecks($action = "Edit", $title = null, $pageidp = null) { global $pgDisablechecks, $pgMasterrunpage; if ($pgDisablechecks) { return; } $preeditinfo = array('action' => 'query', 'meta' => 'userinfo', 'uiprop' => 'hasmsg|blockinfo', 'prop' => 'revisions', 'rvprop' => 'content'); if (!is_null($this->get_runpage())) { $preeditinfo['titles'] = $this->get_runpage(); } if (!is_null($title)) { $preeditinfo['titles'] = (!is_null($this->get_runpage()) ? $preeditinfo['titles'] . "|" : "") . $title; } $preeditinfo = $this->apiQuery($preeditinfo); $messages = false; $blocked = false; $oldtext = ''; $runtext = 'enable'; if (isset($preeditinfo['query']['pages'])) { //$oldtext = $preeditinfo['query']['pages'][$this->pageid]['revisions'][0]['*']; foreach ($preeditinfo['query']['pages'] as $pageid => $page) { if ($pageid == $pageidp) { $oldtext = $page['revisions'][0]['*']; } elseif ($pageid == "-1") { if ($page['title'] == $this->get_runpage()) { pecho("{$action} failed, enable page does not exist.\n\n", PECHO_WARN); throw new EditError("Enablepage", "Enable page does not exist."); } else { $oldtext = ''; } } else { $runtext = $page['revisions'][0]['*']; } } if (isset($preeditinfo['query']['userinfo']['messages'])) { $messages = true; } if (isset($preeditinfo['query']['userinfo']['blockedby'])) { $blocked = true; } } //Perform nobots checks, login checks, /Run checks if (checkExclusion($this, $oldtext, $this->get_username(), $this->get_optout(), $this->nobotsTaskname) && $this->get_nobots()) { throw new EditError("Nobots", "The page has a nobots template"); } if (!is_null($pgMasterrunpage) && !preg_match('/enable|yes|run|go|true/i', $this->initPage($pgMasterrunpage)->get_text())) { throw new EditError("Enablepage", "Script was disabled by Master Run page"); } if (!is_null($this->get_runpage()) && !preg_match('/enable|yes|run|go|true/i', $runtext)) { throw new EditError("Enablepage", "Script was disabled by Run page"); } if ($messages && $this->get_stoponnewmessages()) { throw new EditError("NewMessages", "User has new messages"); } if ($blocked) { throw new EditError("Blocked", "User has been blocked"); } }