function revertTipOnArticle($pageId, $revId) { global $wgParser; // do not revert if no revId if ($revId <= 0 || $revId == null || $revId == "") { return false; } $undoRevision = Revision::newFromId($revId); $previousRevision = $undoRevision ? $undoRevision->getPrevious() : null; // do not revert if the page is wrong or changed.. if (is_null($undoRevision) || is_null($previousRevision) || $undoRevision->getPage() != $previousRevision->getPage() || $undoRevision->getPage() != $pageId) { return false; } $title = Title::newFromID($pageId); $article = new Article($title); $undoRevisionText = $undoRevision->getText(); $currentText = $article->getContent(); $undoTips = Wikitext::splitTips(reset(Wikitext::getSection($undoRevisionText, "Tips", true))); $prevTips = Wikitext::splitTips(reset(Wikitext::getSection($previousRevision->getText(), "Tips", true))); $currentTipsSection = Wikitext::getSection($currentText, "Tips", true); $currentTips = Wikitext::splitTips($currentTipsSection[0]); $section = $currentTipsSection[1]; $undoTipsFormatted = array(); foreach ($undoTips as $tip) { $undoTipsFormatted[] = self::cleanTip($tip); } $prevTipsFormatted = array(); foreach ($prevTips as $tip) { $prevTipsFormatted[] = self::cleanTip($tip); } $badTips = array_diff($undoTipsFormatted, $prevTipsFormatted); $resultTips = "== Tips =="; foreach ($currentTips as $currentTip) { $tip = self::cleanTip($currentTip); if (in_array($tip, $badTips)) { continue; } $resultTips .= "\n" . $currentTip; } $newText = $wgParser->replaceSection($currentText, $section, $resultTips); $success = $article->doEdit($newText, 'reverting tip from revision ' . $revId, EDIT_UPDATE | EDIT_MINOR); // mark the recent change as patrolled if ($success) { // should be ok to read from slave here because the change has been done earlier. $dbr = wfGetDB(DB_SLAVE); $rcid = $dbr->selectField('recentchanges', 'rc_id', array("rc_this_oldid={$revId}")); RecentChange::markPatrolled($rcid); PatrolLog::record($rcid, false); } return $success; }
private function replaceSection($sectionName, $wikitext) { global $wgParser; $section = Wikitext::getSection($this->wikitext, $sectionName, true); if (empty($section[0])) { throw new Exception("Couldn't find '{$sectionName}' section"); } $newTxt = "== {$sectionName} ==\n" . $wikitext; $this->wikitext = $wgParser->replaceSection($this->wikitext, $section[1], $newTxt); }
public function calc(&$dbr, &$r, &$t, &$pageRow) { $stats = array(); $text = Wikitext::getSection($r->getText(), wfMsg('steps'), true); $text = $text[0]; $num = preg_match_all("@\\{\\{ *whvid\\|[^\\}]+ *\\}\\}@", $text, $matches); $stats['ti_num_wikivideos'] = $num; return $stats; }