3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
23 * TODO: Allow sorting by count. We need to have a unique index to do this
28 class CategoryPager
extends AlphabeticPager
{
31 * @var PageLinkRenderer
33 protected $linkRenderer;
36 * @param IContextSource $context
38 * @param PageLinkRenderer $linkRenderer
40 public function __construct( IContextSource
$context, $from, PageLinkRenderer
$linkRenderer
42 parent
::__construct( $context );
43 $from = str_replace( ' ', '_', $from );
45 $from = Title
::capitalize( $from, NS_CATEGORY
);
46 $this->setOffset( $from );
47 $this->setIncludeOffset( true );
50 $this->linkRenderer
= $linkRenderer;
53 function getQueryInfo() {
55 'tables' => [ 'category' ],
56 'fields' => [ 'cat_title', 'cat_pages' ],
57 'conds' => [ 'cat_pages > 0' ],
58 'options' => [ 'USE INDEX' => 'cat_title' ],
62 function getIndexField() {
63 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
67 function getDefaultQuery() {
68 parent
::getDefaultQuery();
69 unset( $this->mDefaultQuery
['from'] );
71 return $this->mDefaultQuery
;
74 # protected function getOrderTypeMessages() {
75 # return array( 'abc' => 'special-categories-sort-abc',
76 # 'count' => 'special-categories-sort-count' );
79 protected function getDefaultDirections() {
80 # return array( 'abc' => false, 'count' => true );
84 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
85 public function getBody() {
86 $batch = new LinkBatch
;
88 $this->mResult
->rewind();
90 foreach ( $this->mResult
as $row ) {
91 $batch->addObj( Title
::makeTitleSafe( NS_CATEGORY
, $row->cat_title
) );
94 $this->mResult
->rewind();
96 return parent
::getBody();
99 function formatRow( $result ) {
100 $title = new TitleValue( NS_CATEGORY
, $result->cat_title
);
101 $text = $title->getText();
102 $link = $this->linkRenderer
->renderHtmlLink( $title, $text );
104 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages
)->escaped();
105 return Html
::rawElement( 'li', null, $this->getLanguage()->specialList( $link, $count ) ) . "\n";
108 public function getStartForm( $from ) {
111 [ 'method' => 'get', 'action' => wfScript() ],
112 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
114 $this->msg( 'categories' )->text(),
116 $this->msg( 'categoriesfrom' )->text(),
117 'from', 'from', 20, $from, [ 'class' => 'mw-ui-input-inline' ] ) .
120 $this->msg( 'categories-submit' )->text(),
121 [], [ 'mw-ui-progressive' ]