]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialCategories.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.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 /**
25  * @ingroup SpecialPage
26  */
27 class SpecialCategories extends SpecialPage {
28
29         function __construct() {
30                 parent::__construct( 'Categories' );
31         }
32
33         function execute( $par ) {
34                 global $wgOut, $wgRequest;
35
36                 $this->setHeaders();
37                 $this->outputHeader();
38                 $wgOut->allowClickjacking();
39
40                 $from = $wgRequest->getText( 'from', $par );
41
42                 $cap = new CategoryPager( $from );
43                 $cap->doQuery();
44
45                 $wgOut->addHTML(
46                         Html::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) .
47                         wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
48                         $cap->getStartForm( $from ) .
49                         $cap->getNavigationBar() .
50                         '<ul>' . $cap->getBody() . '</ul>' .
51                         $cap->getNavigationBar() .
52                         Html::closeElement( 'div' )
53                 );
54         }
55 }
56
57 /**
58  * TODO: Allow sorting by count.  We need to have a unique index to do this
59  * properly.
60  *
61  * @ingroup SpecialPage Pager
62  */
63 class CategoryPager extends AlphabeticPager {
64         function __construct( $from ) {
65                 parent::__construct();
66                 $from = str_replace( ' ', '_', $from );
67                 if( $from !== '' ) {
68                         $from = Title::capitalize( $from, NS_CATEGORY );
69                         $this->mOffset = $from;
70                 }
71         }
72         
73         function getQueryInfo() {
74                 return array(
75                         'tables' => array( 'category' ),
76                         'fields' => array( 'cat_title','cat_pages' ),
77                         'conds' => array( 'cat_pages > 0' ), 
78                         'options' => array( 'USE INDEX' => 'cat_title' ),
79                 );
80         }
81
82         function getIndexField() {
83 #               return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
84                 return 'cat_title';
85         }
86
87         function getDefaultQuery() {
88                 parent::getDefaultQuery();
89                 unset( $this->mDefaultQuery['from'] );
90                 return $this->mDefaultQuery;
91         }
92 #       protected function getOrderTypeMessages() {
93 #               return array( 'abc' => 'special-categories-sort-abc',
94 #                       'count' => 'special-categories-sort-count' );
95 #       }
96
97         protected function getDefaultDirections() {
98 #               return array( 'abc' => false, 'count' => true );
99                 return false;
100         }
101
102         /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
103         public function getBody() {
104                 $batch = new LinkBatch;
105
106                 $this->mResult->rewind();
107
108                 foreach ( $this->mResult as $row ) {
109                         $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
110                 }
111                 $batch->execute();
112                 $this->mResult->rewind();
113                 return parent::getBody();
114         }
115
116         function formatRow($result) {
117                 global $wgLang;
118                 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
119                 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
120                 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
121                                 $wgLang->formatNum( $result->cat_pages ) );
122                 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
123         }
124         
125         public function getStartForm( $from ) {
126                 global $wgScript;
127                 $t = SpecialPage::getTitleFor( 'Categories' );
128         
129                 return
130                         Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
131                                 Html::hidden( 'title', $t->getPrefixedText() ) .
132                                 Xml::fieldset( wfMsg( 'categories' ),
133                                         Xml::inputLabel( wfMsg( 'categoriesfrom' ),
134                                                 'from', 'from', 20, $from ) .
135                                         ' ' .
136                                         Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
137         }
138 }