public function execute() { $params = $this->extractRequestParams(); $this->requireOnlyOneParameter($params, 'vars', 'rcid', 'logid'); // "Anti-DoS" if (!$this->getUser()->isAllowed('abusefilter-modify')) { $this->dieUsageMsg('permissiondenied'); } if ($params['vars']) { $vars = FormatJson::decode($params['vars'], true); } elseif ($params['rcid']) { $dbr = wfGetDB(DB_SLAVE); $row = $dbr->selectRow('recentchanges', '*', array('rc_id' => $params['rcid']), __METHOD__); if (!$row) { $this->dieUsageMsg(array('nosuchrcid', $params['rcid'])); } $vars = AbuseFilter::getVarsFromRCRow($row); } elseif ($params['logid']) { $dbr = wfGetDB(DB_SLAVE); $row = $dbr->selectRow('abuse_filter_log', '*', array('afl_id' => $params['logid']), __METHOD__); if (!$row) { $this->dieUsage("There is no abuselog entry with the id ``{$params['logid']}''", 'nosuchlogid'); } $vars = AbuseFilter::loadVarDump($row->afl_var_dump); } if (AbuseFilter::checkSyntax($params['filter']) !== true) { $this->dieUsage('The filter has invalid syntax', 'badsyntax'); } $result = AbuseFilter::checkConditions($params['filter'], $vars); $this->getResult()->addValue(null, $this->getModuleName(), array('result' => $result)); }
function doTest() { // Quick syntax check. $out = $this->getOutput(); $result = AbuseFilter::checkSyntax($this->mFilter); if ($result !== true) { $out->addWikiMsg('abusefilter-test-syntaxerr'); return; } $dbr = wfGetDB(DB_SLAVE); $conds = array('rc_user_text' => $this->mTestUser, 'rc_type != ' . RC_EXTERNAL); if ($this->mTestPeriodStart) { $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes($dbr->timestamp(strtotime($this->mTestPeriodStart))); } if ($this->mTestPeriodEnd) { $conds[] = 'rc_timestamp <= ' . $dbr->addQuotes($dbr->timestamp(strtotime($this->mTestPeriodEnd))); } if ($this->mTestPage) { $title = Title::newFromText($this->mTestPage); if ($title instanceof Title) { $conds['rc_namespace'] = $title->getNamespace(); $conds['rc_title'] = $title->getDBkey(); } else { $out->addWikiMsg('abusefilter-test-badtitle'); return; } } // Get our ChangesList $changesList = new AbuseFilterChangesList($this->getSkin()); $output = $changesList->beginRecentChangesList(); $res = $dbr->select('recentchanges', '*', array_filter($conds), __METHOD__, array('LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp desc')); $counter = 1; foreach ($res as $row) { $vars = AbuseFilter::getVarsFromRCRow($row); if (!$vars) { continue; } $result = AbuseFilter::checkConditions($this->mFilter, $vars); if ($result || $this->mShowNegative) { // Stash result in RC item $rc = RecentChange::newFromRow($row); $rc->examineParams['testfilter'] = $this->mFilter; $rc->filterResult = $result; $rc->counter = $counter++; $output .= $changesList->recentChangesLine($rc, false); } } $output .= $changesList->endRecentChangesList(); $out->addHTML($output); }