本文整理汇总了PHP中LinkBatch::addResultToCache方法的典型用法代码示例。如果您正苦于以下问题:PHP LinkBatch::addResultToCache方法的具体用法?PHP LinkBatch::addResultToCache怎么用?PHP LinkBatch::addResultToCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkBatch
的用法示例。
在下文中一共展示了LinkBatch::addResultToCache方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCategoryLinks
/**
* Add an array of categories, with names in the keys
*/
public function addCategoryLinks($categories)
{
global $wgUser, $wgContLang;
if (!is_array($categories) || count($categories) == 0) {
return;
}
# Add the links to a LinkBatch
$arr = array(NS_CATEGORY => $categories);
$lb = new LinkBatch();
$lb->setArray($arr);
# Fetch existence plus the hiddencat property
$dbr = wfGetDB(DB_SLAVE);
$pageTable = $dbr->tableName('page');
$where = $lb->constructSet('page', $dbr);
$propsTable = $dbr->tableName('page_props');
$sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value\n\t\t\tFROM {$pageTable} LEFT JOIN {$propsTable} ON pp_propname='hiddencat' AND pp_page=page_id WHERE {$where}";
$res = $dbr->query($sql, __METHOD__);
# Add the results to the link cache
$lb->addResultToCache(LinkCache::singleton(), $res);
# Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
$categories = array_combine(array_keys($categories), array_fill(0, count($categories), 'normal'));
# Mark hidden categories
foreach ($res as $row) {
if (isset($row->pp_value)) {
$categories[$row->page_title] = 'hidden';
}
}
# Add the remaining categories to the skin
if (wfRunHooks('OutputPageMakeCategoryLinks', array(&$this, $categories, &$this->mCategoryLinks))) {
$sk = $wgUser->getSkin();
foreach ($categories as $category => $type) {
$title = Title::makeTitleSafe(NS_CATEGORY, $category);
$text = $wgContLang->convertHtml($title->getText());
$this->mCategoryLinks[$type][] = $sk->makeLinkObj($title, $text);
}
}
}
示例2: addCategoryLinks
/**
* Add an array of categories, with names in the keys
*
* @param array $categories Mapping category name => sort key
*/
public function addCategoryLinks(array $categories)
{
global $wgContLang;
if (!is_array($categories) || count($categories) == 0) {
return;
}
# Add the links to a LinkBatch
$arr = array(NS_CATEGORY => $categories);
$lb = new LinkBatch();
$lb->setArray($arr);
# Fetch existence plus the hiddencat property
$dbr = wfGetDB(DB_SLAVE);
$fields = array('page_id', 'page_namespace', 'page_title', 'page_len', 'page_is_redirect', 'page_latest', 'pp_value');
if ($this->getConfig()->get('ContentHandlerUseDB')) {
$fields[] = 'page_content_model';
}
$res = $dbr->select(array('page', 'page_props'), $fields, $lb->constructSet('page', $dbr), __METHOD__, array(), array('page_props' => array('LEFT JOIN', array('pp_propname' => 'hiddencat', 'pp_page = page_id'))));
# Add the results to the link cache
$lb->addResultToCache(LinkCache::singleton(), $res);
# Set all the values to 'normal'.
$categories = array_fill_keys(array_keys($categories), 'normal');
# Mark hidden categories
foreach ($res as $row) {
if (isset($row->pp_value)) {
$categories[$row->page_title] = 'hidden';
}
}
# Add the remaining categories to the skin
if (Hooks::run('OutputPageMakeCategoryLinks', array(&$this, $categories, &$this->mCategoryLinks))) {
foreach ($categories as $category => $type) {
$origcategory = $category;
$title = Title::makeTitleSafe(NS_CATEGORY, $category);
if (!$title) {
continue;
}
$wgContLang->findVariantLink($category, $title, true);
if ($category != $origcategory && array_key_exists($category, $categories)) {
continue;
}
$text = $wgContLang->convertHtml($title->getText());
$this->mCategories[] = $title->getText();
$this->mCategoryLinks[$type][] = Linker::link($title, $text);
}
}
}
示例3: addCategoryLinks
/**
* Add an array of categories, with names in the keys
*
* @param array $categories Mapping category name => sort key
*/
public function addCategoryLinks(array $categories)
{
global $wgContLang;
if (!is_array($categories) || count($categories) == 0) {
return;
}
# Add the links to a LinkBatch
$arr = [NS_CATEGORY => $categories];
$lb = new LinkBatch();
$lb->setArray($arr);
# Fetch existence plus the hiddencat property
$dbr = wfGetDB(DB_REPLICA);
$fields = array_merge(LinkCache::getSelectFields(), ['page_namespace', 'page_title', 'pp_value']);
$res = $dbr->select(['page', 'page_props'], $fields, $lb->constructSet('page', $dbr), __METHOD__, [], ['page_props' => ['LEFT JOIN', ['pp_propname' => 'hiddencat', 'pp_page = page_id']]]);
# Add the results to the link cache
$lb->addResultToCache(LinkCache::singleton(), $res);
# Set all the values to 'normal'.
$categories = array_fill_keys(array_keys($categories), 'normal');
# Mark hidden categories
foreach ($res as $row) {
if (isset($row->pp_value)) {
$categories[$row->page_title] = 'hidden';
}
}
# Add the remaining categories to the skin
if (Hooks::run('OutputPageMakeCategoryLinks', [&$this, $categories, &$this->mCategoryLinks])) {
foreach ($categories as $category => $type) {
// array keys will cast numeric category names to ints, so cast back to string
$category = (string) $category;
$origcategory = $category;
$title = Title::makeTitleSafe(NS_CATEGORY, $category);
if (!$title) {
continue;
}
$wgContLang->findVariantLink($category, $title, true);
if ($category != $origcategory && array_key_exists($category, $categories)) {
continue;
}
$text = $wgContLang->convertHtml($title->getText());
$this->mCategories[] = $title->getText();
$this->mCategoryLinks[$type][] = Linker::link($title, $text);
}
}
}