* partly fixes two issues exposed by bug 34280
[mediawiki.git] / includes / specials / SpecialCategories.php
blob6d2831c7b0433ad4e17de4e1687618ab1674f23c
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' )
55 /**
56 * TODO: Allow sorting by count. We need to have a unique index to do this
57 * properly.
59 * @ingroup SpecialPage Pager
61 class CategoryPager extends AlphabeticPager {
62 function __construct( IContextSource $context, $from ) {
63 parent::__construct( $context );
64 $from = str_replace( ' ', '_', $from );
65 if( $from !== '' ) {
66 $from = Title::capitalize( $from, NS_CATEGORY );
67 $this->mOffset = $from;
71 function getQueryInfo() {
72 return array(
73 'tables' => array( 'category' ),
74 'fields' => array( 'cat_title','cat_pages' ),
75 'conds' => array( 'cat_pages > 0' ),
76 'options' => array( 'USE INDEX' => 'cat_title' ),
80 function getIndexField() {
81 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
82 return 'cat_title';
85 function getDefaultQuery() {
86 parent::getDefaultQuery();
87 unset( $this->mDefaultQuery['from'] );
88 return $this->mDefaultQuery;
90 # protected function getOrderTypeMessages() {
91 # return array( 'abc' => 'special-categories-sort-abc',
92 # 'count' => 'special-categories-sort-count' );
93 # }
95 protected function getDefaultDirections() {
96 # return array( 'abc' => false, 'count' => true );
97 return false;
100 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
101 public function getBody() {
102 $batch = new LinkBatch;
104 $this->mResult->rewind();
106 foreach ( $this->mResult as $row ) {
107 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
109 $batch->execute();
110 $this->mResult->rewind();
111 return parent::getBody();
114 function formatRow($result) {
115 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
116 $titleText = Linker::link( $title, htmlspecialchars( $title->getText() ) );
117 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped();
118 return Xml::tags( 'li', null, $this->getLanguage()->specialList( $titleText, $count ) ) . "\n";
121 public function getStartForm( $from ) {
122 global $wgScript;
124 return
125 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
126 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
127 Xml::fieldset( $this->msg( 'categories' )->text(),
128 Xml::inputLabel( $this->msg( 'categoriesfrom' )->text(),
129 'from', 'from', 20, $from ) .
130 ' ' .
131 Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) ) );