本文整理汇总了PHP中LinkBatch类的典型用法代码示例。如果您正苦于以下问题:PHP LinkBatch类的具体用法?PHP LinkBatch怎么用?PHP LinkBatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkBatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSQL
function getSQL()
{
$dbr =& wfGetDB(DB_SLAVE);
list($page, $pagelinks, $templatelinks) = $dbr->tableNamesN('page', 'pagelinks', 'templatelinks');
$dMsgText = wfMsgForContent('disambiguationspage');
$linkBatch = new LinkBatch();
# If the text can be treated as a title, use it verbatim.
# Otherwise, pull the titles from the links table
$dp = Title::newFromText($dMsgText);
if ($dp) {
if ($dp->getNamespace() != NS_TEMPLATE) {
# FIXME we assume the disambiguation message is a template but
# the page can potentially be from another namespace :/
wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
}
$linkBatch->addObj($dp);
} else {
# Get all the templates linked from the Mediawiki:Disambiguationspage
$disPageObj = $this->getDisambiguationPageObj();
$res = $dbr->select(array('pagelinks', 'page'), 'pl_title', array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), 'DisambiguationsPage::getSQL');
while ($row = $dbr->fetchObject($res)) {
$linkBatch->addObj(Title::makeTitle(NS_TEMPLATE, $row->pl_title));
}
$dbr->freeResult($res);
}
$set = $linkBatch->constructSet('lb.tl', $dbr);
if ($set === false) {
$set = 'FALSE';
# We must always return a valid sql query, but this way DB will always quicly return an empty result
wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
}
$sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace," . " pb.page_title AS title, la.pl_from AS value" . " FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa" . " WHERE {$set}" . ' AND pa.page_id = la.pl_from' . ' AND pa.page_namespace = ' . NS_MAIN . ' AND pb.page_id = lb.tl_from' . ' AND pb.page_namespace = la.pl_namespace' . ' AND pb.page_title = la.pl_title' . ' ORDER BY lb.tl_namespace, lb.tl_title';
return $sql;
}
示例2: disambiguation_templates
/**
* Return a clause with the list of disambiguation templates.
* This function was copied verbatim from specials/SpecialDisambiguations.php
*/
function disambiguation_templates( $dbr ) {
$dMsgText = wfMsgForContent('disambiguationspage');
$linkBatch = new LinkBatch;
# If the text can be treated as a title, use it verbatim.
# Otherwise, pull the titles from the links table
$dp = Title::newFromText($dMsgText);
if( $dp ) {
if($dp->getNamespace() != NS_TEMPLATE) {
# FIXME we assume the disambiguation message is a template but
# the page can potentially be from another namespace :/
wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
}
$linkBatch->addObj( $dp );
} else {
# Get all the templates linked from the Mediawiki:Disambiguationspage
$disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
$res = $dbr->select(
array('pagelinks', 'page'),
'pl_title',
array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
__METHOD__ );
foreach ( $res as $row ) {
$linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
}
}
return $linkBatch->constructSet( 'tl', $dbr );
}
示例3: getBody
/**
* @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;
}
示例4: execute
/**
* 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();
}
示例5: getRevIncludes
/**
* 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;
}
示例6: preprocessResults
/**
* 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);
}
}
示例7: getStartBody
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 '';
}
示例8: preprocessResults
/**
* 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();
}
}
示例9: getBody
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();
}
示例10: getBody
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();
}
示例11: preprocessResults
/**
* 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();
}
}
示例12: preprocessResults
/**
* 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);
}
}
示例13: preprocessResults
/**
* 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);
}
示例14: preprocessResults
/**
* 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);
}
}
示例15: preprocessResults
/**
* 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);
}
}