Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
CategoryPager | |
0.00% |
0 / 46 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getQueryInfo | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultQuery | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getBody | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
formatRow | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getStartForm | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | * @ingroup Pager |
20 | */ |
21 | |
22 | namespace MediaWiki\Pager; |
23 | |
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; |
32 | |
33 | /** |
34 | * @ingroup Pager |
35 | */ |
36 | class CategoryPager extends AlphabeticPager { |
37 | |
38 | private LinkBatchFactory $linkBatchFactory; |
39 | |
40 | /** |
41 | * @param IContextSource $context |
42 | * @param LinkBatchFactory $linkBatchFactory |
43 | * @param LinkRenderer $linkRenderer |
44 | * @param IConnectionProvider $dbProvider |
45 | * @param string $from |
46 | */ |
47 | public function __construct( |
48 | IContextSource $context, |
49 | LinkBatchFactory $linkBatchFactory, |
50 | LinkRenderer $linkRenderer, |
51 | IConnectionProvider $dbProvider, |
52 | $from |
53 | ) { |
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 ); |
59 | if ( $from !== '' ) { |
60 | $from = Title::capitalize( $from, NS_CATEGORY ); |
61 | $this->setOffset( $from ); |
62 | $this->setIncludeOffset( true ); |
63 | } |
64 | } |
65 | |
66 | public function getQueryInfo() { |
67 | return [ |
68 | 'tables' => [ 'category' ], |
69 | 'fields' => [ 'cat_title', 'cat_pages' ], |
70 | 'options' => [ 'USE INDEX' => 'cat_title' ], |
71 | ]; |
72 | } |
73 | |
74 | public function getIndexField() { |
75 | return 'cat_title'; |
76 | } |
77 | |
78 | public function getDefaultQuery() { |
79 | parent::getDefaultQuery(); |
80 | unset( $this->mDefaultQuery['from'] ); |
81 | |
82 | return $this->mDefaultQuery; |
83 | } |
84 | |
85 | /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */ |
86 | public function getBody() { |
87 | $batch = $this->linkBatchFactory->newLinkBatch(); |
88 | |
89 | $this->mResult->rewind(); |
90 | |
91 | foreach ( $this->mResult as $row ) { |
92 | $batch->add( NS_CATEGORY, $row->cat_title ); |
93 | } |
94 | $batch->execute(); |
95 | $this->mResult->rewind(); |
96 | |
97 | return parent::getBody(); |
98 | } |
99 | |
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 ); |
104 | |
105 | $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped(); |
106 | return Html::rawElement( 'li', [], $this->getLanguage()->specialList( $link, $count ) ) . "\n"; |
107 | } |
108 | |
109 | public function getStartForm( $from ) { |
110 | $formDescriptor = [ |
111 | 'from' => [ |
112 | 'type' => 'title', |
113 | 'namespace' => NS_CATEGORY, |
114 | 'relative' => true, |
115 | 'label-message' => 'categoriesfrom', |
116 | 'name' => 'from', |
117 | 'id' => 'from', |
118 | 'size' => 20, |
119 | 'default' => $from, |
120 | ], |
121 | ]; |
122 | |
123 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
124 | ->setSubmitTextMsg( 'categories-submit' ) |
125 | ->setWrapperLegendMsg( 'categories' ) |
126 | ->setMethod( 'get' ); |
127 | return $htmlForm->prepareForm()->getHTML( false ); |
128 | } |
129 | |
130 | } |
131 | |
132 | /** |
133 | * Retain the old class name for backwards compatibility. |
134 | * @deprecated since 1.41 |
135 | */ |
136 | class_alias( CategoryPager::class, 'CategoryPager' ); |