diff options
Diffstat (limited to 'includes/SpecialCategories.php')
-rw-r--r-- | includes/SpecialCategories.php | 103 |
1 files changed, 50 insertions, 53 deletions
diff --git a/includes/SpecialCategories.php b/includes/SpecialCategories.php index 346eac63..45e1ae6c 100644 --- a/includes/SpecialCategories.php +++ b/includes/SpecialCategories.php @@ -1,69 +1,66 @@ <?php /** * - * @package MediaWiki - * @subpackage SpecialPage + * @addtogroup SpecialPage */ -/** - * - * @package MediaWiki - * @subpackage SpecialPage - */ -class CategoriesPage extends QueryPage { - - function getName() { - return "Categories"; - } - - function isExpensive() { - return false; - } +function wfSpecialCategories() { + global $wgOut; - function isSyndicated() { return false; } + $cap = new CategoryPager(); + $wgOut->addHTML( + wfMsgWikiHtml( 'categoriespagetext' ) . + $cap->getNavigationBar() + . '<ul>' . $cap->getBody() . '</ul>' . + $cap->getNavigationBar() + ); +} - function getPageHeader() { - return wfMsgWikiHtml( 'categoriespagetext' ); +/** + * @addtogroup SpecialPage + * @addtogroup Pager + */ +class CategoryPager extends AlphabeticPager { + function getQueryInfo() { + return array( + 'tables' => array('categorylinks'), + 'fields' => array('cl_to','count(*) AS count'), + 'options' => array('GROUP BY' => 'cl_to') + ); } - function getSQL() { - $NScat = NS_CATEGORY; - $dbr =& wfGetDB( DB_SLAVE ); - $categorylinks = $dbr->tableName( 'categorylinks' ); - $implicit_groupby = $dbr->implicitGroupby() ? '1' : 'cl_to'; - $s= "SELECT 'Categories' as type, - {$NScat} as namespace, - cl_to as title, - $implicit_groupby as value, - COUNT(*) as count - FROM $categorylinks - GROUP BY 1,2,3,4"; - return $s; + function getIndexField() { + return "cl_to"; } - - function sortDescending() { - return false; + + /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */ + 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(); } - - function formatResult( $skin, $result ) { + + function formatRow($result) { global $wgLang; - $title = Title::makeTitle( NS_CATEGORY, $result->title ); - $plink = $skin->makeLinkObj( $title, $title->getText() ); - $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'), - $wgLang->formatNum( $result->count ) ); - return wfSpecialList($plink, $nlinks); + $title = Title::makeTitle( NS_CATEGORY, $result->cl_to ); + return ( + '<li>' . + $this->getSkin()->makeLinkObj( $title, $title->getText() ) + . ' ' . + wfMsgExt( 'nmembers', array( 'parsemag', 'escape'), + $wgLang->formatNum( $result->count ) ) + . "</li>\n" ); } } -/** - * - */ -function wfSpecialCategories() { - list( $limit, $offset ) = wfCheckLimits(); - - $cap = new CategoriesPage(); - - return $cap->doQuery( $offset, $limit ); -} - ?> |