Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
SpecialMostCategories | |
0.00% |
0 / 46 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Mostcategories |
4 | * |
5 | * Copyright © 2005 Ævar Arnfjörð Bjarmason |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * http://www.gnu.org/copyleft/gpl.html |
21 | * |
22 | * @file |
23 | * @ingroup SpecialPage |
24 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
25 | */ |
26 | |
27 | namespace MediaWiki\Specials; |
28 | |
29 | use MediaWiki\Cache\LinkBatchFactory; |
30 | use MediaWiki\Html\Html; |
31 | use MediaWiki\Linker\Linker; |
32 | use MediaWiki\SpecialPage\QueryPage; |
33 | use MediaWiki\Title\NamespaceInfo; |
34 | use MediaWiki\Title\Title; |
35 | use Skin; |
36 | use stdClass; |
37 | use Wikimedia\Rdbms\IConnectionProvider; |
38 | use Wikimedia\Rdbms\IDatabase; |
39 | use Wikimedia\Rdbms\IResultWrapper; |
40 | |
41 | /** |
42 | * A special page that list pages that have highest category count |
43 | * |
44 | * @ingroup SpecialPage |
45 | */ |
46 | class SpecialMostCategories extends QueryPage { |
47 | |
48 | private NamespaceInfo $namespaceInfo; |
49 | |
50 | /** |
51 | * @param NamespaceInfo $namespaceInfo |
52 | * @param IConnectionProvider $dbProvider |
53 | * @param LinkBatchFactory $linkBatchFactory |
54 | */ |
55 | public function __construct( |
56 | NamespaceInfo $namespaceInfo, |
57 | IConnectionProvider $dbProvider, |
58 | LinkBatchFactory $linkBatchFactory |
59 | ) { |
60 | parent::__construct( 'Mostcategories' ); |
61 | $this->namespaceInfo = $namespaceInfo; |
62 | $this->setDatabaseProvider( $dbProvider ); |
63 | $this->setLinkBatchFactory( $linkBatchFactory ); |
64 | } |
65 | |
66 | public function isExpensive() { |
67 | return true; |
68 | } |
69 | |
70 | public function isSyndicated() { |
71 | return false; |
72 | } |
73 | |
74 | public function getQueryInfo() { |
75 | return [ |
76 | 'tables' => [ 'categorylinks', 'page' ], |
77 | 'fields' => [ |
78 | 'namespace' => 'page_namespace', |
79 | 'title' => 'page_title', |
80 | 'value' => 'COUNT(*)' |
81 | ], |
82 | 'conds' => [ |
83 | 'page_namespace' => $this->namespaceInfo->getContentNamespaces() |
84 | ], |
85 | 'options' => [ |
86 | 'HAVING' => 'COUNT(*) > 1', |
87 | 'GROUP BY' => [ 'page_namespace', 'page_title' ] |
88 | ], |
89 | 'join_conds' => [ |
90 | 'page' => [ |
91 | 'LEFT JOIN', |
92 | 'page_id = cl_from' |
93 | ] |
94 | ] |
95 | ]; |
96 | } |
97 | |
98 | /** |
99 | * @param IDatabase $db |
100 | * @param IResultWrapper $res |
101 | */ |
102 | public function preprocessResults( $db, $res ) { |
103 | $this->executeLBFromResultWrapper( $res ); |
104 | } |
105 | |
106 | /** |
107 | * @param Skin $skin |
108 | * @param stdClass $result Result row |
109 | * @return string |
110 | */ |
111 | public function formatResult( $skin, $result ) { |
112 | $title = Title::makeTitleSafe( $result->namespace, $result->title ); |
113 | if ( !$title ) { |
114 | return Html::element( |
115 | 'span', |
116 | [ 'class' => 'mw-invalidtitle' ], |
117 | Linker::getInvalidTitleDescription( |
118 | $this->getContext(), |
119 | $result->namespace, |
120 | $result->title |
121 | ) |
122 | ); |
123 | } |
124 | |
125 | $linkRenderer = $this->getLinkRenderer(); |
126 | if ( $this->isCached() ) { |
127 | $link = $linkRenderer->makeLink( $title ); |
128 | } else { |
129 | $link = $linkRenderer->makeKnownLink( $title ); |
130 | } |
131 | |
132 | $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped(); |
133 | |
134 | return $this->getLanguage()->specialList( $link, $count ); |
135 | } |
136 | |
137 | protected function getGroupName() { |
138 | return 'highuse'; |
139 | } |
140 | } |
141 | |
142 | /** |
143 | * Retain the old class name for backwards compatibility. |
144 | * @deprecated since 1.41 |
145 | */ |
146 | class_alias( SpecialMostCategories::class, 'SpecialMostCategories' ); |