Esempio n. 1
0
 /**
  * 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();
 }
 /**
  * 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;
 }
 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 '';
 }
Esempio n. 5
0
 /**
  * Pre-fill the link cache
  */
 function preprocessResults(&$db, &$res)
 {
     if ($db->numRows($res) > 0) {
         $linkBatch = new LinkBatch();
         while ($row = $db->fetchObject($res)) {
             $linkBatch->addObj(Title::makeTitleSafe($row->namespace, $row->title));
         }
         $db->dataSeek($res, 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);
     }
 }
Esempio n. 7
0
 public function getBody()
 {
     $batch = new LinkBatch();
     $this->mResult->rewind();
     foreach ($this->mResult as $row) {
         $batch->addObj(Title::makeTitleSafe(NS_CATEGORY, $row->cat_title));
     }
     $batch->execute();
     $this->mResult->rewind();
     return parent::getBody();
 }
Esempio n. 8
0
 public function getBody()
 {
     $batch = new LinkBatch();
     $this->mResult->rewind();
     while ($row = $this->mResult->fetchObject()) {
         $batch->addObj(Title::makeTitleSafe(NS_CATEGORY, $row->cat_title));
     }
     $batch->execute();
     $this->mResult->rewind();
     return parent::getBody();
 }
 /**
  * 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 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-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)
 {
     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);
 }
 /**
  * Fetch user page links and cache their existence
  */
 function preprocessResults(&$db, &$res)
 {
     $batch = new LinkBatch();
     while ($row = $db->fetchObject($res)) {
         $batch->addObj(Title::makeTitleSafe($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)
 {
     $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);
     }
 }
Esempio n. 15
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);
     }
 }
 function getBody()
 {
     if (!$this->mQueryDone) {
         $this->doQuery();
     }
     $batch = new LinkBatch();
     $this->mResult->rewind();
     while ($row = $this->mResult->fetchObject()) {
         $batch->addObj(Title::makeTitleSafe(NS_CATEGORY, $row->cl_to));
     }
     $batch->execute();
     $this->mResult->rewind();
     return parent::getBody();
 }
 /**
  * @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);
 }
Esempio n. 18
0
 /**
  * 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);
 }
Esempio n. 19
0
 function preprocessResults(&$dbo, &$res)
 {
     # Do a batch existence check on the user and talk pages
     $linkBatch = new LinkBatch();
     while ($row = $dbo->fetchObject($res)) {
         $linkBatch->addObj(Title::makeTitleSafe(NS_USER, $row->user_text));
         $linkBatch->addObj(Title::makeTitleSafe(NS_USER_TALK, $row->user_text));
     }
     $linkBatch->execute();
     # Seek to start
     if ($dbo->numRows($res) > 0) {
         $dbo->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();
     }
     return parent::getStartBody();
 }
Esempio n. 21
0
 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->addObj(Title::makeTitleSafe($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 function preprocessResults($results)
 {
     $names = array();
     foreach ($results as $result) {
         $names[] = $result->utr_name;
     }
     if (!$names) {
         return;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array('user', 'ipblocks'), User::selectFields(), array('user_name' => array_unique($names), 'ipb_deleted IS NULL OR ipb_deleted = 0'), __METHOD__, array(), array('ipblocks' => array('LEFT JOIN', 'user_id = ipb_user')));
     $userArray = UserArray::newFromResult($res);
     $lb = new LinkBatch();
     foreach ($userArray as $user) {
         $this->users[$user->getName()] = $user;
         $lb->addObj($user->getUserPage());
         $lb->addObj($user->getTalkPage());
     }
     $lb->execute();
 }
 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;
 }
Esempio n. 25
0
 /**
  * Cache page existence for performance
  */
 function preprocessResults(&$db, &$res)
 {
     global $wgUser;
     $batch = new LinkBatch();
     while ($row = $db->fetchObject($res)) {
         # <jld>
         $ns = $row->pl_namespace;
         if (!$wgUser->isAllowedEx($ns, "~", "browse")) {
             continue;
         }
         #if (! $wgUser->isAllowed( hnpClass::buildPermissionKey($ns,"~","browse") ))				continue;
         # </jld>
         $batch->addObj(Title::makeTitleSafe($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);
     }
 }
Esempio n. 26
0
 function getStartBody()
 {
     # Do a link batch query
     $this->mResult->seek(0);
     $batch = new LinkBatch();
     # Give some pointers to make (last) links
     $this->mForm->prevId = [];
     foreach ($this->mResult as $row) {
         $batch->addObj(Title::makeTitleSafe(NS_USER, $row->user_name));
         $batch->addObj(Title::makeTitleSafe(NS_USER_TALK, $row->user_name));
         $rev_id = isset($rev_id) ? $rev_id : $row->rev_id;
         if ($rev_id > $row->rev_id) {
             $this->mForm->prevId[$rev_id] = $row->rev_id;
         } elseif ($rev_id < $row->rev_id) {
             $this->mForm->prevId[$row->rev_id] = $rev_id;
         }
         $rev_id = $row->rev_id;
     }
     $batch->execute();
     $this->mResult->seek(0);
     return '';
 }
 function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $this->getOutput()->allowClickjacking();
     $this->getOutput()->addHTML(Html::openElement('table', ['class' => 'mw-datatable', 'id' => 'mw-trackingcategories-table']) . "\n" . "<thead><tr>\n\t\t\t<th>" . $this->msg('trackingcategories-msg')->escaped() . "\n\t\t\t</th>\n\t\t\t<th>" . $this->msg('trackingcategories-name')->escaped() . "</th>\n\t\t\t<th>" . $this->msg('trackingcategories-desc')->escaped() . "\n\t\t\t</th>\n\t\t\t</tr></thead>");
     $trackingCategories = $this->prepareTrackingCategoriesData();
     $batch = new LinkBatch();
     foreach ($trackingCategories as $catMsg => $data) {
         $batch->addObj($data['msg']);
         foreach ($data['cats'] as $catTitle) {
             $batch->addObj($catTitle);
         }
     }
     $batch->execute();
     foreach ($trackingCategories as $catMsg => $data) {
         $allMsgs = [];
         $catDesc = $catMsg . '-desc';
         $catMsgTitleText = Linker::link($data['msg'], htmlspecialchars($catMsg));
         foreach ($data['cats'] as $catTitle) {
             $catTitleText = Linker::link($catTitle, htmlspecialchars($catTitle->getText()));
             $allMsgs[] = $catTitleText;
         }
         # Extra message, when no category was found
         if (!count($allMsgs)) {
             $allMsgs[] = $this->msg('trackingcategories-disabled')->parse();
         }
         /*
          * Show category description if it exists as a system message
          * as category-name-desc
          */
         $descMsg = $this->msg($catDesc);
         if ($descMsg->isBlank()) {
             $descMsg = $this->msg('trackingcategories-nodesc');
         }
         $this->getOutput()->addHTML(Html::openElement('tr') . Html::openElement('td', ['class' => 'mw-trackingcategories-name']) . $this->getLanguage()->commaList(array_unique($allMsgs)) . Html::closeElement('td') . Html::openElement('td', ['class' => 'mw-trackingcategories-msg']) . $catMsgTitleText . Html::closeElement('td') . Html::openElement('td', ['class' => 'mw-trackingcategories-desc']) . $descMsg->parse() . Html::closeElement('td') . Html::closeElement('tr'));
     }
     $this->getOutput()->addHTML(Html::closeElement('table'));
 }
 /**
  * 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();
 }
 /**
  * Make an HTML list of templates, and then add a "More..." link at
  * the bottom. If $more is null, do not add a "More..." link. If $more
  * is a LinkTarget, make a link to that title and use it. If $more is a string,
  * directly paste it in as the link (escaping needs to be done manually).
  *
  * @param LinkTarget[] $templates
  * @param string|bool $type 'preview' if a preview, 'section' if a section edit, false if neither
  * @param LinkTarget|string|null $more An escaped link for "More..." of the templates
  * @return string HTML output
  */
 public function format(array $templates, $type = false, $more = null)
 {
     if (!$templates) {
         // No templates
         return '';
     }
     # Do a batch existence check
     $batch = new LinkBatch();
     foreach ($templates as $title) {
         $batch->addObj($title);
     }
     $batch->execute();
     # Construct the HTML
     $outText = '<div class="mw-templatesUsedExplanation">';
     $count = count($templates);
     if ($type === 'preview') {
         $outText .= $this->context->msg('templatesusedpreview')->numParams($count)->parseAsBlock();
     } elseif ($type === 'section') {
         $outText .= $this->context->msg('templatesusedsection')->numParams($count)->parseAsBlock();
     } else {
         $outText .= $this->context->msg('templatesused')->numParams($count)->parseAsBlock();
     }
     $outText .= "</div><ul>\n";
     usort($templates, 'Title::compare');
     foreach ($templates as $template) {
         $outText .= $this->formatTemplate($template);
     }
     if ($more instanceof LinkTarget) {
         $outText .= Html::rawElement('li', [], $this->linkRenderer->makeLink($more, $this->context->msg('moredotdotdot')->text()));
     } elseif ($more) {
         // Documented as should already be escaped
         $outText .= Html::rawElement('li', [], $more);
     }
     $outText .= '</ul>';
     return $outText;
 }
Esempio n. 30
0
 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 '';
 }