4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
25 function wfSpecialCategories( $par=null ) {
26 global $wgOut, $wgRequest;
29 $from = $wgRequest->getText( 'from' );
33 $cap = new CategoryPager( $from );
36 Xml
::openElement( 'div', array('class' => 'mw-spcontent') ) .
37 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
38 $cap->getStartForm( $from ) .
39 $cap->getNavigationBar() .
40 '<ul>' . $cap->getBody() . '</ul>' .
41 $cap->getNavigationBar() .
42 Xml
::closeElement( 'div' )
47 * TODO: Allow sorting by count. We need to have a unique index to do this
50 * @ingroup SpecialPage Pager
52 class CategoryPager
extends AlphabeticPager
{
53 function __construct( $from ) {
54 parent
::__construct();
55 $from = str_replace( ' ', '_', $from );
57 $from = Title
::capitalize( $from, NS_CATEGORY
);
58 $this->mOffset
= $from;
62 function getQueryInfo() {
64 'tables' => array( 'category' ),
65 'fields' => array( 'cat_title','cat_pages' ),
66 'conds' => array( 'cat_pages > 0' ),
67 'options' => array( 'USE INDEX' => 'cat_title' ),
71 function getIndexField() {
72 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
76 function getDefaultQuery() {
77 parent
::getDefaultQuery();
78 unset( $this->mDefaultQuery
['from'] );
79 return $this->mDefaultQuery
;
81 # protected function getOrderTypeMessages() {
82 # return array( 'abc' => 'special-categories-sort-abc',
83 # 'count' => 'special-categories-sort-count' );
86 protected function getDefaultDirections() {
87 # return array( 'abc' => false, 'count' => true );
91 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
92 public function getBody() {
93 $batch = new LinkBatch
;
95 $this->mResult
->rewind();
97 while ( $row = $this->mResult
->fetchObject() ) {
98 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
101 $this->mResult
->rewind();
102 return parent
::getBody();
105 function formatRow($result) {
107 $title = Title
::makeTitle( NS_CATEGORY
, $result->cat_title
);
108 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
109 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
110 $wgLang->formatNum( $result->cat_pages
) );
111 return Xml
::tags('li', null, "$titleText ($count)" ) . "\n";
114 public function getStartForm( $from ) {
116 $t = SpecialPage
::getTitleFor( 'Categories' );
119 Xml
::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
120 Xml
::hidden( 'title', $t->getPrefixedText() ) .
121 Xml
::fieldset( wfMsg( 'categories' ),
122 Xml
::inputLabel( wfMsg( 'categoriesfrom' ),
123 'from', 'from', 20, $from ) .
125 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) ) );