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); }
public function execute() { // "Anti-DoS" if (!$this->getUser()->isAllowed('abusefilter-modify')) { $this->dieUsage('You don\'t have permission to check syntax of abuse filters', 'permissiondenied'); } $params = $this->extractRequestParams(); $result = AbuseFilter::checkSyntax($params['filter']); $r = array(); if ($result === true) { // Everything went better than expected :) $r['status'] = 'ok'; } else { $r = array('status' => 'error', 'message' => $result[0], 'character' => $result[1]); } $this->getResult()->addValue(null, $this->getModuleName(), $r); }
function show() { $user = $this->getUser(); $out = $this->getOutput(); $request = $this->getRequest(); $filter = $this->mFilter; $history_id = $this->mHistoryID; if ($filter == 'new' && !$user->isAllowed('abusefilter-modify')) { $out->addWikiMsg('abusefilter-edit-notallowed'); return; } $editToken = $request->getVal('wpEditToken'); $didEdit = $this->canEdit() && $user->matchEditToken($editToken, array('abusefilter', $filter)); if ($didEdit) { // Check syntax $syntaxerr = AbuseFilter::checkSyntax($request->getVal('wpFilterRules')); if ($syntaxerr !== true) { $out->addHTML($this->buildFilterEditor(wfMsgExt('abusefilter-edit-badsyntax', array('parse'), array($syntaxerr[0])), $filter, $history_id)); return; } $dbw = wfGetDB(DB_MASTER); list($newRow, $actions) = $this->loadRequest($filter); $differences = AbuseFilter::compareVersions(array($newRow, $actions), array($newRow->mOriginalRow, $newRow->mOriginalActions)); $origActions = $newRow->mOriginalActions; unset($newRow->mOriginalRow); unset($newRow->mOriginalActions); // Check for non-changes if (!count($differences)) { $out->redirect($this->getTitle()->getLocalURL()); return; } // Check for restricted actions global $wgAbuseFilterRestrictedActions; $allActions = array_keys(array_merge(array_filter($actions), array_filter($origActions))); if (count(array_intersect($wgAbuseFilterRestrictedActions, $allActions)) && !$user->isAllowed('abusefilter-modify-restricted')) { $out->addHTML($this->buildFilterEditor(wfMsgExt('abusefilter-edit-restricted', 'parse'), $this->mFilter, $history_id)); return; } // If we've activated the 'tag' option, check the arguments for validity. if (!empty($actions['tag'])) { $bad = false; foreach ($actions['tag']['parameters'] as $tag) { $t = Title::makeTitleSafe(NS_MEDIAWIKI, 'tag-' . $tag); if (!$t) { $bad = true; } if ($bad) { $out->addHTML($this->buildFilterEditor(wfMsgExt('abusefilter-edit-bad-tags', 'parse'), $this->mFilter, $history_id)); return; } } } $newRow = get_object_vars($newRow); // Convert from object to array // Set last modifier. $newRow['af_timestamp'] = $dbw->timestamp(wfTimestampNow()); $newRow['af_user'] = $user->getId(); $newRow['af_user_text'] = $user->getName(); $dbw->begin(); // Insert MAIN row. if ($filter == 'new') { $new_id = $dbw->nextSequenceValue('abuse_filter_af_id_seq'); $is_new = true; } else { $new_id = $this->mFilter; $is_new = false; } // Reset throttled marker, if we're re-enabling it. $newRow['af_throttled'] = $newRow['af_throttled'] && !$newRow['af_enabled']; $newRow['af_id'] = $new_id; // ID. $dbw->replace('abuse_filter', array('af_id'), $newRow, __METHOD__); if ($is_new) { $new_id = $dbw->insertId(); } // Actions global $wgAbuseFilterAvailableActions; $deadActions = array(); $actionsRows = array(); foreach ($wgAbuseFilterAvailableActions as $action) { // Check if it's set $enabled = isset($actions[$action]) && (bool) $actions[$action]; if ($enabled) { $parameters = $actions[$action]['parameters']; $thisRow = array('afa_filter' => $new_id, 'afa_consequence' => $action, 'afa_parameters' => implode("\n", $parameters)); $actionsRows[] = $thisRow; } else { $deadActions[] = $action; } } // Create a history row $afh_row = array(); foreach (AbuseFilter::$history_mappings as $af_col => $afh_col) { $afh_row[$afh_col] = $newRow[$af_col]; } // Actions $displayActions = array(); foreach ($actions as $action) { $displayActions[$action['action']] = $action['parameters']; } $afh_row['afh_actions'] = serialize($displayActions); $afh_row['afh_changed_fields'] = implode(',', $differences); // Flags $flags = array(); if ($newRow['af_hidden']) { $flags[] = 'hidden'; } if ($newRow['af_enabled']) { $flags[] = 'enabled'; } if ($newRow['af_deleted']) { $flags[] = 'deleted'; } if ($newRow['af_global']) { $flags[] = 'global'; } $afh_row['afh_flags'] = implode(',', $flags); $afh_row['afh_filter'] = $new_id; $afh_row['afh_id'] = $dbw->nextSequenceValue('abuse_filter_af_id_seq'); // Do the update $dbw->insert('abuse_filter_history', $afh_row, __METHOD__); $history_id = $dbw->insertId(); if ($filter != 'new') { $dbw->delete('abuse_filter_action', array('afa_filter' => $filter), __METHOD__); } $dbw->insert('abuse_filter_action', $actionsRows, __METHOD__); $dbw->commit(); // Logging $lp = new LogPage('abusefilter'); $lp->addEntry('modify', $this->getTitle($new_id), '', array($history_id, $new_id)); // Special-case stuff for tags -- purge the tag list cache. if (isset($actions['tag'])) { global $wgMemc; $wgMemc->delete(wfMemcKey('valid-tags')); } AbuseFilter::resetFilterProfile($new_id); $out->redirect($this->getTitle()->getLocalURL('result=success&changedfilter=' . $new_id)); } else { if ($history_id) { $out->addWikiMsg('abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter); } $out->addHTML($this->buildFilterEditor(null, $this->mFilter, $history_id)); if ($history_id) { $out->addWikiMsg('abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter); } } }