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
24 function wfSpecialCategories( $par=null ) {
25 global $wgOut, $wgRequest;
28 $from = $wgRequest->getText( 'from' );
32 $cap = new CategoryPager( $from );
35 Xml
::openElement( 'div', array('class' => 'mw-spcontent') ) .
36 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
37 $cap->getStartForm( $from ) .
38 $cap->getNavigationBar() .
39 '<ul>' . $cap->getBody() . '</ul>' .
40 $cap->getNavigationBar() .
41 Xml
::closeElement( 'div' )
46 * TODO: Allow sorting by count. We need to have a unique index to do this
49 * @ingroup SpecialPage Pager
51 class CategoryPager
extends AlphabeticPager
{
52 function __construct( $from ) {
53 parent
::__construct();
54 $from = str_replace( ' ', '_', $from );
56 $from = Title
::capitalize( $from, NS_CATEGORY
);
57 $this->mOffset
= $from;
61 function getQueryInfo() {
63 'tables' => array( 'category' ),
64 'fields' => array( 'cat_title','cat_pages' ),
65 'conds' => array( 'cat_pages > 0' ),
66 'options' => array( 'USE INDEX' => 'cat_title' ),
70 function getIndexField() {
71 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
75 function getDefaultQuery() {
76 parent
::getDefaultQuery();
77 unset( $this->mDefaultQuery
['from'] );
78 return $this->mDefaultQuery
;
80 # protected function getOrderTypeMessages() {
81 # return array( 'abc' => 'special-categories-sort-abc',
82 # 'count' => 'special-categories-sort-count' );
85 protected function getDefaultDirections() {
86 # return array( 'abc' => false, 'count' => true );
90 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
91 public function getBody() {
92 $batch = new LinkBatch
;
94 $this->mResult
->rewind();
96 while ( $row = $this->mResult
->fetchObject() ) {
97 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
100 $this->mResult
->rewind();
101 return parent
::getBody();
104 function formatRow($result) {
106 $title = Title
::makeTitle( NS_CATEGORY
, $result->cat_title
);
107 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
108 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
109 $wgLang->formatNum( $result->cat_pages
) );
110 return Xml
::tags('li', null, "$titleText ($count)" ) . "\n";
113 public function getStartForm( $from ) {
115 $t = SpecialPage
::getTitleFor( 'Categories' );
118 Xml
::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
119 Xml
::hidden( 'title', $t->getPrefixedText() ) .
120 Xml
::fieldset( wfMsg( 'categories' ),
121 Xml
::inputLabel( wfMsg( 'categoriesfrom' ),
122 'from', 'from', 20, $from ) .
124 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) ) );