/**
  * Main execution point
  *
  * @param string $subpage
  */
 public function execute($subpage)
 {
     $this->rcSubpage = $subpage;
     $this->setHeaders();
     $this->outputHeader();
     $this->addModules();
     $rows = $this->getRows();
     $opts = $this->getOptions();
     if ($rows === false) {
         if (!$this->including()) {
             $this->doHeader($opts, 0);
             $this->getOutput()->setStatusCode(404);
         }
         return;
     }
     $batch = new LinkBatch();
     foreach ($rows as $row) {
         $batch->add(NS_USER, $row->rc_user_text);
         $batch->add(NS_USER_TALK, $row->rc_user_text);
         $batch->add($row->rc_namespace, $row->rc_title);
     }
     $batch->execute();
     $this->webOutput($rows, $opts);
     $rows->free();
 }
 /**
  * Main execution point
  *
  * @param string $subpage
  */
 public function execute($subpage)
 {
     $this->rcSubpage = $subpage;
     $this->setHeaders();
     $this->outputHeader();
     $this->addModules();
     $rows = $this->getRows();
     $opts = $this->getOptions();
     if ($rows === false) {
         if (!$this->including()) {
             $this->doHeader($opts, 0);
             $this->getOutput()->setStatusCode(404);
         }
         return;
     }
     $batch = new LinkBatch();
     foreach ($rows as $row) {
         $batch->add(NS_USER, $row->rc_user_text);
         $batch->add(NS_USER_TALK, $row->rc_user_text);
         $batch->add($row->rc_namespace, $row->rc_title);
         if ($row->rc_source === RecentChange::SRC_LOG) {
             $formatter = LogFormatter::newFromRow($row);
             foreach ($formatter->getPreloadTitles() as $title) {
                 $batch->addObj($title);
             }
         }
     }
     $batch->execute();
     $this->webOutput($rows, $opts);
     $rows->free();
 }
 /**
  * @return string
  */
 function getBody()
 {
     $s = '';
     $this->doQuery();
     if (count($this->mHist)) {
         if ($this->mImg->isLocal()) {
             // Do a batch existence check for user pages and talkpages
             $linkBatch = new LinkBatch();
             for ($i = $this->mRange[0]; $i <= $this->mRange[1]; $i++) {
                 $file = $this->mHist[$i];
                 $user = $file->getUser('text');
                 $linkBatch->add(NS_USER, $user);
                 $linkBatch->add(NS_USER_TALK, $user);
             }
             $linkBatch->execute();
         }
         $list = new ImageHistoryList($this->mImagePage);
         # Generate prev/next links
         $navLink = $this->getNavigationBar();
         $s = $list->beginImageHistoryList($navLink);
         // Skip rows there just for paging links
         for ($i = $this->mRange[0]; $i <= $this->mRange[1]; $i++) {
             $file = $this->mHist[$i];
             $s .= $list->imageHistoryLine(!$file->isOld(), $file);
         }
         $s .= $list->endImageHistoryList($navLink);
         if ($list->getPreventClickjacking()) {
             $this->preventClickjacking();
         }
     }
     return $s;
 }
 /**
  * Get template and image versions from parsing a revision
  * @param Page $article
  * @param Revision $rev
  * @param User $user
  * @param string $regen use 'regen' to force regeneration
  * @return array( templateIds, fileSHA1Keys )
  * templateIds like ParserOutput->mTemplateIds
  * fileSHA1Keys like ParserOutput->mImageTimeKeys
  */
 public static function getRevIncludes(Page $article, Revision $rev, User $user, $regen = '')
 {
     global $wgParser, $wgMemc;
     wfProfileIn(__METHOD__);
     $versions = false;
     $key = self::getCacheKey($article->getTitle(), $rev->getId());
     if ($regen !== 'regen') {
         // check cache
         $versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article, 'allowStale');
     }
     if (!is_array($versions)) {
         // cache miss
         $pOut = false;
         if ($rev->isCurrent()) {
             $parserCache = ParserCache::singleton();
             # Try current version parser cache (as anon)...
             $pOut = $parserCache->get($article, $article->makeParserOptions($user));
             if ($pOut == false && $rev->getUser()) {
                 // try the user who saved the change
                 $author = User::newFromId($rev->getUser());
                 $pOut = $parserCache->get($article, $article->makeParserOptions($author));
             }
         }
         // ParserOutput::mImageTimeKeys wasn't always there
         if ($pOut == false || !FlaggedRevs::parserOutputIsVersioned($pOut)) {
             $title = $article->getTitle();
             $pOpts = ParserOptions::newFromUser($user);
             // Note: tidy off
             $pOut = $wgParser->parse($rev->getText(), $title, $pOpts, true, true, $rev->getId());
         }
         # Get the template/file versions used...
         $versions = array($pOut->getTemplateIds(), $pOut->getFileSearchOptions());
         # Save to cache (check cache expiry for dynamic elements)...
         $data = FlaggedRevs::makeMemcObj($versions);
         $wgMemc->set($key, $data, $pOut->getCacheExpiry());
     } else {
         $tVersions =& $versions[0];
         // templates
         # Do a link batch query for page_latest...
         $lb = new LinkBatch();
         foreach ($tVersions as $ns => $tmps) {
             foreach ($tmps as $dbKey => $revIdDraft) {
                 $lb->add($ns, $dbKey);
             }
         }
         $lb->execute();
         # Update array with the current page_latest values.
         # This kludge is there since $newTemplates (thus $revIdDraft) is cached.
         foreach ($tVersions as $ns => &$tmps) {
             foreach ($tmps as $dbKey => &$revIdDraft) {
                 $title = Title::makeTitle($ns, $dbKey);
                 $revIdDraft = (int) $title->getLatestRevID();
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $versions;
 }
 /**
  * Pre-cache page existence to speed up link generation
  *
  * @param Database $dbr Database connection
  * @param int $res Result pointer
  */
 public function preprocessResults($db, $res)
 {
     $batch = new LinkBatch();
     while ($row = $db->fetchObject($res)) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     if ($db->numRows($res) > 0) {
         $db->dataSeek($res, 0);
     }
 }
 /**
  * Pre-fill the link cache
  *
  * @param DatabaseBase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if ($res->numRows() > 0) {
         $linkBatch = new LinkBatch();
         foreach ($res as $row) {
             $linkBatch->add($row->namespace, $row->title);
         }
         $res->seek(0);
         $linkBatch->execute();
     }
 }
 /**
  * Pre-cache page existence to speed up link generation
  *
  * @param $db Database connection
  * @param $res ResultWrapper
  */
 public function preprocessResults($db, $res)
 {
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     if ($db->numRows($res) > 0) {
         $db->dataSeek($res, 0);
     }
 }
 function getStartBody()
 {
     # Do a link batch query
     $this->mResult->seek(0);
     $lb = new LinkBatch();
     foreach ($this->mResult as $row) {
         $lb->add($row->pt_namespace, $row->pt_title);
     }
     $lb->execute();
     return '';
 }
 /**
  * Pre-cache page existence to speed up link generation
  *
  * @param $db DatabaseBase connection
  * @param $res ResultWrapper
  */
 public function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     $res->seek(0);
 }
 /**
  * Fetch user page links and cache their existence
  *
  * @param $db DatabaseBase
  * @param $res DatabaseResult
  */
 function preprocessResults($db, $res)
 {
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add(NS_CATEGORY, $row->title);
     }
     $batch->execute();
     // Back to start for display
     if ($db->numRows($res) > 0) {
         // If there are no rows we get an error seeking.
         $db->dataSeek($res, 0);
     }
 }
 /**
  * Fetch user page links and cache their existence
  */
 function preprocessResults($db, $res)
 {
     $batch = new LinkBatch();
     while ($row = $db->fetchObject($res)) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     // Back to start for display
     if ($db->numRows($res) > 0) {
         // If there are no rows we get an error seeking.
         $db->dataSeek($res, 0);
     }
 }
 /**
  * Fetch user page links and cache their existence
  *
  * @param $db DatabaseBase
  * @param $res DatabaseResult
  */
 function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add(NS_CATEGORY, $row->title);
     }
     $batch->execute();
     // Back to start for display
     $res->seek(0);
 }
 /**
  * Main execution point
  *
  * @param string $subpage
  */
 public function execute($subpage)
 {
     $this->rcSubpage = $subpage;
     $this->feedFormat = $this->including() ? null : $this->getRequest()->getVal('feed');
     if ($this->feedFormat !== 'atom' && $this->feedFormat !== 'rss') {
         $this->feedFormat = null;
     }
     $this->setHeaders();
     $this->outputHeader();
     $this->addModules();
     $opts = $this->getOptions();
     // Fetch results, prepare a batch link existence check query
     $conds = $this->buildMainQueryConds($opts);
     $rows = $this->doMainQuery($conds, $opts);
     if ($rows === false || $rows->numRows() == 0) {
         if (!$this->including()) {
             $this->doHeader($opts);
         }
         return;
     }
     if (!$this->feedFormat) {
         $batch = new LinkBatch();
         foreach ($rows as $row) {
             $batch->add(NS_USER, $row->rc_user_text);
             $batch->add(NS_USER_TALK, $row->rc_user_text);
             $batch->add($row->rc_namespace, $row->rc_title);
         }
         $batch->execute();
     }
     if ($this->feedFormat) {
         list($changesFeed, $formatter) = $this->getFeedObject($this->feedFormat);
         /** @var ChangesFeed $changesFeed */
         $changesFeed->execute($formatter, $rows, $this->checkLastModified($this->feedFormat), $opts);
     } else {
         $this->webOutput($rows, $opts);
     }
     $rows->free();
 }
 /**
  * Cache page existence for performance
  *
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     if (!$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
         $batch->addObj($this->getRedirectTarget($row));
     }
     $batch->execute();
     // Back to start for display
     $res->seek(0);
 }
 /**
  * Cache page existence for performance
  *
  * @param $db DatabaseBase
  * @param $res ResultWrapper
  */
 function preprocessResults($db, $res)
 {
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
         $batch->addObj($this->getRedirectTarget($row));
     }
     $batch->execute();
     // Back to start for display
     if ($db->numRows($res) > 0) {
         // If there are no rows we get an error seeking.
         $db->dataSeek($res, 0);
     }
 }
 /**
  * @param IDatabase $db
  * @param ResultWrapper $res
  */
 function preprocessResults($db, $res)
 {
     # There's no point doing a batch check if we aren't caching results;
     # the page must exist for it to have been pulled out of the table
     if (!$this->isCached() || !$res->numRows()) {
         return;
     }
     $batch = new LinkBatch();
     foreach ($res as $row) {
         $batch->add($row->namespace, $row->title);
     }
     $batch->execute();
     $res->seek(0);
 }
 function getStartBody()
 {
     # Do a link batch query for user pages
     if ($this->mResult->numRows()) {
         $lb = new LinkBatch();
         $this->mResult->seek(0);
         while ($row = $this->mResult->fetchObject()) {
             if ($row->img_user) {
                 $lb->add(NS_USER, str_replace(' ', '_', $row->img_user_text));
             }
         }
         $lb->execute();
     }
     return parent::getStartBody();
 }
 function preprocessResults($db, $res)
 {
     # There's no point doing a batch check if we aren't caching results;
     # the page must exist for it to have been pulled out of the table
     if ($this->isCached()) {
         $batch = new LinkBatch();
         while ($row = $db->fetchObject($res)) {
             $batch->add($row->namespace, $row->title);
         }
         $batch->execute();
         if ($db->numRows($res) > 0) {
             $db->dataSeek($res, 0);
         }
     }
 }
 function getStartBody()
 {
     # Do a link batch query for user pages
     if ($this->mResult->numRows()) {
         $lb = new LinkBatch();
         $this->mResult->seek(0);
         while ($row = $this->mResult->fetchObject()) {
             if ($row->img_user) {
                 $lb->add(NS_USER, str_replace(' ', '_', $row->img_user_text));
             }
         }
         $lb->execute();
     }
     # Cache messages used in each row
     $this->mMessages['imgdesc'] = wfMsgHtml('imgdesc');
     $this->mMessages['imgfile'] = wfMsgHtml('imgfile');
     return parent::getStartBody();
 }
 protected static function templatesStale(array $tVersions)
 {
     # Do a link batch query for page_latest...
     $lb = new LinkBatch();
     foreach ($tVersions as $ns => $tmps) {
         foreach ($tmps as $dbKey => $revIdDraft) {
             $lb->add($ns, $dbKey);
         }
     }
     $lb->execute();
     # Check if any of these templates have a newer version
     foreach ($tVersions as $ns => $tmps) {
         foreach ($tmps as $dbKey => $revIdDraft) {
             $title = Title::makeTitle($ns, $dbKey);
             if ($revIdDraft != $title->getLatestRevID()) {
                 return true;
             }
         }
     }
     return false;
 }
 public function getStartBody()
 {
     # Do a link batch query
     if ($this->getNumRows() > 0) {
         $lb = new LinkBatch();
         foreach ($this->mResult as $row) {
             $lb->add($row->log_namespace, $row->log_title);
             $lb->addObj(Title::makeTitleSafe(NS_USER, $row->user_name));
             $lb->addObj(Title::makeTitleSafe(NS_USER_TALK, $row->user_name));
             $formatter = LogFormatter::newFromRow($row);
             foreach ($formatter->getPreloadTitles() as $title) {
                 $lb->addObj($title);
             }
         }
         $lb->execute();
         $this->mResult->seek(0);
     }
     return '';
 }
 function preprocessResults($result)
 {
     # Do a link batch query
     $lb = new LinkBatch();
     $userids = array();
     foreach ($result as $row) {
         $lb->add($row->page_namespace, $row->page_title);
         // field is nullable, maybe null on old protections
         if ($row->log_user !== null) {
             $userids[] = $row->log_user;
         }
     }
     // fill LinkBatch with user page and user talk
     if (count($userids)) {
         $userCache = UserCache::singleton();
         $userCache->doQuery($userids, array(), __METHOD__);
         foreach ($userids as $userid) {
             $name = $userCache->getProp($userid, 'name');
             if ($name !== false) {
                 $lb->add(NS_USER, $name);
                 $lb->add(NS_USER_TALK, $name);
             }
         }
     }
     $lb->execute();
 }
	function getStartBody() {
		wfProfileIn( __METHOD__ );
		# Do a link batch query
		$this->mResult->seek( 0 );
		$lb = new LinkBatch;

		foreach ( $this->mResult as $row ) {
			$lb->add( $row->pt_namespace, $row->pt_title );
		}

		$lb->execute();
		wfProfileOut( __METHOD__ );

		return '';
	}
 function doBatchLookups($list)
 {
     $batch = new LinkBatch();
     /** @var File $file */
     foreach ($list as $file) {
         $batch->addObj($file->getTitle());
         if ($file->isLocal()) {
             $userName = $file->getUser('text');
             $batch->add(NS_USER, $userName);
             $batch->add(NS_USER_TALK, $userName);
         }
     }
     $batch->execute();
 }
 /**
  * Get a list of titles on a user's watchlist, excluding talk pages,
  * and return as a two-dimensional array with namespace and title.
  *
  * @return array
  */
 private function getWatchlistInfo()
 {
     $titles = array();
     $dbr = wfGetDB(DB_MASTER);
     $res = $dbr->select(array('watchlist'), array('wl_namespace', 'wl_title'), array('wl_user' => $this->getUser()->getId()), __METHOD__, array('ORDER BY' => 'wl_namespace, wl_title'));
     $lb = new LinkBatch();
     foreach ($res as $row) {
         $lb->add($row->wl_namespace, $row->wl_title);
         if (!MWNamespace::isTalk($row->wl_namespace)) {
             $titles[$row->wl_namespace][$row->wl_title] = 1;
         }
     }
     $lb->execute();
     return $titles;
 }
Exemple #26
0
 /**
  * Get the targets of the pending redirects from the database
  *
  * Also creates entries in the redirect table for redirects that don't
  * have one.
  * @return LinkBatch
  */
 private function getRedirectTargets()
 {
     $lb = new LinkBatch();
     $db = $this->getDB();
     $this->profileDBIn();
     $res = $db->select('redirect', array('rd_from', 'rd_namespace', 'rd_fragment', 'rd_interwiki', 'rd_title'), array('rd_from' => array_keys($this->mPendingRedirectIDs)), __METHOD__);
     $this->profileDBOut();
     foreach ($res as $row) {
         $rdfrom = intval($row->rd_from);
         $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
         $to = Title::makeTitle($row->rd_namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki);
         unset($this->mPendingRedirectIDs[$rdfrom]);
         if (!isset($this->mAllPages[$row->rd_namespace][$row->rd_title])) {
             $lb->add($row->rd_namespace, $row->rd_title);
         }
         $this->mRedirectTitles[$from] = $to;
     }
     if ($this->mPendingRedirectIDs) {
         // We found pages that aren't in the redirect table
         // Add them
         foreach ($this->mPendingRedirectIDs as $id => $title) {
             $page = WikiPage::factory($title);
             $rt = $page->insertRedirect();
             if (!$rt) {
                 // What the hell. Let's just ignore this
                 continue;
             }
             $lb->addObj($rt);
             $this->mRedirectTitles[$title->getPrefixedText()] = $rt;
             unset($this->mPendingRedirectIDs[$id]);
         }
     }
     return $lb;
 }
 function doBatchLookups()
 {
     # Do a link batch query
     $this->mResult->seek(0);
     $batch = new LinkBatch();
     $revIds = array();
     foreach ($this->mResult as $row) {
         if ($row->rev_parent_id) {
             $revIds[] = $row->rev_parent_id;
         }
         if (!is_null($row->user_name)) {
             $batch->add(NS_USER, $row->user_name);
             $batch->add(NS_USER_TALK, $row->user_name);
         } else {
             # for anons or usernames of imported revisions
             $batch->add(NS_USER, $row->rev_user_text);
             $batch->add(NS_USER_TALK, $row->rev_user_text);
         }
     }
     $this->parentLens = Revision::getParentLengths($this->mDb, $revIds);
     $batch->execute();
     $this->mResult->seek(0);
 }
 function getStartBody()
 {
     # Do a batch existence check on pages
     $linkBatch = new LinkBatch();
     foreach ($this->mResult as $row) {
         $linkBatch->add(NS_USER, $row->rc_user_text);
         $linkBatch->add(NS_USER_TALK, $row->rc_user_text);
         $linkBatch->add($row->rc_namespace, $row->rc_title);
     }
     $linkBatch->execute();
     return '<ul>';
 }
 /**
  * Main execution point
  *
  * @param string $subpage
  */
 public function execute($subpage)
 {
     $this->rcSubpage = $subpage;
     $feedFormat = $this->including() ? null : $this->getRequest()->getVal('feed');
     # 10 seconds server-side caching max
     $this->getOutput()->setSquidMaxage(10);
     # Check if the client has a cached version
     $lastmod = $this->checkLastModified($feedFormat);
     if ($lastmod === false) {
         return;
     }
     $opts = $this->getOptions();
     $this->setHeaders();
     $this->outputHeader();
     $this->addRecentChangesJS();
     // Fetch results, prepare a batch link existence check query
     $conds = $this->buildMainQueryConds($opts);
     $rows = $this->doMainQuery($conds, $opts);
     if ($rows === false) {
         if (!$this->including()) {
             $this->doHeader($opts);
         }
         return;
     }
     if (!$feedFormat) {
         $batch = new LinkBatch();
         foreach ($rows as $row) {
             $batch->add(NS_USER, $row->rc_user_text);
             $batch->add(NS_USER_TALK, $row->rc_user_text);
             $batch->add($row->rc_namespace, $row->rc_title);
         }
         $batch->execute();
     }
     if ($feedFormat) {
         list($changesFeed, $formatter) = $this->getFeedObject($feedFormat);
         /** @var ChangesFeed $changesFeed */
         $changesFeed->execute($formatter, $rows, $lastmod, $opts);
     } else {
         $this->webOutput($rows, $opts);
     }
     $rows->free();
 }
 function doBatchLookups()
 {
     # Do a link batch query
     $this->mResult->seek(0);
     $revIds = array();
     $batch = new LinkBatch();
     # Give some pointers to make (last) links
     foreach ($this->mResult as $row) {
         if (isset($row->rev_parent_id) && $row->rev_parent_id) {
             $revIds[] = $row->rev_parent_id;
         }
         if (isset($row->rev_id)) {
             if ($this->contribs === 'newbie') {
                 // multiple users
                 $batch->add(NS_USER, $row->user_name);
                 $batch->add(NS_USER_TALK, $row->user_name);
             }
             $batch->add($row->page_namespace, $row->page_title);
         }
     }
     $this->mParentLens = Revision::getParentLengths($this->getDatabase(), $revIds);
     $batch->execute();
     $this->mResult->seek(0);
 }