Allow partially blocked users to tag unrelated revisions
[lhc/web/wiklou.git] / includes / specials / SpecialWantedcategories.php
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 use MediaWiki\MediaWikiServices;
27
28 /**
29 * A querypage to list the most wanted categories - implements Special:Wantedcategories
30 *
31 * @ingroup SpecialPage
32 */
33 class WantedCategoriesPage extends WantedQueryPage {
34 private $currentCategoryCounts;
35
36 function __construct( $name = 'Wantedcategories' ) {
37 parent::__construct( $name );
38 }
39
40 function getQueryInfo() {
41 return [
42 'tables' => [ 'categorylinks', 'page' ],
43 'fields' => [
44 'namespace' => NS_CATEGORY,
45 'title' => 'cl_to',
46 'value' => 'COUNT(*)'
47 ],
48 'conds' => [ 'page_title IS NULL' ],
49 'options' => [ 'GROUP BY' => 'cl_to' ],
50 'join_conds' => [ 'page' => [ 'LEFT JOIN',
51 [ 'page_title = cl_to',
52 'page_namespace' => NS_CATEGORY ] ] ]
53 ];
54 }
55
56 function preprocessResults( $db, $res ) {
57 parent::preprocessResults( $db, $res );
58
59 $this->currentCategoryCounts = [];
60
61 if ( !$res->numRows() || !$this->isCached() ) {
62 return;
63 }
64
65 // Fetch (hopefully) up-to-date numbers of pages in each category.
66 // This should be fast enough as we limit the list to a reasonable length.
67
68 $allCategories = [];
69 foreach ( $res as $row ) {
70 $allCategories[] = $row->title;
71 }
72
73 $categoryRes = $db->select(
74 'category',
75 [ 'cat_title', 'cat_pages' ],
76 [ 'cat_title' => $allCategories ],
77 __METHOD__
78 );
79 foreach ( $categoryRes as $row ) {
80 $this->currentCategoryCounts[$row->cat_title] = intval( $row->cat_pages );
81 }
82
83 // Back to start for display
84 $res->seek( 0 );
85 }
86
87 /**
88 * @param Skin $skin
89 * @param object $result Result row
90 * @return string
91 */
92 function formatResult( $skin, $result ) {
93 $nt = Title::makeTitle( $result->namespace, $result->title );
94 $text = new HtmlArmor( MediaWikiServices::getInstance()->getContentLanguage()
95 ->convert( htmlspecialchars( $nt->getText() ) ) );
96
97 if ( !$this->isCached() ) {
98 // We can assume the freshest data
99 $plink = $this->getLinkRenderer()->makeBrokenLink(
100 $nt,
101 $text
102 );
103 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
104 } else {
105 $plink = $this->getLinkRenderer()->makeLink( $nt, $text );
106
107 $currentValue = $this->currentCategoryCounts[$result->title] ?? 0;
108 $cachedValue = intval( $result->value ); // T76910
109
110 // If the category has been created or emptied since the list was refreshed, strike it
111 if ( $nt->isKnown() || $currentValue === 0 ) {
112 $plink = "<del>$plink</del>";
113 }
114
115 // Show the current number of category entries if it changed
116 if ( $currentValue !== $cachedValue ) {
117 $nlinks = $this->msg( 'nmemberschanged' )
118 ->numParams( $cachedValue, $currentValue )->escaped();
119 } else {
120 $nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped();
121 }
122 }
123
124 return $this->getLanguage()->specialList( $plink, $nlinks );
125 }
126
127 protected function getGroupName() {
128 return 'maintenance';
129 }
130 }