Use category table for more efficient display of Special:Categories. I never realize...
[lhc/web/wiklou.git] / includes / SpecialCategories.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 function wfSpecialCategories() {
8 global $wgOut;
9
10 $cap = new CategoryPager();
11 $wgOut->addHTML(
12 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
13 $cap->getNavigationBar()
14 . '<ul>' . $cap->getBody() . '</ul>' .
15 $cap->getNavigationBar()
16 );
17 }
18
19 /**
20 * @addtogroup SpecialPage
21 * @addtogroup Pager
22 */
23 class CategoryPager extends AlphabeticPager {
24 function getQueryInfo() {
25 global $wgRequest;
26 return array(
27 'tables' => array('category'),
28 'fields' => array('cat_title','cat_pages')
29 );
30 }
31
32 function getIndexField() {
33 return "cat_title";
34 }
35
36 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
37 function getBody() {
38 if (!$this->mQueryDone) {
39 $this->doQuery();
40 }
41 $batch = new LinkBatch;
42
43 $this->mResult->rewind();
44
45 while ( $row = $this->mResult->fetchObject() ) {
46 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
47 }
48 $batch->execute();
49 $this->mResult->rewind();
50 return parent::getBody();
51 }
52
53 function formatRow($result) {
54 global $wgLang;
55 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
56 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
57 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
58 $wgLang->formatNum( $result->cat_pages ) );
59 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
60 }
61 }
62
63