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();
39 $from = $wgRequest->getText( 'from', $par );
41 $cap = new CategoryPager( $from );
45 Html
::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) .
46 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
47 $cap->getStartForm( $from ) .
48 $cap->getNavigationBar() .
49 '<ul>' . $cap->getBody() . '</ul>' .
50 $cap->getNavigationBar() .
51 Html
::closeElement( 'div' )
57 * TODO: Allow sorting by count. We need to have a unique index to do this
60 * @ingroup SpecialPage Pager
62 class CategoryPager
extends AlphabeticPager
{
63 function __construct( $from ) {
64 parent
::__construct();
65 $from = str_replace( ' ', '_', $from );
67 $from = Title
::capitalize( $from, NS_CATEGORY
);
68 $this->mOffset
= $from;
72 function getQueryInfo() {
74 'tables' => array( 'category' ),
75 'fields' => array( 'cat_title','cat_pages' ),
76 'conds' => array( 'cat_pages > 0' ),
77 'options' => array( 'USE INDEX' => 'cat_title' ),
81 function getIndexField() {
82 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
86 function getDefaultQuery() {
87 parent
::getDefaultQuery();
88 unset( $this->mDefaultQuery
['from'] );
89 return $this->mDefaultQuery
;
91 # protected function getOrderTypeMessages() {
92 # return array( 'abc' => 'special-categories-sort-abc',
93 # 'count' => 'special-categories-sort-count' );
96 protected function getDefaultDirections() {
97 # return array( 'abc' => false, 'count' => true );
101 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
102 public function getBody() {
103 $batch = new LinkBatch
;
105 $this->mResult
->rewind();
107 while ( $row = $this->mResult
->fetchObject() ) {
108 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
111 $this->mResult
->rewind();
112 return parent
::getBody();
115 function formatRow($result) {
117 $title = Title
::makeTitle( NS_CATEGORY
, $result->cat_title
);
118 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
119 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
120 $wgLang->formatNum( $result->cat_pages
) );
121 return Xml
::tags('li', null, "$titleText ($count)" ) . "\n";
124 public function getStartForm( $from ) {
126 $t = SpecialPage
::getTitleFor( 'Categories' );
129 Xml
::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
130 Xml
::hidden( 'title', $t->getPrefixedText() ) .
131 Xml
::fieldset( wfMsg( 'categories' ),
132 Xml
::inputLabel( wfMsg( 'categoriesfrom' ),
133 'from', 'from', 20, $from ) .
135 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) ) );