Fixed HTML error when there isn't any unsettable right (XML Parsing Error: mismatched...
[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 * TODO: Allow sorting by count. We need to have a unique index to do this
21 * properly.
22 *
23 * @addtogroup SpecialPage
24 * @addtogroup Pager
25 */
26 class CategoryPager extends AlphabeticPager {
27 function getQueryInfo() {
28 global $wgRequest;
29 return array(
30 'tables' => array( 'category' ),
31 'fields' => array( 'cat_title','cat_pages' ),
32 'conds' => array( 'cat_pages > 0' )
33 );
34 }
35
36 function getIndexField() {
37 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
38 return 'cat_title';
39 }
40
41 # protected function getOrderTypeMessages() {
42 # return array( 'abc' => 'special-categories-sort-abc',
43 # 'count' => 'special-categories-sort-count' );
44 # }
45
46 protected function getDefaultDirections() {
47 # return array( 'abc' => false, 'count' => true );
48 return false;
49 }
50
51 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
52 public function getBody() {
53 if (!$this->mQueryDone) {
54 $this->doQuery();
55 }
56 $batch = new LinkBatch;
57
58 $this->mResult->rewind();
59
60 while ( $row = $this->mResult->fetchObject() ) {
61 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
62 }
63 $batch->execute();
64 $this->mResult->rewind();
65 return parent::getBody();
66 }
67
68 function formatRow($result) {
69 global $wgLang;
70 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
71 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
72 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
73 $wgLang->formatNum( $result->cat_pages ) );
74 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
75 }
76 }