MediaWiki REL1_34
SpecialWantedCategories.php
Go to the documentation of this file.
1<?php
27
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
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}
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:28
MediaWikiServices is the service locator for the application scope of MediaWiki.
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
A querypage to list the most wanted categories - implements Special:Wantedcategories.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
preprocessResults( $db, $res)
Cache page existence for performance.
__construct( $name='Wantedcategories')
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
const NS_CATEGORY
Definition Defines.php:83