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
21 * @ingroup SpecialPage
25 * @ingroup SpecialPage
27 class SpecialCategories extends SpecialPage {
29 function __construct() {
30 parent::__construct( 'Categories' );
33 function execute( $par ) {
34 global $wgOut, $wgRequest;
37 $this->outputHeader();
38 $wgOut->allowClickjacking();
40 $from = $wgRequest->getText( 'from', $par );
42 $cap = new CategoryPager( $from );
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' )
58 * TODO: Allow sorting by count. We need to have a unique index to do this
61 * @ingroup SpecialPage Pager
63 class CategoryPager extends AlphabeticPager {
64 function __construct( $from ) {
65 parent::__construct();
66 $from = str_replace( ' ', '_', $from );
68 $from = Title::capitalize( $from, NS_CATEGORY );
69 $this->mOffset = $from;
73 function getQueryInfo() {
75 'tables' => array( 'category' ),
76 'fields' => array( 'cat_title','cat_pages' ),
77 'conds' => array( 'cat_pages > 0' ),
78 'options' => array( 'USE INDEX' => 'cat_title' ),
82 function getIndexField() {
83 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
87 function getDefaultQuery() {
88 parent::getDefaultQuery();
89 unset( $this->mDefaultQuery['from'] );
90 return $this->mDefaultQuery;
92 # protected function getOrderTypeMessages() {
93 # return array( 'abc' => 'special-categories-sort-abc',
94 # 'count' => 'special-categories-sort-count' );
97 protected function getDefaultDirections() {
98 # return array( 'abc' => false, 'count' => true );
102 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
103 public function getBody() {
104 $batch = new LinkBatch;
106 $this->mResult->rewind();
108 foreach ( $this->mResult as $row ) {
109 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
112 $this->mResult->rewind();
113 return parent::getBody();
116 function formatRow($result) {
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";
125 public function getStartForm( $from ) {
127 $t = SpecialPage::getTitleFor( 'Categories' );
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 ) .
136 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );