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 private $conds = array( 'cat_pages > 0' );
64 function __construct( IContextSource
$context, $from ) {
65 parent
::__construct( $context );
66 $from = str_replace( ' ', '_', $from );
68 $from = Title
::capitalize( $from, NS_CATEGORY
);
69 $dbr = wfGetDB( DB_SLAVE
);
70 $this->conds
[] = 'cat_title >= ' . $dbr->addQuotes( $from );
71 $this->setOffset( '' );
75 function getQueryInfo() {
77 'tables' => array( 'category' ),
78 'fields' => array( 'cat_title','cat_pages' ),
79 'conds' => $this->conds
,
80 'options' => array( 'USE INDEX' => 'cat_title' ),
84 function getIndexField() {
85 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
89 function getDefaultQuery() {
90 parent
::getDefaultQuery();
91 unset( $this->mDefaultQuery
['from'] );
92 return $this->mDefaultQuery
;
94 # protected function getOrderTypeMessages() {
95 # return array( 'abc' => 'special-categories-sort-abc',
96 # 'count' => 'special-categories-sort-count' );
99 protected function getDefaultDirections() {
100 # return array( 'abc' => false, 'count' => true );
104 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
105 public function getBody() {
106 $batch = new LinkBatch
;
108 $this->mResult
->rewind();
110 foreach ( $this->mResult
as $row ) {
111 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
114 $this->mResult
->rewind();
115 return parent
::getBody();
118 function formatRow($result) {
119 $title = Title
::makeTitle( NS_CATEGORY
, $result->cat_title
);
120 $titleText = Linker
::link( $title, htmlspecialchars( $title->getText() ) );
121 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages
)->escaped();
122 return Xml
::tags( 'li', null, $this->getLanguage()->specialList( $titleText, $count ) ) . "\n";
125 public function getStartForm( $from ) {
129 Xml
::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
130 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
131 Xml
::fieldset( $this->msg( 'categories' )->text(),
132 Xml
::inputLabel( $this->msg( 'categoriesfrom' )->text(),
133 'from', 'from', 20, $from ) .
135 Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) ) );