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
22 namespace MediaWiki\Pager
;
24 use MediaWiki\Cache\LinkBatchFactory
;
25 use MediaWiki\Context\IContextSource
;
26 use MediaWiki\Html\Html
;
27 use MediaWiki\HTMLForm\HTMLForm
;
28 use MediaWiki\Linker\LinkRenderer
;
29 use MediaWiki\Title\Title
;
30 use MediaWiki\Title\TitleValue
;
31 use Wikimedia\Rdbms\IConnectionProvider
;
36 class CategoryPager
extends AlphabeticPager
{
38 private LinkBatchFactory
$linkBatchFactory;
41 * @param IContextSource $context
42 * @param LinkBatchFactory $linkBatchFactory
43 * @param LinkRenderer $linkRenderer
44 * @param IConnectionProvider $dbProvider
47 public function __construct(
48 IContextSource
$context,
49 LinkBatchFactory
$linkBatchFactory,
50 LinkRenderer
$linkRenderer,
51 IConnectionProvider
$dbProvider,
54 // Set database before parent constructor to avoid setting it there
55 $this->mDb
= $dbProvider->getReplicaDatabase();
56 parent
::__construct( $context, $linkRenderer );
57 $this->linkBatchFactory
= $linkBatchFactory;
58 $from = str_replace( ' ', '_', $from );
60 $from = Title
::capitalize( $from, NS_CATEGORY
);
61 $this->setOffset( $from );
62 $this->setIncludeOffset( true );
66 public function getQueryInfo() {
68 'tables' => [ 'category' ],
69 'fields' => [ 'cat_title', 'cat_pages' ],
70 'options' => [ 'USE INDEX' => 'cat_title' ],
74 public function getIndexField() {
78 public function getDefaultQuery() {
79 parent
::getDefaultQuery();
80 unset( $this->mDefaultQuery
['from'] );
82 return $this->mDefaultQuery
;
85 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
86 public function getBody() {
87 $batch = $this->linkBatchFactory
->newLinkBatch();
89 $this->mResult
->rewind();
91 foreach ( $this->mResult
as $row ) {
92 $batch->add( NS_CATEGORY
, $row->cat_title
);
95 $this->mResult
->rewind();
97 return parent
::getBody();
100 public function formatRow( $result ) {
101 $title = new TitleValue( NS_CATEGORY
, $result->cat_title
);
102 $text = $title->getText();
103 $link = $this->getLinkRenderer()->makeLink( $title, $text );
105 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages
)->escaped();
106 return Html
::rawElement( 'li', [], $this->getLanguage()->specialList( $link, $count ) ) . "\n";
109 public function getStartForm( $from ) {
113 'namespace' => NS_CATEGORY
,
115 'label-message' => 'categoriesfrom',
123 $htmlForm = HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
124 ->setSubmitTextMsg( 'categories-submit' )
125 ->setWrapperLegendMsg( 'categories' )
126 ->setMethod( 'get' );
127 return $htmlForm->prepareForm()->getHTML( false );
133 * Retain the old class name for backwards compatibility.
134 * @deprecated since 1.41
136 class_alias( CategoryPager
::class, 'CategoryPager' );