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); $revId = $rev->getId(); $currentRevId = $revId; while ($rev && LinkFilter::matchEntry($rev->getText(), $domain)) { # 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(); } }
private function cleanupArticle($id, $domain) { $title = Title::newFromID($id); if (!$title) { $this->error("Internal error: no page for ID {$id}"); return; } $this->output($title->getPrefixedDBkey() . " ..."); $rev = Revision::newFromTitle($title); $currentRevId = $rev->getId(); while ($rev && ($rev->isDeleted(Revision::DELETED_TEXT) || LinkFilter::matchEntry($rev->getContent(Revision::RAW), $domain))) { $rev = $rev->getPrevious(); } if ($rev && $rev->getId() == $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 $this->output("False match\n"); } else { $dbw = wfGetDB(DB_MASTER); $dbw->begin(__METHOD__); $page = WikiPage::factory($title); if ($rev) { // Revert to this revision $content = $rev->getContent(Revision::RAW); $this->output("reverting\n"); $page->doEditContent($content, wfMessage('spam_reverting', $domain)->inContentLanguage()->text(), EDIT_UPDATE, $rev->getId()); } elseif ($this->hasOption('delete')) { // Didn't find a non-spammy revision, blank the page $this->output("deleting\n"); $page->doDeleteArticle(wfMessage('spam_deleting', $domain)->inContentLanguage()->text()); } else { // Didn't find a non-spammy revision, blank the page $handler = ContentHandler::getForTitle($title); $content = $handler->makeEmptyContent(); $this->output("blanking\n"); $page->doEditContent($content, wfMessage('spam_blanking', $domain)->inContentLanguage()->text()); } $dbw->commit(__METHOD__); } }
private function cleanupArticle($id, $domain) { $title = Title::newFromID($id); if (!$title) { $this->error("Internal error: no page for ID {$id}"); return; } $this->output($title->getPrefixedDBkey() . " ..."); $rev = Revision::newFromTitle($title); $revId = $rev->getId(); $currentRevId = $revId; while ($rev && LinkFilter::matchEntry($rev->getText(), $domain)) { # 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 $this->output("False match\n"); } else { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); if (!$rev) { // Didn't find a non-spammy revision, blank the page $this->output("blanking\n"); $article = new Article($title); $article->doEdit('', wfMsg('spam_blanking', $domain)); } else { // Revert to this revision $this->output("reverting\n"); $article = new Article($title); $article->doEdit($rev->getText(), wfMsg('spam_reverting', $domain), EDIT_UPDATE); } $dbw->commit(); } }