DifferenceEngine cleanup
[mediawiki.git] / includes / specials / SpecialCategories.php
blobd01bfd7d3ca8c0c2044aa929fe1f76d14c1bd8cd
1 <?php
2 /**
3 * Implements Special:Categories
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * @ingroup SpecialPage
27 class SpecialCategories extends SpecialPage {
29 function __construct() {
30 parent::__construct( 'Categories' );
33 function execute( $par ) {
34 $this->setHeaders();
35 $this->outputHeader();
36 $this->getOutput()->allowClickjacking();
38 $from = $this->getRequest()->getText( 'from', $par );
40 $cap = new CategoryPager( $this->getContext(), $from );
41 $cap->doQuery();
43 $this->getOutput()->addHTML(
44 Html::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) .
45 $this->msg( 'categoriespagetext', $cap->getNumRows() )->parseAsBlock() .
46 $cap->getStartForm( $from ) .
47 $cap->getNavigationBar() .
48 '<ul>' . $cap->getBody() . '</ul>' .
49 $cap->getNavigationBar() .
50 Html::closeElement( 'div' )
54 protected function getGroupName() {
55 return 'pages';
59 /**
60 * TODO: Allow sorting by count. We need to have a unique index to do this
61 * properly.
63 * @ingroup SpecialPage Pager
65 class CategoryPager extends AlphabeticPager {
66 function __construct( IContextSource $context, $from ) {
67 parent::__construct( $context );
68 $from = str_replace( ' ', '_', $from );
69 if ( $from !== '' ) {
70 $from = Title::capitalize( $from, NS_CATEGORY );
71 $this->setOffset( $from );
72 $this->setIncludeOffset( true );
76 function getQueryInfo() {
77 return array(
78 'tables' => array( 'category' ),
79 'fields' => array( 'cat_title', 'cat_pages' ),
80 'conds' => array( 'cat_pages > 0' ),
81 'options' => array( 'USE INDEX' => 'cat_title' ),
85 function getIndexField() {
86 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
87 return 'cat_title';
90 function getDefaultQuery() {
91 parent::getDefaultQuery();
92 unset( $this->mDefaultQuery['from'] );
94 return $this->mDefaultQuery;
97 # protected function getOrderTypeMessages() {
98 # return array( 'abc' => 'special-categories-sort-abc',
99 # 'count' => 'special-categories-sort-count' );
102 protected function getDefaultDirections() {
103 # return array( 'abc' => false, 'count' => true );
104 return false;
107 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
108 public function getBody() {
109 $batch = new LinkBatch;
111 $this->mResult->rewind();
113 foreach ( $this->mResult as $row ) {
114 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
116 $batch->execute();
117 $this->mResult->rewind();
119 return parent::getBody();
122 function formatRow( $result ) {
123 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
124 $titleText = Linker::link( $title, htmlspecialchars( $title->getText() ) );
125 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped();
127 return Xml::tags( 'li', null, $this->getLanguage()->specialList( $titleText, $count ) ) . "\n";
130 public function getStartForm( $from ) {
131 global $wgScript;
133 return Xml::tags(
134 'form',
135 array( 'method' => 'get', 'action' => $wgScript ),
136 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
137 Xml::fieldset(
138 $this->msg( 'categories' )->text(),
139 Xml::inputLabel(
140 $this->msg( 'categoriesfrom' )->text(),
141 'from', 'from', 20, $from ) .
142 ' ' .
143 Xml::submitButton( $this->msg( 'allpagessubmit' )->text()