3 * Implements Special:Wantedcategories
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
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.
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.
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
23 * @ingroup SpecialPage
26 use MediaWiki\MediaWikiServices
;
29 * A querypage to list the most wanted categories - implements Special:Wantedcategories
31 * @ingroup SpecialPage
33 class SpecialWantedCategories
extends WantedQueryPage
{
34 private $currentCategoryCounts;
36 function __construct( $name = 'Wantedcategories' ) {
37 parent
::__construct( $name );
40 function getQueryInfo() {
42 'tables' => [ 'categorylinks', 'page' ],
44 'namespace' => NS_CATEGORY
,
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
] ] ]
56 function preprocessResults( $db, $res ) {
57 parent
::preprocessResults( $db, $res );
59 $this->currentCategoryCounts
= [];
61 if ( !$res->numRows() ||
!$this->isCached() ) {
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.
69 foreach ( $res as $row ) {
70 $allCategories[] = $row->title
;
73 $categoryRes = $db->select(
75 [ 'cat_title', 'cat_pages' ],
76 [ 'cat_title' => $allCategories ],
79 foreach ( $categoryRes as $row ) {
80 $this->currentCategoryCounts
[$row->cat_title
] = intval( $row->cat_pages
);
83 // Back to start for display
89 * @param object $result Result row
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() ) ) );
97 if ( !$this->isCached() ) {
98 // We can assume the freshest data
99 $plink = $this->getLinkRenderer()->makeBrokenLink(
103 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value
)->escaped();
105 $plink = $this->getLinkRenderer()->makeLink( $nt, $text );
107 $currentValue = $this->currentCategoryCounts
[$result->title
] ??
0;
108 $cachedValue = intval( $result->value
); // T76910
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>";
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();
120 $nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped();
124 return $this->getLanguage()->specialList( $plink, $nlinks );
127 protected function getGroupName() {
128 return 'maintenance';