Standardised file description headers; first path
[lhc/web/wiklou.git] / includes / specials / SpecialCategories.php
1 <?php
2 /**
3 * Implements Special:Categories
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 function wfSpecialCategories( $par=null ) {
25 global $wgOut, $wgRequest;
26
27 if( $par == '' ) {
28 $from = $wgRequest->getText( 'from' );
29 } else {
30 $from = $par;
31 }
32 $cap = new CategoryPager( $from );
33 $cap->doQuery();
34 $wgOut->addHTML(
35 Xml::openElement( 'div', array('class' => 'mw-spcontent') ) .
36 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
37 $cap->getStartForm( $from ) .
38 $cap->getNavigationBar() .
39 '<ul>' . $cap->getBody() . '</ul>' .
40 $cap->getNavigationBar() .
41 Xml::closeElement( 'div' )
42 );
43 }
44
45 /**
46 * TODO: Allow sorting by count. We need to have a unique index to do this
47 * properly.
48 *
49 * @ingroup SpecialPage Pager
50 */
51 class CategoryPager extends AlphabeticPager {
52 function __construct( $from ) {
53 parent::__construct();
54 $from = str_replace( ' ', '_', $from );
55 if( $from !== '' ) {
56 $from = Title::capitalize( $from, NS_CATEGORY );
57 $this->mOffset = $from;
58 }
59 }
60
61 function getQueryInfo() {
62 return array(
63 'tables' => array( 'category' ),
64 'fields' => array( 'cat_title','cat_pages' ),
65 'conds' => array( 'cat_pages > 0' ),
66 'options' => array( 'USE INDEX' => 'cat_title' ),
67 );
68 }
69
70 function getIndexField() {
71 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
72 return 'cat_title';
73 }
74
75 function getDefaultQuery() {
76 parent::getDefaultQuery();
77 unset( $this->mDefaultQuery['from'] );
78 return $this->mDefaultQuery;
79 }
80 # protected function getOrderTypeMessages() {
81 # return array( 'abc' => 'special-categories-sort-abc',
82 # 'count' => 'special-categories-sort-count' );
83 # }
84
85 protected function getDefaultDirections() {
86 # return array( 'abc' => false, 'count' => true );
87 return false;
88 }
89
90 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
91 public function getBody() {
92 $batch = new LinkBatch;
93
94 $this->mResult->rewind();
95
96 while ( $row = $this->mResult->fetchObject() ) {
97 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
98 }
99 $batch->execute();
100 $this->mResult->rewind();
101 return parent::getBody();
102 }
103
104 function formatRow($result) {
105 global $wgLang;
106 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
107 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
108 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
109 $wgLang->formatNum( $result->cat_pages ) );
110 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
111 }
112
113 public function getStartForm( $from ) {
114 global $wgScript;
115 $t = SpecialPage::getTitleFor( 'Categories' );
116
117 return
118 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
119 Xml::hidden( 'title', $t->getPrefixedText() ) .
120 Xml::fieldset( wfMsg( 'categories' ),
121 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
122 'from', 'from', 20, $from ) .
123 ' ' .
124 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
125 }
126 }