protected function fetchArticleHtml($title, $revid) { if (!$revid) { $good = GoodRevision::newFromTitle($title, $title->getArticleID()); if ($good) { $revid = $good->latestGood(); } } $article = new Article($title, $revid); if (!$article) { return false; } $article->loadContent(); $rev = $article->mRevision; if (!$rev) { return false; } $this->getNonMobileHtml($title, $rev); $builder = new MobileAppArticleBuilder(); $this->html = $builder->createByHtml($title, $this->html); return true; }
function getLastGoodRevision($aid) { $t = Title::newFromId($aid); $r = null; if (GoodRevision::patrolledGood($t)) { $gr = GoodRevision::newFromTitle($t, $aid); $r = Revision::newFromId($gr->latestGood()); } return $r; }
/** * Compute the latest good revisions table for all articles. */ public static function computeLatestAll() { $dbw = wfGetDB(DB_MASTER); $one_week_ago = wfTimestamp(TS_MW, time() - 7 * 24 * 60 * 60); $corrected = array(); $updateRevFunc = function ($page_id, $page_title, $rev_id) { $title = Title::newFromDBkey($page_title); $goodRev = GoodRevision::newFromTitle($title, $page_id); if ($goodRev) { return $goodRev->updateRev($rev_id, true); } else { return false; } }; // Clear from good_revision table all the deleted articles, // articles moved to other namespaces and articles // turned into redirects. $sql = 'DELETE good_revision FROM good_revision LEFT JOIN page ON gr_page = page_id WHERE page_is_redirect <> 0 OR page_namespace <> 0 OR page_title IS NULL'; $dbw->query($sql, __METHOD__); $count = $dbw->affectedRows(); print __METHOD__ . ": removed " . $dbw->affectedRows() . " non-article rows from good_revision table\n"; // List all articles patrolled over the last week and // compute good_rev on them $sql = 'SELECT page_title, page_id, MAX(rc_id) AS rc_id FROM page, recentchanges WHERE page_id = rc_cur_id AND page_namespace = 0 AND page_is_redirect = 0 AND rc_patrolled = 1 AND page_touched >= ' . $dbw->addQuotes($one_week_ago) . ' GROUP BY rc_cur_id'; $patrolled = array(); $res = $dbw->query($sql, __METHOD__); foreach ($res as $obj) { $patrolled[$obj->page_id] = (array) $obj; } // Store recently patrolled articles with their patrolled revision foreach ($patrolled as $row) { $rev_id = GoodRevision::getRevFromRC($row['page_id'], $row['rc_id']); $updated = $updateRevFunc($row['page_id'], $row['page_title'], $rev_id); if ($updated) { $corrected[] = $row['page_id']; } } $count = count($corrected); print __METHOD__ . ": updated {$count} recently patrolled articles in good_revision table\n"; // List all articles that haven't been touched in the last week // and correct their good revision if need $sql = 'SELECT page_title, page_id, page_latest FROM page WHERE page_namespace = 0 AND page_is_redirect = 0 AND page_touched < ' . $dbw->addQuotes($one_week_ago); $rows = array(); $res = $dbw->query($sql, __METHOD__); foreach ($res as $obj) { $rows[] = (array) $obj; } // Store latest revision of all articles not edited in the last week foreach ($rows as $row) { if (!isset($patrolled[$row['page_id']])) { $updated = $updateRevFunc($row['page_id'], $row['page_title'], $row['page_latest']); if ($updated) { $corrected[] = $row['page_id']; } } } print __METHOD__ . ": updated " . (count($corrected) - $count) . " older articles in good_revision table\n"; // Call out to DailyEdits to let Titus and others know what should be recomputed foreach ($corrected as $aid) { DailyEdits::onGoodRevisionFixed($aid); } }
static function loadTitleRevision($title, $revid = 0) { if (!$revid) { $good = GoodRevision::newFromTitle($title, $title->getArticleId()); if ($good) { $revid = $good->latestGood(); } } // TODO these two are to be uncommented only for debugging //$revision = Revision::newFromTitle($title); //$revid = $revision->getId(); $article = new Article($title, $revid); if (!$article) { return null; } $article->loadContent(); $rev = $article->mRevision; return $rev ? $rev : null; }
/** * Print the history page for an article. */ function onView() { global $wgScript, $wgUseFileCache; $out = $this->getOutput(); $request = $this->getRequest(); /** * Allow client caching. */ if ($out->checkLastModified($this->page->getTouched())) { return; // Client cache fresh and headers sent, nothing more to do. } wfProfileIn(__METHOD__); $this->preCacheMessages(); # Fill in the file cache if not set already if ($wgUseFileCache && HTMLFileCache::useFileCache($this->getContext())) { $cache = HTMLFileCache::newFromTitle($this->getTitle(), 'history'); if (!$cache->isCacheGood()) { ob_start(array(&$cache, 'saveToFileCache')); } } // Setup page variables. $out->setFeedAppendQuery('action=history'); $out->addModules('mediawiki.action.history'); // Handle atom/RSS feeds. $feedType = $request->getVal('feed'); if ($feedType) { $this->feed($feedType); wfProfileOut(__METHOD__); return; } // Fail nicely if article doesn't exist. if (!$this->page->exists()) { $out->addWikiMsg('nohistory'); # show deletion/move log if there is an entry LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); wfProfileOut(__METHOD__); return; } /** * Add date selector to quickly get to a certain time */ $year = $request->getInt('year'); $month = $request->getInt('month'); $tagFilter = $request->getVal('tagfilter'); $tagSelector = ChangeTags::buildTagFilterSelector($tagFilter); /** * Option to show only revisions that have been (partially) hidden via RevisionDelete */ if ($request->getBool('deleted')) { $conds = array('rev_deleted != 0'); } else { $conds = array(); } if ($this->getUser()->isAllowed('deletedhistory')) { $checkDeleted = Xml::checkLabel($this->msg('history-show-deleted')->text(), 'deleted', 'mw-show-deleted-only', $request->getBool('deleted')) . "\n"; } else { $checkDeleted = ''; } // Add the general form $action = htmlspecialchars($wgScript); $out->addHTML("<form action=\"{$action}\" method=\"get\" id=\"mw-history-searchform\">" . Xml::fieldset($this->msg('history-fieldset-title')->text(), false, array('id' => 'mw-history-search')) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . "\n" . Html::hidden('action', 'history') . "\n" . Xml::dateMenu($year == null ? MWTimestamp::getLocalInstance()->format('Y') : $year, $month) . ' ' . ($tagSelector ? implode(' ', $tagSelector) . ' ' : '') . $checkDeleted . Xml::submitButton($this->msg('allpagessubmit')->text()) . "\n" . '</fieldset></form>'); wfRunHooks('PageHistoryBeforeList', array(&$this->page, $this->getContext())); // XXCHANGED Reuben 1/23/2014: include good revision debugging info in // page history for staff global $wgUser; $userGroups = $wgUser ? $wgUser->getGroups() : array(); $this->mShowGoodRev = in_array('staff', $userGroups); if ($this->mShowGoodRev) { $pageid = $this->page->getId(); $gr = GoodRevision::newFromTitle($this->getTitle(), $pageid); if ($gr) { $this->mGoodRev = $gr->latestGood(); } } // Create and output the list. $pager = new HistoryPager($this, $year, $month, $tagFilter, $conds); $out->addHTML($pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar()); $out->preventClickjacking($pager->getPreventClickjacking()); wfProfileOut(__METHOD__); }
/** * Print the history page for an article. * * @returns nothing */ function history() { global $wgOut, $wgRequest, $wgTitle; /* * Allow client caching. */ if ($wgOut->checkLastModified($this->mArticle->getTimestamp())) { /* Client cache fresh and headers sent, nothing more to do. */ return; } $wgOut->addScript("<script src='/skins/common/history.js'></script>"); $fname = 'PageHistory::history'; wfProfileIn($fname); /* * Setup page variables. */ $wgOut->setPageTitle(wfMsg('history-title', $this->mTitle->getPrefixedText())); $wgOut->setPageTitleActionText(wfMsg('history_short')); $wgOut->setArticleFlag(false); $wgOut->setArticleRelated(true); $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->setSyndicated(true); $wgOut->setFeedAppendQuery('action=history'); $logPage = SpecialPage::getTitleFor('Log'); $logLink = $this->mSkin->makeKnownLinkObj($logPage, wfMsgHtml('viewpagelogs'), 'page=' . $this->mTitle->getPrefixedUrl()); $wgOut->setSubtitle($logLink); $feedType = $wgRequest->getVal('feed'); if ($feedType) { wfProfileOut($fname); return $this->feed($feedType); } /* * Fail if article doesn't exist. */ if (!$this->mTitle->exists()) { $wgOut->addWikiMsg('nohistory'); wfProfileOut($fname); return; } /* * "go=first" means to jump to the last (earliest) history page. * This is deprecated, it no longer appears in the user interface */ if ($wgRequest->getText("go") == 'first') { $limit = $wgRequest->getInt('limit', 50); $wgOut->redirect($wgTitle->getLocalURL("action=history&limit={$limit}&dir=prev")); return; } wfRunHooks('PageHistoryBeforeList', array(&$this->mArticle)); // XXCHANGED - show last patrolled revision to staff global $wgUser; $userGroups = $wgUser ? $wgUser->getGroups() : array(); $this->mShowGoodRev = in_array('staff', $userGroups); if ($this->mShowGoodRev) { $gr = GoodRevision::newFromTitle($this->mTitle, $this->mArticle->getId()); if ($gr) { $this->mGoodRev = $gr->latestGood(); } } /** * Do the list */ $pager = new PageHistoryPager($this); $this->linesonpage = $pager->getNumRows(); $wgOut->addHTML($pager->getNavigationBar() . $this->beginHistoryList() . $pager->getBody() . $this->endHistoryList() . $pager->getNavigationBar()); wfProfileOut($fname); }
public static function getTitleImage($title, $skip_parser = false) { global $wgContLang; wfProfileIn(__METHOD__); //resolve redirects $r = Revision::newFromTitle($title); if (!$r) { wfProfileOut(__METHOD__); return ""; } $text = $r->getText(); if (preg_match("/^#REDIRECT \\[\\[(.*?)\\]\\]/", $text, $matches)) { if ($matches[1]) { $title = Title::newFromText($matches[1]); if (!$title || !$title->exists()) { wfProfileOut(__METHOD__); return ''; } $goodRev = GoodRevision::newFromTitle($title, $title->getArticleId()); $revId = $goodRev ? $goodRev->latestGood() : 0; $rev = $revId ? Revision::newFromId($revId) : Revision::newFromTitle($title); if (!$rev) { return ''; } $text = $rev->getText(); } } // Make sure to look for an appropriately namespaced image. Always check for "Image" // as a lot of files are in the english image repository $nsTxt = "(Image|" . $wgContLang->getNsText(NS_IMAGE) . ")"; //check the steps $matches = ''; if ($skip_parser) { $steps[0] = self::getStepsNoParser($text); } else { $steps = self::getStepsSection($text, true); } wfProfileIn(__METHOD__ . '-imagematch'); //[[Image:...]] preg_match_all("@\\[\\[" . $nsTxt . ":([^\\|]+)[^\\]]*\\]\\]@im", $steps[0], $matches_img); wfProfileOut(__METHOD__ . '-imagematch'); if (!empty($matches_img[2])) { $matches = $matches_img[2]; } else { //{{largeimage|...}} wfProfileIn(__METHOD__ . '-largeimagematch'); preg_match_all("@\\{\\{largeimage\\|([^\\||\\}]+)\\}\\}@im", $steps[0], $matches_lgimg); wfProfileOut(__METHOD__ . '-largeimagematch'); if (!empty($matches_lgimg[1])) { $matches = $matches_lgimg[1]; } } // Check for wikivideos and pull images from there if (empty($matches)) { //{{whvid|...|...}} wfProfileIn(__METHOD__ . '-whvidmatch'); preg_match_all("@\\{\\{whvid\\|[^\\||\\}]+\\|([^\\||\\}]+)\\}\\}@im", $steps[0], $matches_whvid); wfProfileOut(__METHOD__ . '-whvidmatch'); if (!empty($matches_whvid[1])) { $matches = $matches_whvid[1]; } } if ($matches) { //grab the last image that appears in the steps section $file = wfFindFile(str_replace(" ", "-", end($matches))); if ($file && isset($file)) { wfProfileOut(__METHOD__); return $file; } } wfProfileOut(__METHOD__); }
<?php require_once 'commandLine.inc'; # Export list of alternative methods for a list of articles to CSV file $filename = $argv[0]; $f = fopen($filename, 'r'); $contents = fread($f, filesize($filename)); fclose($f); $pages = preg_split('@[\\r\\n]+@', $contents); foreach ($pages as $page) { $t = Title::newFromText($page); $gr = GoodRevision::newFromTitle($t); if ($gr) { $dbr = wfGetDB(DB_SLAVE); $lr = $gr->latestGood(); $r = Revision::loadFromId($dbr, $lr); if ($r) { $text = Wikitext::getStepsSection($r->getText(), true); if (preg_match_all("@===([^=]+)===@", $text[0], $matches)) { print $page; foreach ($matches[1] as $m) { if (!preg_match("@\r\n@", $m)) { print ',' . $m; } } print "\n"; } } } }
/** * Grab the wikitext for the article record */ private function getArticleWikiText() { // cache this if it was already pulled if ($this->wikitext) { return $this->wikitext; } if (!$this->title || !$this->title->exists()) { //throw new Exception('ArticleMetaInfo: title not found'); return ''; } $good = GoodRevision::newFromTitle($this->title, $this->articleID); $revid = $good ? $good->latestGood() : 0; $dbr = $this->getDB(); $rev = Revision::loadFromTitle($dbr, $this->title, $revid); if (!$rev) { //throw new Exception('ArticleMetaInfo: could not load revision'); return ''; } $this->wikitext = $rev->getText(); return $this->wikitext; }
public function calcPageStats(&$statsToCalc, &$row) { $dbr = $this->getWikiDB(); $t = Title::newFromId($row->page_id); $goodRevision = GoodRevision::newFromTitle($t, $row->page_id); $revId = 0; if ($goodRevision) { $revId = $goodRevision->latestGood(); } $r = $revId > 0 ? Revision::loadFromId($dbr, $revId) : Revision::loadFromPageId($dbr, $row->page_id); $fields = array(); if ($r && $t && $t->exists()) { foreach ($statsToCalc as $stat => $isOn) { if ($isOn) { $statCalculator = $this->getStatClass($stat); $fields = array_merge($fields, $statCalculator->calc($dbr, $r, $t, $row)); } } } return $fields; }