public static function onEditFilterMerged($editor, $text, &$error, $summary) { // Load vars $vars = new AbuseFilterVariableHolder(); // Cache article object so we can share a parse operation $title = $editor->mTitle; $articleCacheKey = $title->getNamespace() . ':' . $title->getText(); AFComputedVariable::$articleCache[$articleCacheKey] = $editor->mArticle; // Check for null edits. $oldtext = ''; if ($editor->mArticle->exists()) { $oldtext = $editor->mArticle->getContent(); } if (strcmp($oldtext, $text) == 0) { // Don't trigger for null edits. return true; } global $wgUser; $vars->addHolder(AbuseFilter::generateUserVars($wgUser)); $vars->addHolder(AbuseFilter::generateTitleVars($editor->mTitle, 'ARTICLE')); $vars->setVar('ACTION', 'edit'); $vars->setVar('SUMMARY', $summary); $vars->setVar('minor_edit', $editor->minoredit); $vars->setVar('old_wikitext', $oldtext); $vars->setVar('new_wikitext', $text); $vars->addHolder(AbuseFilter::getEditVars($editor->mTitle)); $filter_result = AbuseFilter::filterAction($vars, $editor->mTitle); if ($filter_result !== true) { global $wgOut; $wgOut->addHTML($filter_result); $editor->showEditForm(); return false; } return true; }
/** * Entry points for MediaWiki hook 'EditFilterMerged' * * @param $editor EditPage instance (object) * @param $text Content of the edit box * @param &$error Error message to return * @param $summary Edit summary for page * @return bool */ public static function onEditFilterMerged($editor, $text, &$error, $summary) { // Load vars $vars = new AbuseFilterVariableHolder(); // Check for null edits. $oldtext = ''; $article = $editor->getArticle(); if ($article->exists()) { //Wikia Change Start - Jakub Olek $rev = $article->getRevision(); if ($rev instanceof Revision) { // Make sure we load the latest text saved in database (bug 31656) $oldtext = $rev->getRawText(); } //Wikia Change End } // Cache article object so we can share a parse operation $title = $editor->mTitle; $articleCacheKey = $title->getNamespace() . ':' . $title->getText(); AFComputedVariable::$articleCache[$articleCacheKey] = $article; if (strcmp($oldtext, $text) == 0) { // Don't trigger for null edits. return true; } global $wgUser; $vars->addHolder(AbuseFilter::generateUserVars($wgUser)); $vars->addHolder(AbuseFilter::generateTitleVars($title, 'ARTICLE')); $vars->setVar('ACTION', 'edit'); $vars->setVar('SUMMARY', $summary); $vars->setVar('minor_edit', $editor->minoredit); $vars->setVar('old_wikitext', $oldtext); $vars->setVar('new_wikitext', $text); $vars->addHolder(AbuseFilter::getEditVars($title, $article)); $filter_result = AbuseFilter::filterAction($vars, $title); if ($filter_result !== true) { global $wgOut; $wgOut->addHTML($filter_result); $editor->showEditForm(); return false; } return true; }
/** * Common implementation for the APIEditBeforeSave, EditFilterMerged * and EditFilterMergedContent hooks. * * @param IContextSource $context the context of the edit * @param Content|null $content the new Content generated by the edit * @param string $text new page content (subject of filtering) * @param Status $status Error message to return * @param string $summary Edit summary for page * @param bool $minoredit whether this is a minor edit according to the user. * * @return bool */ public static function filterEdit(IContextSource $context, $content, $text, Status $status, $summary, $minoredit) { // Load vars $vars = new AbuseFilterVariableHolder(); $title = $context->getTitle(); // Some edits are running through multiple hooks, but we only want to filter them once if (isset($title->editAlreadyFiltered)) { return true; } elseif ($title) { $title->editAlreadyFiltered = true; } self::$successful_action_vars = false; self::$last_edit_page = false; $user = $context->getUser(); // Check for null edits. $oldtext = ''; $oldcontent = null; if ($title instanceof Title && $title->canExist() && $title->exists()) { // Make sure we load the latest text saved in database (bug 31656) $page = $context->getWikiPage(); $revision = $page->getRevision(); if (!$revision) { return true; } if (defined('MW_SUPPORTS_CONTENTHANDLER')) { $oldcontent = $revision->getContent(Revision::RAW); $oldtext = AbuseFilter::contentToString($oldcontent); } else { $oldtext = AbuseFilter::revisionToString($revision, Revision::RAW); } // Cache article object so we can share a parse operation $articleCacheKey = $title->getNamespace() . ':' . $title->getText(); AFComputedVariable::$articleCache[$articleCacheKey] = $page; } else { $page = null; } // Don't trigger for null edits. if ($content && $oldcontent && $oldcontent->equals($content)) { // Compare Content objects if available return true; } else { if (strcmp($oldtext, $text) == 0) { // Otherwise, compare strings return true; } } $vars->addHolders(AbuseFilter::generateUserVars($user), AbuseFilter::generateTitleVars($title, 'ARTICLE')); $vars->setVar('action', 'edit'); $vars->setVar('summary', $summary); $vars->setVar('minor_edit', $minoredit); $vars->setVar('old_wikitext', $oldtext); $vars->setVar('new_wikitext', $text); // TODO: set old_content and new_content vars, use them $vars->addHolders(AbuseFilter::getEditVars($title, $page)); $filter_result = AbuseFilter::filterAction($vars, $title); if (!$filter_result->isOK()) { $status->merge($filter_result); return true; // re-show edit form } self::$successful_action_vars = $vars; self::$last_edit_page = $page; 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(); $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; }