function doCategoryQuery() { $dbr = wfGetDB(DB_SLAVE, 'category'); $this->nextPage = array('page' => null, 'subcat' => null, 'file' => null); $this->flip = array('page' => false, 'subcat' => false, 'file' => false); foreach (array('page', 'subcat', 'file') as $type) { # Get the sortkeys for start/end, if applicable. Note that if # the collation in the database differs from the one # set in $wgCategoryCollation, pagination might go totally haywire. $extraConds = array('cl_type' => $type); if ($this->from[$type] !== null) { $extraConds[] = 'cl_sortkey >= ' . $dbr->addQuotes($this->collation->getSortKey($this->from[$type])); } elseif ($this->until[$type] !== null) { $extraConds[] = 'cl_sortkey < ' . $dbr->addQuotes($this->collation->getSortKey($this->until[$type])); $this->flip[$type] = true; } /* Wikia change begin - @author: TomekO */ /* Changed by MoLi (1.19 ugrade) */ wfRunHooks('CategoryViewer::beforeCategoryData', array(&$extraConds)); /* Wikia change end */ $res = $dbr->select(array('page', 'categorylinks', 'category'), array('page_id', 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files', 'cl_sortkey_prefix', 'cl_collation'), array_merge(array('cl_to' => $this->title->getDBkey()), $extraConds), __METHOD__, array('USE INDEX' => array('categorylinks' => 'cl_sortkey'), 'LIMIT' => is_integer($this->limit) ? $this->limit + 1 : null, 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey'), array('categorylinks' => array('INNER JOIN', 'cl_from = page_id'), 'category' => array('LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY))); $count = 0; foreach ($res as $row) { $title = Title::newFromRow($row); if ($row->cl_collation === '') { // Hack to make sure that while updating from 1.16 schema // and db is inconsistent, that the sky doesn't fall. // See r83544. Could perhaps be removed in a couple decades... $humanSortkey = $row->cl_sortkey; } else { $humanSortkey = $title->getCategorySortkey($row->cl_sortkey_prefix); } if (++$count > $this->limit && is_integer($this->limit)) { # We've reached the one extra which shows that there # are additional pages to be had. Stop here... $this->nextPage[$type] = $humanSortkey; break; } if ($title->getNamespace() == NS_CATEGORY) { $cat = Category::newFromRow($row, $title); $this->addSubcategoryObject($cat, $humanSortkey, $row->page_len); } elseif ($title->getNamespace() == NS_FILE) { $this->addImage($title, $humanSortkey, $row->page_len, $row->page_is_redirect); } else { # <Wikia> if (wfRunHooks("CategoryViewer::addPage", array(&$this, &$title, &$row, $humanSortkey))) { $this->addPage($title, $humanSortkey, $row->page_len, $row->page_is_redirect); } # </Wikia> } } } }
function doCategoryQuery() { $dbr = wfGetDB(DB_REPLICA, 'category'); $this->nextPage = ['page' => null, 'subcat' => null, 'file' => null]; $this->prevPage = ['page' => null, 'subcat' => null, 'file' => null]; $this->flip = ['page' => false, 'subcat' => false, 'file' => false]; foreach (['page', 'subcat', 'file'] as $type) { # Get the sortkeys for start/end, if applicable. Note that if # the collation in the database differs from the one # set in $wgCategoryCollation, pagination might go totally haywire. $extraConds = ['cl_type' => $type]; if (isset($this->from[$type]) && $this->from[$type] !== null) { $extraConds[] = 'cl_sortkey >= ' . $dbr->addQuotes($this->collation->getSortKey($this->from[$type])); } elseif (isset($this->until[$type]) && $this->until[$type] !== null) { $extraConds[] = 'cl_sortkey < ' . $dbr->addQuotes($this->collation->getSortKey($this->until[$type])); $this->flip[$type] = true; } $res = $dbr->select(['page', 'categorylinks', 'category'], array_merge(LinkCache::getSelectFields(), ['page_namespace', 'page_title', 'cl_sortkey', 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files', 'cl_sortkey_prefix', 'cl_collation']), array_merge(['cl_to' => $this->title->getDBkey()], $extraConds), __METHOD__, ['USE INDEX' => ['categorylinks' => 'cl_sortkey'], 'LIMIT' => $this->limit + 1, 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey'], ['categorylinks' => ['INNER JOIN', 'cl_from = page_id'], 'category' => ['LEFT JOIN', ['cat_title = page_title', 'page_namespace' => NS_CATEGORY]]]); Hooks::run('CategoryViewer::doCategoryQuery', [$type, $res]); $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $count = 0; foreach ($res as $row) { $title = Title::newFromRow($row); $linkCache->addGoodLinkObjFromRow($title, $row); if ($row->cl_collation === '') { // Hack to make sure that while updating from 1.16 schema // and db is inconsistent, that the sky doesn't fall. // See r83544. Could perhaps be removed in a couple decades... $humanSortkey = $row->cl_sortkey; } else { $humanSortkey = $title->getCategorySortkey($row->cl_sortkey_prefix); } if (++$count > $this->limit) { # We've reached the one extra which shows that there # are additional pages to be had. Stop here... $this->nextPage[$type] = $humanSortkey; break; } if ($count == $this->limit) { $this->prevPage[$type] = $humanSortkey; } if ($title->getNamespace() == NS_CATEGORY) { $cat = Category::newFromRow($row, $title); $this->addSubcategoryObject($cat, $humanSortkey, $row->page_len); } elseif ($title->getNamespace() == NS_FILE) { $this->addImage($title, $humanSortkey, $row->page_len, $row->page_is_redirect); } else { $this->addPage($title, $humanSortkey, $row->page_len, $row->page_is_redirect); } } } }