Disable hooks display in Special:Version by default. It's unnecessarily technical...
[lhc/web/wiklou.git] / includes / SpecialCategories.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 function wfSpecialCategories() {
8 global $wgOut, $wgRequest;
9
10 $cap = new CategoryPager();
11 $wgOut->addHTML(
12 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
13 $cap->getStartForm( str_replace( '_', ' ', $wgRequest->getVal( 'offset' ) ) ) .
14 $cap->getNavigationBar() .
15 '<ul>' . $cap->getBody() . '</ul>' .
16 $cap->getNavigationBar()
17 );
18 }
19
20 /**
21 * TODO: Allow sorting by count. We need to have a unique index to do this
22 * properly.
23 *
24 * @ingroup SpecialPage 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 'options' => array( 'USE INDEX' => 'cat_title' ),
34 );
35 }
36
37 function getIndexField() {
38 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
39 return 'cat_title';
40 }
41
42 # protected function getOrderTypeMessages() {
43 # return array( 'abc' => 'special-categories-sort-abc',
44 # 'count' => 'special-categories-sort-count' );
45 # }
46
47 protected function getDefaultDirections() {
48 # return array( 'abc' => false, 'count' => true );
49 return false;
50 }
51
52 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
53 public function getBody() {
54 if (!$this->mQueryDone) {
55 $this->doQuery();
56 }
57 $batch = new LinkBatch;
58
59 $this->mResult->rewind();
60
61 while ( $row = $this->mResult->fetchObject() ) {
62 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
63 }
64 $batch->execute();
65 $this->mResult->rewind();
66 return parent::getBody();
67 }
68
69 function formatRow($result) {
70 global $wgLang;
71 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
72 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
73 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
74 $wgLang->formatNum( $result->cat_pages ) );
75 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
76 }
77
78 public function getStartForm( $from='' ) {
79 global $wgScript;
80 $t = SpecialPage::getTitleFor( 'Categories' );
81
82 return
83 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
84 Xml::hidden( 'title', $t->getPrefixedText() ) .
85 Xml::fieldset( wfMsg( 'categories' ),
86 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
87 'offset', 'offset', 20, $from ) .
88 ' ' .
89 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
90 }
91 }