public function revertList($list, $revertUser) { global $wgServer, $wgLanguageCode; $results = array(); foreach ($list as $l) { if (preg_match('@^http://(.+)\\.wikihow\\.com/(.+)@', $l, $matches)) { if (!($wgLanguageCode == "en" && $matches[1] == "www" || $matches[1] == $wgLanguageCode)) { $results[] = array('url' => $l, 'success' => false, 'msg' => "Invalid URL for language"); } else { $link = $matches[2]; $title = Title::newFromUrl($link); $article = new Article($title); if ($article && $article->exists()) { $ret = $article->commitRollback($revertUser, wfMsg("mass-revert-message"), TRUE, $resultDetails); if (empty($ret)) { $results[] = array('url' => $l, 'success' => true); } else { $results[] = array('url' => $l, 'success' => false, 'msg' => $ret[0][0]); } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Article not found"); } } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Bad URL"); } } return $results; }
public function execute() { $user = $this->getOption('user'); $username = User::isIP($user) ? $user : User::getCanonicalName($user); if (!$username) { $this->error('Invalid username', true); } $bot = $this->hasOption('bot'); $summary = $this->getOption('summary', $this->mSelf . ' mass rollback'); $titles = array(); $results = array(); if ($this->hasOption('titles')) { foreach (explode('|', $this->getOption('titles')) as $title) { $t = Title::newFromText($title); if (!$t) { $this->error('Invalid title, ' . $title); } else { $titles[] = $t; } } } else { $titles = $this->getRollbackTitles($user); } if (!$titles) { $this->output('No suitable titles to be rolled back'); return; } foreach ($titles as $t) { $a = new Article($t); $this->output('Processing ' . $t->getPrefixedText() . '...'); if (!$a->commitRollback($user, $summary, $bot, $results)) { $this->output("done\n"); } else { $this->output("failed\n"); } } }
$sql = "select distinct(rc_title) FROM `recentchanges` WHERE rc_namespace=0 and rc_comment LIKE '%Added Image using ImageAdder Tool%' AND rc_timestamp > '20110401144146' AND rc_timestamp < '20110404164139';"; $res = $dbr->query($sql); while ($row = $dbr->fetchObject($res)) { $t = Title::makeTitle(NS_MAIN, $row->rc_title); if (!$t) { echo "Can't make title out of {$row->rc_title}\n"; continue; } # update imageadder table, reset the stats on this bad boy $dbw = wfGetDB(DB_MASTER); $dbw->update("imageadder", array("imageadder_hasimage" => 0, "imageadder_skip" => 0), array("imageadder_page" => $t->getArticleID())); // last revision comment? $row = $dbr->selectRow('revision', '*', array('rev_page' => $t->getArticleID()), "fix intro adder", array("ORDER BY" => "rev_id desc", "LIMIT" => 1)); if ($row->rev_comment == "Added Image using ImageAdder Tool") { $a = new Article($t); $a->commitRollback($row->rev_user_text, "Rolling back bug", false, &$results); echo "{$t->getFullURL()} rolled back \n"; continue; } // how many sections? $r = Revision::newFromTitle($t); if (!$r) { echo "Can't make revision out of {$row->rc_title}\n"; continue; } $text = $r->getText(); preg_match_all("@^==.*==@m", $text, $matches); if (sizeof($matches[0]) == 0) { echo "{$t->getFullURL()} has no sections\n"; // get the last edit $lastgood_rev = $dbr->selectRow("revision", "*", array('rev_page' => $t->getArticleID(), 'rev_comment != "Added Image using ImageAdder Tool"', "rev_id < {$row->rev_id}"), "fix intro adder", array("ORDER BY" => "rev_id desc", "LIMIT" => 1));