当前位置: 首页>>代码示例>>PHP>>正文


PHP LinkBatch::isEmpty方法代码示例

本文整理汇总了PHP中LinkBatch::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP LinkBatch::isEmpty方法的具体用法?PHP LinkBatch::isEmpty怎么用?PHP LinkBatch::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkBatch的用法示例。


在下文中一共展示了LinkBatch::isEmpty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTitleMtimes

 /**
  * Get the modification times of all titles that would be loaded for
  * a given context.
  * @param $context ResourceLoaderContext: Context object
  * @return array( prefixed DB key => UNIX timestamp ), nonexistent titles are dropped
  */
 protected function getTitleMtimes(ResourceLoaderContext $context)
 {
     $dbr = $this->getDB();
     if (!$dbr) {
         // We're dealing with a subclass that doesn't have a DB
         return array();
     }
     $hash = $context->getHash();
     if (isset($this->titleMtimes[$hash])) {
         return $this->titleMtimes[$hash];
     }
     $this->titleMtimes[$hash] = array();
     $batch = new LinkBatch();
     foreach ($this->getPages($context) as $titleText => $options) {
         $batch->addObj(Title::newFromText($titleText));
     }
     if (!$batch->isEmpty()) {
         $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_touched'), $batch->constructSet('page', $dbr), __METHOD__);
         foreach ($res as $row) {
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $this->titleMtimes[$hash][$title->getPrefixedDBkey()] = wfTimestamp(TS_UNIX, $row->page_touched);
         }
     }
     return $this->titleMtimes[$hash];
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:31,代码来源:ResourceLoaderWikiModule.php

示例2: doVariants

 /**
  * Modify $this->internals and $colours according to language variant linking rules
  */
 protected function doVariants(&$colours)
 {
     global $wgContLang;
     $linkBatch = new LinkBatch();
     $variantMap = array();
     // maps $pdbkey_Variant => $keys (of link holders)
     $output = $this->parent->getOutput();
     $linkCache = LinkCache::singleton();
     $threshold = $this->parent->getOptions()->getStubThreshold();
     $titlesToBeConverted = '';
     $titlesAttrs = array();
     // Concatenate titles to a single string, thus we only need auto convert the
     // single string to all variants. This would improve parser's performance
     // significantly.
     foreach ($this->internals as $ns => $entries) {
         foreach ($entries as $index => $entry) {
             $pdbk = $entry['pdbk'];
             // we only deal with new links (in its first query)
             if (!isset($colours[$pdbk])) {
                 $title = $entry['title'];
                 $titleText = $title->getText();
                 $titlesAttrs[] = array('ns' => $ns, 'key' => "{$ns}:{$index}", 'titleText' => $titleText);
                 // separate titles with \0 because it would never appears
                 // in a valid title
                 $titlesToBeConverted .= $titleText . "";
             }
         }
     }
     // Now do the conversion and explode string to text of titles
     $titlesAllVariants = $wgContLang->autoConvertToAllVariants($titlesToBeConverted);
     $allVariantsName = array_keys($titlesAllVariants);
     foreach ($titlesAllVariants as &$titlesVariant) {
         $titlesVariant = explode("", $titlesVariant);
     }
     $l = count($titlesAttrs);
     // Then add variants of links to link batch
     for ($i = 0; $i < $l; $i++) {
         foreach ($allVariantsName as $variantName) {
             $textVariant = $titlesAllVariants[$variantName][$i];
             if ($textVariant != $titlesAttrs[$i]['titleText']) {
                 $variantTitle = Title::makeTitle($titlesAttrs[$i]['ns'], $textVariant);
                 if (is_null($variantTitle)) {
                     continue;
                 }
                 $linkBatch->addObj($variantTitle);
                 $variantMap[$variantTitle->getPrefixedDBkey()][] = $titlesAttrs[$i]['key'];
             }
         }
     }
     // process categories, check if a category exists in some variant
     $categoryMap = array();
     // maps $category_variant => $category (dbkeys)
     $varCategories = array();
     // category replacements oldDBkey => newDBkey
     foreach ($output->getCategoryLinks() as $category) {
         $variants = $wgContLang->autoConvertToAllVariants($category);
         foreach ($variants as $variant) {
             if ($variant != $category) {
                 $variantTitle = Title::newFromDBkey(Title::makeName(NS_CATEGORY, $variant));
                 if (is_null($variantTitle)) {
                     continue;
                 }
                 $linkBatch->addObj($variantTitle);
                 $categoryMap[$variant] = $category;
             }
         }
     }
     if (!$linkBatch->isEmpty()) {
         // construct query
         $dbr = wfGetDB(DB_SLAVE);
         $varRes = $dbr->select('page', array('page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest'), $linkBatch->constructSet('page', $dbr), __METHOD__);
         $linkcolour_ids = array();
         // for each found variants, figure out link holders and replace
         foreach ($varRes as $s) {
             $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
             $varPdbk = $variantTitle->getPrefixedDBkey();
             $vardbk = $variantTitle->getDBkey();
             $holderKeys = array();
             if (isset($variantMap[$varPdbk])) {
                 $holderKeys = $variantMap[$varPdbk];
                 $linkCache->addGoodLinkObjFromRow($variantTitle, $s);
                 $output->addLink($variantTitle, $s->page_id);
             }
             // loop over link holders
             foreach ($holderKeys as $key) {
                 list($ns, $index) = explode(':', $key, 2);
                 $entry =& $this->internals[$ns][$index];
                 $pdbk = $entry['pdbk'];
                 if (!isset($colours[$pdbk])) {
                     // found link in some of the variants, replace the link holder data
                     $entry['title'] = $variantTitle;
                     $entry['pdbk'] = $varPdbk;
                     // set pdbk and colour
                     # @todo FIXME: Convoluted data flow
                     # The redirect status and length is passed to getLinkColour via the LinkCache
                     # Use formal parameters instead
                     $colours[$varPdbk] = Linker::getLinkColour($variantTitle, $threshold);
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:media-wiki-law,代码行数:101,代码来源:LinkHolderArray.php

示例3: doVariants

 /**
  * Modify $this->internals and $colours according to language variant linking rules
  * @param array $colours
  */
 protected function doVariants(&$colours)
 {
     global $wgContLang, $wgContentHandlerUseDB;
     $linkBatch = new LinkBatch();
     $variantMap = array();
     // maps $pdbkey_Variant => $keys (of link holders)
     $output = $this->parent->getOutput();
     $linkCache = LinkCache::singleton();
     $threshold = $this->parent->getOptions()->getStubThreshold();
     $titlesToBeConverted = '';
     $titlesAttrs = array();
     // Concatenate titles to a single string, thus we only need auto convert the
     // single string to all variants. This would improve parser's performance
     // significantly.
     foreach ($this->internals as $ns => $entries) {
         if ($ns == NS_SPECIAL) {
             continue;
         }
         foreach ($entries as $index => $entry) {
             $pdbk = $entry['pdbk'];
             // we only deal with new links (in its first query)
             if (!isset($colours[$pdbk]) || $colours[$pdbk] === 'new') {
                 $titlesAttrs[] = array($index, $entry['title']);
                 // separate titles with \0 because it would never appears
                 // in a valid title
                 $titlesToBeConverted .= $entry['title']->getText() . "";
             }
         }
     }
     // Now do the conversion and explode string to text of titles
     $titlesAllVariants = $wgContLang->autoConvertToAllVariants(rtrim($titlesToBeConverted, ""));
     $allVariantsName = array_keys($titlesAllVariants);
     foreach ($titlesAllVariants as &$titlesVariant) {
         $titlesVariant = explode("", $titlesVariant);
     }
     // Then add variants of links to link batch
     $parentTitle = $this->parent->getTitle();
     foreach ($titlesAttrs as $i => $attrs) {
         /** @var Title $title */
         list($index, $title) = $attrs;
         $ns = $title->getNamespace();
         $text = $title->getText();
         foreach ($allVariantsName as $variantName) {
             $textVariant = $titlesAllVariants[$variantName][$i];
             if ($textVariant === $text) {
                 continue;
             }
             $variantTitle = Title::makeTitle($ns, $textVariant);
             if (is_null($variantTitle)) {
                 continue;
             }
             // Self-link checking for mixed/different variant titles. At this point, we
             // already know the exact title does not exist, so the link cannot be to a
             // variant of the current title that exists as a separate page.
             if ($variantTitle->equals($parentTitle) && !$title->hasFragment()) {
                 $this->internals[$ns][$index]['selflink'] = true;
                 continue 2;
             }
             $linkBatch->addObj($variantTitle);
             $variantMap[$variantTitle->getPrefixedDBkey()][] = "{$ns}:{$index}";
         }
     }
     // process categories, check if a category exists in some variant
     $categoryMap = array();
     // maps $category_variant => $category (dbkeys)
     $varCategories = array();
     // category replacements oldDBkey => newDBkey
     foreach ($output->getCategoryLinks() as $category) {
         $categoryTitle = Title::makeTitleSafe(NS_CATEGORY, $category);
         $linkBatch->addObj($categoryTitle);
         $variants = $wgContLang->autoConvertToAllVariants($category);
         foreach ($variants as $variant) {
             if ($variant !== $category) {
                 $variantTitle = Title::makeTitleSafe(NS_CATEGORY, $variant);
                 if (is_null($variantTitle)) {
                     continue;
                 }
                 $linkBatch->addObj($variantTitle);
                 $categoryMap[$variant] = array($category, $categoryTitle);
             }
         }
     }
     if (!$linkBatch->isEmpty()) {
         // construct query
         $dbr = wfGetDB(DB_SLAVE);
         $fields = array('page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest');
         if ($wgContentHandlerUseDB) {
             $fields[] = 'page_content_model';
         }
         $varRes = $dbr->select('page', $fields, $linkBatch->constructSet('page', $dbr), __METHOD__);
         $linkcolour_ids = array();
         // for each found variants, figure out link holders and replace
         foreach ($varRes as $s) {
             $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
             $varPdbk = $variantTitle->getPrefixedDBkey();
             $vardbk = $variantTitle->getDBkey();
//.........这里部分代码省略.........
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:101,代码来源:LinkHolderArray.php

示例4: getTitleInfo

 /**
  * Get the information about the wiki pages for a given context.
  * @param ResourceLoaderContext $context
  * @return array Keyed by page name. Contains arrays with 'rev_len' and 'rev_sha1' keys
  */
 protected function getTitleInfo(ResourceLoaderContext $context)
 {
     $dbr = $this->getDB();
     if (!$dbr) {
         // We're dealing with a subclass that doesn't have a DB
         return array();
     }
     $pages = $this->getPages($context);
     $key = implode('|', array_keys($pages));
     if (!isset($this->titleInfo[$key])) {
         $this->titleInfo[$key] = array();
         $batch = new LinkBatch();
         foreach ($pages as $titleText => $options) {
             $batch->addObj(Title::newFromText($titleText));
         }
         if (!$batch->isEmpty()) {
             $res = $dbr->select(array('page', 'revision'), array('page_namespace', 'page_title', 'rev_len', 'rev_sha1'), $batch->constructSet('page', $dbr), __METHOD__, array(), array('revision' => array('INNER JOIN', array('page_latest=rev_id'))));
             foreach ($res as $row) {
                 // Avoid including ids or timestamps of revision/page tables so
                 // that versions are not wasted
                 $title = Title::makeTitle($row->page_namespace, $row->page_title);
                 $this->titleInfo[$key][$title->getPrefixedText()] = array('rev_len' => $row->rev_len, 'rev_sha1' => $row->rev_sha1);
             }
         }
     }
     return $this->titleInfo[$key];
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:32,代码来源:ResourceLoaderWikiModule.php

示例5: replaceLinkHolders


//.........这里部分代码省略.........
                 }
                 $pdbk = $title->getPrefixedDBkey();
                 $titleText = $title->getText();
                 // generate all variants of the link title text
                 $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText);
                 // if link was not found (in first query), add all variants to query
                 if (!isset($colours[$pdbk])) {
                     foreach ($allTextVariants as $textVariant) {
                         if ($textVariant != $titleText) {
                             $variantTitle = Title::makeTitle($ns, $textVariant);
                             if (is_null($variantTitle)) {
                                 continue;
                             }
                             $linkBatch->addObj($variantTitle);
                             $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
                         }
                     }
                 }
             }
             // process categories, check if a category exists in some variant
             foreach ($categories as $category) {
                 $variants = $wgContLang->convertLinkToAllVariants($category);
                 foreach ($variants as $variant) {
                     if ($variant != $category) {
                         $variantTitle = Title::newFromDBkey(Title::makeName(NS_CATEGORY, $variant));
                         if (is_null($variantTitle)) {
                             continue;
                         }
                         $linkBatch->addObj($variantTitle);
                         $categoryMap[$variant] = $category;
                     }
                 }
             }
             if (!$linkBatch->isEmpty()) {
                 // construct query
                 $titleClause = $linkBatch->constructSet('page', $dbr);
                 $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect";
                 if ($threshold > 0) {
                     $variantQuery .= ', page_len';
                 }
                 $variantQuery .= " FROM {$page} WHERE {$titleClause}";
                 if ($options & RLH_FOR_UPDATE) {
                     $variantQuery .= ' FOR UPDATE';
                 }
                 $varRes = $dbr->query($variantQuery, $fname);
                 // for each found variants, figure out link holders and replace
                 while ($s = $dbr->fetchObject($varRes)) {
                     $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
                     $varPdbk = $variantTitle->getPrefixedDBkey();
                     $vardbk = $variantTitle->getDBkey();
                     $holderKeys = array();
                     if (isset($variantMap[$varPdbk])) {
                         $holderKeys = $variantMap[$varPdbk];
                         $linkCache->addGoodLinkObj($s->page_id, $variantTitle);
                         $this->mOutput->addLink($variantTitle, $s->page_id);
                     }
                     // loop over link holders
                     foreach ($holderKeys as $key) {
                         $title = $this->mLinkHolders['titles'][$key];
                         if (is_null($title)) {
                             continue;
                         }
                         $pdbk = $title->getPrefixedDBkey();
                         if (!isset($colours[$pdbk])) {
                             // found link in some of the variants, replace the link holder data
                             $this->mLinkHolders['titles'][$key] = $variantTitle;
开发者ID:renemilk,项目名称:spring-website,代码行数:67,代码来源:Parser.php

示例6: doVariants

 /**
  * Modify $this->internals and $colours according to language variant linking rules
  */
 protected function doVariants(&$colours)
 {
     global $wgContLang;
     $linkBatch = new LinkBatch();
     $variantMap = array();
     // maps $pdbkey_Variant => $keys (of link holders)
     $output = $this->parent->getOutput();
     $linkCache = LinkCache::singleton();
     $sk = $this->parent->getOptions()->getSkin();
     $threshold = $this->getStubThreshold();
     // Add variants of links to link batch
     foreach ($this->internals as $ns => $entries) {
         foreach ($entries as $index => $entry) {
             $key = "{$ns}:{$index}";
             $pdbk = $entry['pdbk'];
             $title = $entry['title'];
             $titleText = $title->getText();
             // generate all variants of the link title text
             $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText);
             // if link was not found (in first query), add all variants to query
             if (!isset($colours[$pdbk])) {
                 foreach ($allTextVariants as $textVariant) {
                     if ($textVariant != $titleText) {
                         $variantTitle = Title::makeTitle($ns, $textVariant);
                         if (is_null($variantTitle)) {
                             continue;
                         }
                         $linkBatch->addObj($variantTitle);
                         $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
                     }
                 }
             }
         }
     }
     // process categories, check if a category exists in some variant
     $categoryMap = array();
     // maps $category_variant => $category (dbkeys)
     $varCategories = array();
     // category replacements oldDBkey => newDBkey
     foreach ($output->getCategoryLinks() as $category) {
         $variants = $wgContLang->convertLinkToAllVariants($category);
         foreach ($variants as $variant) {
             if ($variant != $category) {
                 $variantTitle = Title::newFromDBkey(Title::makeName(NS_CATEGORY, $variant));
                 if (is_null($variantTitle)) {
                     continue;
                 }
                 $linkBatch->addObj($variantTitle);
                 $categoryMap[$variant] = $category;
             }
         }
     }
     if (!$linkBatch->isEmpty()) {
         // construct query
         $dbr = wfGetDB(DB_SLAVE);
         $page = $dbr->tableName('page');
         $titleClause = $linkBatch->constructSet('page', $dbr);
         $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len";
         $variantQuery .= " FROM {$page} WHERE {$titleClause}";
         $varRes = $dbr->query($variantQuery, __METHOD__);
         $linkcolour_ids = array();
         // for each found variants, figure out link holders and replace
         while ($s = $dbr->fetchObject($varRes)) {
             $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
             $varPdbk = $variantTitle->getPrefixedDBkey();
             $vardbk = $variantTitle->getDBkey();
             $holderKeys = array();
             if (isset($variantMap[$varPdbk])) {
                 $holderKeys = $variantMap[$varPdbk];
                 $linkCache->addGoodLinkObj($s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect);
                 $output->addLink($variantTitle, $s->page_id);
             }
             // loop over link holders
             foreach ($holderKeys as $key) {
                 list($ns, $index) = explode(':', $key, 2);
                 $entry =& $this->internals[$ns][$index];
                 $pdbk = $entry['pdbk'];
                 if (!isset($colours[$pdbk])) {
                     // found link in some of the variants, replace the link holder data
                     $entry['title'] = $variantTitle;
                     $entry['pdbk'] = $varPdbk;
                     // set pdbk and colour
                     # FIXME: convoluted data flow
                     # The redirect status and length is passed to getLinkColour via the LinkCache
                     # Use formal parameters instead
                     $colours[$varPdbk] = $sk->getLinkColour($variantTitle, $threshold);
                     $linkcolour_ids[$s->page_id] = $pdbk;
                 }
             }
             // check if the object is a variant of a category
             if (isset($categoryMap[$vardbk])) {
                 $oldkey = $categoryMap[$vardbk];
                 if ($oldkey != $vardbk) {
                     $varCategories[$oldkey] = $vardbk;
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:amjadtbssm,项目名称:website,代码行数:101,代码来源:LinkHolderArray.php

示例7: reallyGetTitleMtimes

 protected function reallyGetTitleMtimes(ResourceLoaderContext $context)
 {
     wfProfileIn(__METHOD__);
     $dbr = $this->getDB();
     if (!$dbr) {
         // We're dealing with a subclass that doesn't have a DB
         wfProfileOut(__METHOD__);
         return array();
     }
     $mtimes = array();
     $local = array();
     $byWiki = array();
     $pages = $this->getPages($context);
     foreach ($pages as $titleText => $options) {
         $title = $this->createTitle($titleText, $options);
         if ($title instanceof GlobalTitle) {
             $byWiki[$title->getCityId()][] = array($title, $titleText, $options);
         } else {
             $local[] = array($title, $titleText, $options);
         }
     }
     if (!empty($local)) {
         $batch = new LinkBatch();
         foreach ($local as $page) {
             list($title, $titleText, $options) = $page;
             $batch->addObj($title);
         }
         if (!$batch->isEmpty()) {
             $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_touched'), $batch->constructSet('page', $dbr), __METHOD__);
             foreach ($res as $row) {
                 $title = Title::makeTitle($row->page_namespace, $row->page_title);
                 $mtimes[$title->getPrefixedDBkey()] = wfTimestamp(TS_UNIX, $row->page_touched);
             }
         }
     }
     foreach ($byWiki as $cityId => $pages) {
         // $pages[0][0] has to be GlobalTitle
         $dbName = $pages[0][0]->getDatabaseName();
         $dbr = wfGetDB(DB_SLAVE, array(), $dbName);
         $pagesData = array();
         foreach ($pages as $page) {
             list($title, $titleText, $options) = $page;
             /** @var $title GlobalTitle */
             $pagesData[$title->getNamespace()][$title->getDBkey()] = true;
         }
         $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_touched'), $dbr->makeWhereFrom2d($pagesData, 'page_namespace', 'page_title'), __METHOD__);
         foreach ($res as $row) {
             $title = GlobalTitle::newFromTextCached($row->page_title, $row->page_namespace, $cityId);
             $mtimes[$dbName . '::' . $title->getPrefixedDBkey()] = wfTimestamp(TS_UNIX, $row->page_touched);
         }
     }
     wfProfileOut(__METHOD__);
     return $mtimes;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:54,代码来源:ResourceLoaderGlobalWikiModule.class.php

示例8: search

 /**
  * Perform the search
  *
  * @param string $search Text to search
  * @param int $limit Maximum items to return
  * @param array $namespaces Namespaces to search
  * @param bool $resolveRedir Whether to resolve redirects
  * @param array &$results Put results here. Keys have to be integers.
  */
 protected function search($search, $limit, $namespaces, $resolveRedir, &$results)
 {
     $searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
     $searchEngine->setLimitOffset($limit);
     $searchEngine->setNamespaces($namespaces);
     $titles = $searchEngine->extractTitles($searchEngine->completionSearchWithVariants($search));
     if (!$titles) {
         return;
     }
     // Special pages need unique integer ids in the return list, so we just
     // assign them negative numbers because those won't clash with the
     // always positive articleIds that non-special pages get.
     $nextSpecialPageId = -1;
     if ($resolveRedir) {
         // Query for redirects
         $redirects = [];
         $lb = new LinkBatch($titles);
         if (!$lb->isEmpty()) {
             $db = $this->getDB();
             $res = $db->select(['page', 'redirect'], ['page_namespace', 'page_title', 'rd_namespace', 'rd_title'], ['rd_from = page_id', 'rd_interwiki IS NULL OR rd_interwiki = ' . $db->addQuotes(''), $lb->constructSet('page', $db)], __METHOD__);
             foreach ($res as $row) {
                 $redirects[$row->page_namespace][$row->page_title] = [$row->rd_namespace, $row->rd_title];
             }
         }
         // Bypass any redirects
         $seen = [];
         foreach ($titles as $title) {
             $ns = $title->getNamespace();
             $dbkey = $title->getDBkey();
             $from = null;
             if (isset($redirects[$ns][$dbkey])) {
                 list($ns, $dbkey) = $redirects[$ns][$dbkey];
                 $from = $title;
                 $title = Title::makeTitle($ns, $dbkey);
             }
             if (!isset($seen[$ns][$dbkey])) {
                 $seen[$ns][$dbkey] = true;
                 $resultId = $title->getArticleID();
                 if ($resultId === 0) {
                     $resultId = $nextSpecialPageId;
                     $nextSpecialPageId -= 1;
                 }
                 $results[$resultId] = ['title' => $title, 'redirect from' => $from, 'extract' => false, 'extract trimmed' => false, 'image' => false, 'url' => wfExpandUrl($title->getFullURL(), PROTO_CURRENT)];
             }
         }
     } else {
         foreach ($titles as $title) {
             $resultId = $title->getArticleID();
             if ($resultId === 0) {
                 $resultId = $nextSpecialPageId;
                 $nextSpecialPageId -= 1;
             }
             $results[$resultId] = ['title' => $title, 'redirect from' => null, 'extract' => false, 'extract trimmed' => false, 'image' => false, 'url' => wfExpandUrl($title->getFullURL(), PROTO_CURRENT)];
         }
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:65,代码来源:ApiOpenSearch.php

示例9: replaceLinkHolders


//.........这里部分代码省略.........
                     }
                 } else {
                     $colours[$pdbk] = 1;
                 }
             }
         }
         wfProfileOut($fname . '-check');
         # Do a second query for different language variants of links (if needed)
         if ($wgContLang->hasVariants()) {
             $linkBatch = new LinkBatch();
             $variantMap = array();
             // maps $pdbkey_Variant => $pdbkey_original
             // Add variants of links to link batch
             foreach ($this->mLinkHolders['namespaces'] as $key => $ns) {
                 $title = $this->mLinkHolders['titles'][$key];
                 if (is_null($title)) {
                     continue;
                 }
                 $pdbk = $title->getPrefixedDBkey();
                 // generate all variants of the link title text
                 $allTextVariants = $wgContLang->convertLinkToAllVariants($title->getText());
                 // if link was not found (in first query), add all variants to query
                 if (!isset($colours[$pdbk])) {
                     foreach ($allTextVariants as $textVariant) {
                         $variantTitle = Title::makeTitle($ns, $textVariant);
                         if (is_null($variantTitle)) {
                             continue;
                         }
                         $linkBatch->addObj($variantTitle);
                         $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
                     }
                 }
             }
             if (!$linkBatch->isEmpty()) {
                 // construct query
                 $titleClause = $linkBatch->constructSet('page', $dbr);
                 $variantQuery = "SELECT page_id, page_namespace, page_title";
                 if ($threshold > 0) {
                     $variantQuery .= ', page_len, page_is_redirect';
                 }
                 $variantQuery .= " FROM {$page} WHERE {$titleClause}";
                 if ($options & RLH_FOR_UPDATE) {
                     $variantQuery .= ' FOR UPDATE';
                 }
                 $varRes = $dbr->query($variantQuery, $fname);
                 // for each found variants, figure out link holders and replace
                 while ($s = $dbr->fetchObject($varRes)) {
                     $variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
                     $varPdbk = $variantTitle->getPrefixedDBkey();
                     $linkCache->addGoodLinkObj($s->page_id, $variantTitle);
                     $this->mOutput->addLink($variantTitle, $s->page_id);
                     $holderKeys = $variantMap[$varPdbk];
                     // loop over link holders
                     foreach ($holderKeys as $key) {
                         $title = $this->mLinkHolders['titles'][$key];
                         if (is_null($title)) {
                             continue;
                         }
                         $pdbk = $title->getPrefixedDBkey();
                         if (!isset($colours[$pdbk])) {
                             // found link in some of the variants, replace the link holder data
                             $this->mLinkHolders['titles'][$key] = $variantTitle;
                             $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey();
                             // set pdbk and colour
                             $pdbks[$key] = $varPdbk;
                             if ($threshold > 0) {
开发者ID:puring0815,项目名称:OpenKore,代码行数:67,代码来源:Parser.php

示例10: fetchTitleInfo

 protected static function fetchTitleInfo(IDatabase $db, array $pages, $fname = __METHOD__)
 {
     $titleInfo = [];
     $batch = new LinkBatch();
     foreach ($pages as $titleText) {
         $title = Title::newFromText($titleText);
         if ($title) {
             // Page name may be invalid if user-provided (e.g. gadgets)
             $batch->addObj($title);
         }
     }
     if (!$batch->isEmpty()) {
         $res = $db->select('page', ['page_namespace', 'page_title', 'page_touched', 'page_len', 'page_latest'], $batch->constructSet('page', $db), $fname);
         foreach ($res as $row) {
             // Avoid including ids or timestamps of revision/page tables so
             // that versions are not wasted
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $titleInfo[$title->getPrefixedText()] = ['page_len' => $row->page_len, 'page_latest' => $row->page_latest, 'page_touched' => $row->page_touched];
         }
     }
     return $titleInfo;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:22,代码来源:ResourceLoaderWikiModule.php


注:本文中的LinkBatch::isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。