/** * Check whether $content contains a link to $filterEntry * * @param Content $content Content to check * @param string $filterEntry Domainparts, see makeRegex() for more details * @return int 0 if no match or 1 if there's at least one match */ static function matchEntry(Content $content, $filterEntry) { if (!$content instanceof TextContent) { // TODO: handle other types of content too. // Maybe create ContentHandler::matchFilter( LinkFilter ). // Think about a common base class for LinkFilter and MagicWord. return 0; } $text = $content->getNativeData(); $regex = LinkFilter::makeRegex($filterEntry); return preg_match($regex, $text); }
function cleanupArticle($id, $domain) { $title = Title::newFromID($id); if (!$title) { print "Internal error: no page for ID {$id}\n"; return; } print $title->getPrefixedDBkey() . " ..."; $rev = Revision::newFromTitle($title); $reverted = false; $revId = $rev->getId(); $currentRevId = $revId; $regex = LinkFilter::makeRegex($domain); while ($rev && preg_match($regex, $rev->getText())) { # Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26) #$rev = $rev->getPrevious(); $revId = $title->getPreviousRevisionID($revId); if ($revId) { $rev = Revision::newFromTitle($title, $revId); } else { $rev = false; } } if ($revId == $currentRevId) { // The regex didn't match the current article text // This happens e.g. when a link comes from a template rather than the page itself print "False match\n"; } else { $dbw =& wfGetDB(DB_MASTER); $dbw->immediateBegin(); if (!$rev) { // Didn't find a non-spammy revision, blank the page print "blanking\n"; $article = new Article($title); $article->updateArticle('', wfMsg('spam_blanking', $domain), false, false); } else { // Revert to this revision print "reverting\n"; $article = new Article($title); $article->updateArticle($rev->getText(), wfMsg('spam_reverting', $domain), false, false); } $dbw->immediateCommit(); wfDoUpdates(); } }
/** * Check whether $text contains a link to $filterEntry * * @param $text String: text to check * @param $filterEntry String: domainparts, see makeRegex() for more details * @return Integer: 0 if no match or 1 if there's at least one match */ static function matchEntry($text, $filterEntry) { $regex = LinkFilter::makeRegex($filterEntry); return preg_match($regex, $text); }