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 ) {
35 $this->outputHeader();
36 $this->getOutput()->allowClickjacking();
38 $from = $this->getRequest()->getText( 'from', $par );
40 $cap = new CategoryPager( $this->getContext(), $from );
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' )
56 * TODO: Allow sorting by count. We need to have a unique index to do this
59 * @ingroup SpecialPage Pager
61 class CategoryPager
extends AlphabeticPager
{
62 function __construct( IContextSource
$context, $from ) {
63 parent
::__construct( $context );
64 $from = str_replace( ' ', '_', $from );
66 $from = Title
::capitalize( $from, NS_CATEGORY
);
67 $this->setOffset( $from );
68 $this->setIncludeOffset( true );
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 foreach ( $this->mResult
as $row ) {
108 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
111 $this->mResult
->rewind();
112 return parent
::getBody();
115 function formatRow($result) {
116 $title = Title
::makeTitle( NS_CATEGORY
, $result->cat_title
);
117 $titleText = Linker
::link( $title, htmlspecialchars( $title->getText() ) );
118 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages
)->escaped();
119 return Xml
::tags( 'li', null, $this->getLanguage()->specialList( $titleText, $count ) ) . "\n";
122 public function getStartForm( $from ) {
126 Xml
::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
127 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
128 Xml
::fieldset( $this->msg( 'categories' )->text(),
129 Xml
::inputLabel( $this->msg( 'categoriesfrom' )->text(),
130 'from', 'from', 20, $from ) .
132 Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) ) );