Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialWantedCategories | |
0.00% |
0 / 51 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
preprocessResults | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
formatResult | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Wantedcategories |
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 | */ |
25 | |
26 | namespace MediaWiki\Specials; |
27 | |
28 | use HtmlArmor; |
29 | use ILanguageConverter; |
30 | use MediaWiki\Cache\LinkBatchFactory; |
31 | use MediaWiki\Languages\LanguageConverterFactory; |
32 | use MediaWiki\SpecialPage\WantedQueryPage; |
33 | use MediaWiki\Title\Title; |
34 | use Skin; |
35 | use stdClass; |
36 | use Wikimedia\Rdbms\IConnectionProvider; |
37 | |
38 | /** |
39 | * A querypage to list the most wanted categories - implements Special:Wantedcategories |
40 | * |
41 | * @ingroup SpecialPage |
42 | */ |
43 | class SpecialWantedCategories extends WantedQueryPage { |
44 | private $currentCategoryCounts; |
45 | |
46 | private ILanguageConverter $languageConverter; |
47 | |
48 | /** |
49 | * @param IConnectionProvider $dbProvider |
50 | * @param LinkBatchFactory $linkBatchFactory |
51 | * @param LanguageConverterFactory $languageConverterFactory |
52 | */ |
53 | public function __construct( |
54 | IConnectionProvider $dbProvider, |
55 | LinkBatchFactory $linkBatchFactory, |
56 | LanguageConverterFactory $languageConverterFactory |
57 | ) { |
58 | parent::__construct( 'Wantedcategories' ); |
59 | $this->setDatabaseProvider( $dbProvider ); |
60 | $this->setLinkBatchFactory( $linkBatchFactory ); |
61 | $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ); |
62 | } |
63 | |
64 | public function getQueryInfo() { |
65 | return [ |
66 | 'tables' => [ 'categorylinks', 'page' ], |
67 | 'fields' => [ |
68 | 'namespace' => NS_CATEGORY, |
69 | 'title' => 'cl_to', |
70 | 'value' => 'COUNT(*)' |
71 | ], |
72 | 'conds' => [ 'page_title' => null ], |
73 | 'options' => [ 'GROUP BY' => 'cl_to' ], |
74 | 'join_conds' => [ 'page' => [ 'LEFT JOIN', |
75 | [ 'page_title = cl_to', |
76 | 'page_namespace' => NS_CATEGORY ] ] ] |
77 | ]; |
78 | } |
79 | |
80 | public function preprocessResults( $db, $res ) { |
81 | parent::preprocessResults( $db, $res ); |
82 | |
83 | $this->currentCategoryCounts = []; |
84 | |
85 | if ( !$res->numRows() || !$this->isCached() ) { |
86 | return; |
87 | } |
88 | |
89 | // Fetch (hopefully) up-to-date numbers of pages in each category. |
90 | // This should be fast enough as we limit the list to a reasonable length. |
91 | |
92 | $allCategories = []; |
93 | foreach ( $res as $row ) { |
94 | $allCategories[] = $row->title; |
95 | } |
96 | |
97 | $categoryRes = $db->newSelectQueryBuilder() |
98 | ->select( [ 'cat_title', 'cat_pages' ] ) |
99 | ->from( 'category' ) |
100 | ->where( [ 'cat_title' => $allCategories ] ) |
101 | ->caller( __METHOD__ )->fetchResultSet(); |
102 | foreach ( $categoryRes as $row ) { |
103 | $this->currentCategoryCounts[$row->cat_title] = intval( $row->cat_pages ); |
104 | } |
105 | |
106 | // Back to start for display |
107 | $res->seek( 0 ); |
108 | } |
109 | |
110 | /** |
111 | * @param Skin $skin |
112 | * @param stdClass $result Result row |
113 | * @return string |
114 | */ |
115 | public function formatResult( $skin, $result ) { |
116 | $nt = Title::makeTitle( $result->namespace, $result->title ); |
117 | |
118 | $text = new HtmlArmor( $this->languageConverter->convertHtml( $nt->getText() ) ); |
119 | |
120 | if ( !$this->isCached() ) { |
121 | // We can assume the freshest data |
122 | $plink = $this->getLinkRenderer()->makeBrokenLink( |
123 | $nt, |
124 | $text |
125 | ); |
126 | $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); |
127 | } else { |
128 | $plink = $this->getLinkRenderer()->makeLink( $nt, $text ); |
129 | |
130 | $currentValue = $this->currentCategoryCounts[$result->title] ?? 0; |
131 | $cachedValue = intval( $result->value ); // T76910 |
132 | |
133 | // If the category has been created or emptied since the list was refreshed, strike it |
134 | if ( $nt->isKnown() || $currentValue === 0 ) { |
135 | $plink = "<del>$plink</del>"; |
136 | } |
137 | |
138 | // Show the current number of category entries if it changed |
139 | if ( $currentValue !== $cachedValue ) { |
140 | $nlinks = $this->msg( 'nmemberschanged' ) |
141 | ->numParams( $cachedValue, $currentValue )->escaped(); |
142 | } else { |
143 | $nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped(); |
144 | } |
145 | } |
146 | |
147 | return $this->getLanguage()->specialList( $plink, $nlinks ); |
148 | } |
149 | |
150 | protected function getGroupName() { |
151 | return 'maintenance'; |
152 | } |
153 | } |
154 | |
155 | /** |
156 | * Retain the old class name for backwards compatibility. |
157 | * @deprecated since 1.41 |
158 | */ |
159 | class_alias( SpecialWantedCategories::class, 'SpecialWantedCategories' ); |