Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / SpecialCategories.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 function wfSpecialCategories( $par=null ) {
8 global $wgOut, $wgRequest;
9
10 if( $par == '' ) {
11 $from = $wgRequest->getText( 'from' );
12 } else {
13 $from = $par;
14 }
15 $cap = new CategoryPager( $from );
16 $wgOut->addHTML(
17 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
18 $cap->getStartForm( $from ) .
19 $cap->getNavigationBar() .
20 '<ul>' . $cap->getBody() . '</ul>' .
21 $cap->getNavigationBar()
22 );
23 }
24
25 /**
26 * TODO: Allow sorting by count. We need to have a unique index to do this
27 * properly.
28 *
29 * @ingroup SpecialPage Pager
30 */
31 class CategoryPager extends AlphabeticPager {
32 function __construct( $from ) {
33 parent::__construct();
34 $from = str_replace( ' ', '_', $from );
35 if( $from !== '' ) {
36 global $wgCapitalLinks, $wgContLang;
37 if( $wgCapitalLinks ) {
38 $from = $wgContLang->ucfirst( $from );
39 }
40 $this->mOffset = $from;
41 }
42 }
43
44 function getQueryInfo() {
45 global $wgRequest;
46 return array(
47 'tables' => array( 'category' ),
48 'fields' => array( 'cat_title','cat_pages' ),
49 'conds' => array( 'cat_pages > 0' ),
50 'options' => array( 'USE INDEX' => 'cat_title' ),
51 );
52 }
53
54 function getIndexField() {
55 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
56 return 'cat_title';
57 }
58
59 function getDefaultQuery() {
60 parent::getDefaultQuery();
61 unset( $this->mDefaultQuery['from'] );
62 }
63 # protected function getOrderTypeMessages() {
64 # return array( 'abc' => 'special-categories-sort-abc',
65 # 'count' => 'special-categories-sort-count' );
66 # }
67
68 protected function getDefaultDirections() {
69 # return array( 'abc' => false, 'count' => true );
70 return false;
71 }
72
73 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
74 public function getBody() {
75 if (!$this->mQueryDone) {
76 $this->doQuery();
77 }
78 $batch = new LinkBatch;
79
80 $this->mResult->rewind();
81
82 while ( $row = $this->mResult->fetchObject() ) {
83 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
84 }
85 $batch->execute();
86 $this->mResult->rewind();
87 return parent::getBody();
88 }
89
90 function formatRow($result) {
91 global $wgLang;
92 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
93 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
94 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
95 $wgLang->formatNum( $result->cat_pages ) );
96 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
97 }
98
99 public function getStartForm( $from ) {
100 global $wgScript;
101 $t = SpecialPage::getTitleFor( 'Categories' );
102
103 return
104 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
105 Xml::hidden( 'title', $t->getPrefixedText() ) .
106 Xml::fieldset( wfMsg( 'categories' ),
107 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
108 'from', 'from', 20, $from ) .
109 ' ' .
110 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
111 }
112 }