/** * Hook function for APIEditBeforeSave * * @param $editPage EditPage * @param $text string * @param $resultArr array * @return bool */ static function filterAPIEditBeforeSave( $editPage, $text, &$resultArr ) { $spamObj = BaseBlacklist::getInstance( 'spam' ); $title = $editPage->mArticle->getTitle(); $ret = $spamObj->filter( $title, $text, '', '', $editPage ); if ( $ret!==false ) { $resultArr['spamblacklist'] = $ret; } // Return convention for hooks is the inverse of $wgFilterCallback return ( $ret === false ); }
public function execute() { $params = $this->extractRequestParams(); $matches = BaseBlacklist::getInstance('spam')->filter($params['url'], NULL, true); $res = $this->getResult(); if ($matches !== false) { // this url is blacklisted. $res->addValue('spamblacklist', 'result', 'blacklisted'); $res->setIndexedTagName($matches, 'match'); $res->addValue('spamblacklist', 'matches', $matches); } else { // not blacklisted $res->addValue('spamblacklist', 'result', 'ok'); } }
/** * Hook function for EditFilter * Confirm that a local blacklist page being saved is valid, * and toss back a warning to the user if it isn't. * * @param $editPage EditPage * @param $text string * @param $section string * @param $hookError string * @return bool */ static function validate($editPage, $text, $section, &$hookError) { $thisPageName = $editPage->mTitle->getPrefixedDBkey(); if (!BaseBlacklist::isLocalSource($editPage->mTitle)) { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] not a local blacklist\n"); return true; } $type = BaseBlacklist::getTypeFromTitle($editPage->mTitle); if ($type === false) { return true; } $lines = explode("\n", $text); $badLines = SpamRegexBatch::getBadLines($lines, BaseBlacklist::getInstance($type)); if ($badLines) { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] given invalid input lines: " . implode(', ', $badLines) . "\n"); $badList = "*<code>" . implode("</code>\n*<code>", array_map('wfEscapeWikiText', $badLines)) . "</code>\n"; $hookError = "<div class='errorbox'>" . wfMessage('spam-invalid-lines')->numParams($badLines)->text() . "<br />" . $badList . "</div>\n" . "<br clear='all' />\n"; } else { wfDebugLog('SpamBlacklist', "Spam blacklist validator: [[{$thisPageName}]] ok or empty blacklist\n"); } return true; }
/** * Hook function for PageContentSaveComplete * Clear local spam blacklist caches on page save. * * @param Page $wikiPage * @param User $user * @param Content $content * @param string $summary * @param bool $isMinor * @param bool $isWatch * @param string $section * @param int $flags * @param int $revision * @param Status $status * @param int $baseRevId * * @return bool */ static function pageSaveContent(Page $wikiPage, User $user, Content $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId) { if (!BaseBlacklist::isLocalSource($wikiPage->getTitle())) { return true; } // This sucks because every Blacklist needs to be cleared foreach (BaseBlacklist::getBlacklistTypes() as $type => $class) { $blacklist = BaseBlacklist::getInstance($type); $blacklist->clearCache(); } return true; }
/** * Check for abusive or spammy content * * Check the following in sequence (cheapest processing to most expensive, * returning if we get a hit): * 1) Respect $wgSpamRegex * 2) Check SpamBlacklist * 3) Check AbuseFilter * * @param $value string the text to check * @param $pageId int the page ID */ private function findAbuse(&$value, $pageId) { // Respect $wgSpamRegex global $wgSpamRegex; if (is_array($wgSpamRegex) && count($wgSpamRegex) > 0 || is_string($wgSpamRegex) && strlen($wgSpamRegex) > 0) { // In older versions, $wgSpamRegex may be a single string rather than // an array of regexes, so make it compatible. $regexes = (array) $wgSpamRegex; foreach ($regexes as $regex) { if (preg_match($regex, $value)) { return true; } } } // Create a fake title so we can pretend this is an article edit $title = Title::newFromText('__article_feedback_5__'); // Check SpamBlacklist, if installed if (function_exists('wfSpamBlacklistObject')) { $spam = wfSpamBlacklistObject(); } elseif (class_exists('BaseBlacklist')) { $spam = BaseBlacklist::getInstance('spam'); } if ($spam) { $ret = $spam->filter($title, $value, ''); if ($ret !== false) { return true; } } // Check AbuseFilter, if installed if (class_exists('AbuseFilter')) { global $wgUser; $vars = new AbuseFilterVariableHolder(); $vars->addHolder(AbuseFilter::generateUserVars($wgUser)); $vars->addHolder(AbuseFilter::generateTitleVars($title, 'FEEDBACK')); $vars->setVar('SUMMARY', 'Article Feedback 5'); $vars->setVar('ACTION', 'feedback'); $vars->setVar('old_wikitext', ''); $vars->setVar('new_wikitext', $value); $vars->addHolder(AbuseFilter::getEditVars($title)); $filter_result = AbuseFilter::filterAction($vars, $title); return $filter_result != '' && $filter_result !== true; } return false; }