MediaWiki REL1_40
SpecialWantedCategories.php
Go to the documentation of this file.
1<?php
30
37 private $currentCategoryCounts;
38
40 private $languageConverter;
41
47 public function __construct(
48 ILoadBalancer $loadBalancer,
49 LinkBatchFactory $linkBatchFactory,
50 LanguageConverterFactory $languageConverterFactory
51 ) {
52 parent::__construct( 'Wantedcategories' );
53 $this->setDBLoadBalancer( $loadBalancer );
54 $this->setLinkBatchFactory( $linkBatchFactory );
55 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
56 }
57
58 public function getQueryInfo() {
59 return [
60 'tables' => [ 'categorylinks', 'page' ],
61 'fields' => [
62 'namespace' => NS_CATEGORY,
63 'title' => 'cl_to',
64 'value' => 'COUNT(*)'
65 ],
66 'conds' => [ 'page_title IS NULL' ],
67 'options' => [ 'GROUP BY' => 'cl_to' ],
68 'join_conds' => [ 'page' => [ 'LEFT JOIN',
69 [ 'page_title = cl_to',
70 'page_namespace' => NS_CATEGORY ] ] ]
71 ];
72 }
73
74 public function preprocessResults( $db, $res ) {
75 parent::preprocessResults( $db, $res );
76
77 $this->currentCategoryCounts = [];
78
79 if ( !$res->numRows() || !$this->isCached() ) {
80 return;
81 }
82
83 // Fetch (hopefully) up-to-date numbers of pages in each category.
84 // This should be fast enough as we limit the list to a reasonable length.
85
86 $allCategories = [];
87 foreach ( $res as $row ) {
88 $allCategories[] = $row->title;
89 }
90
91 $categoryRes = $db->select(
92 'category',
93 [ 'cat_title', 'cat_pages' ],
94 [ 'cat_title' => $allCategories ],
95 __METHOD__
96 );
97 foreach ( $categoryRes as $row ) {
98 $this->currentCategoryCounts[$row->cat_title] = intval( $row->cat_pages );
99 }
100
101 // Back to start for display
102 $res->seek( 0 );
103 }
104
110 public function formatResult( $skin, $result ) {
111 $nt = Title::makeTitle( $result->namespace, $result->title );
112
113 $text = new HtmlArmor( $this->languageConverter->convertHtml( $nt->getText() ) );
114
115 if ( !$this->isCached() ) {
116 // We can assume the freshest data
117 $plink = $this->getLinkRenderer()->makeBrokenLink(
118 $nt,
119 $text
120 );
121 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
122 } else {
123 $plink = $this->getLinkRenderer()->makeLink( $nt, $text );
124
125 $currentValue = $this->currentCategoryCounts[$result->title] ?? 0;
126 $cachedValue = intval( $result->value ); // T76910
127
128 // If the category has been created or emptied since the list was refreshed, strike it
129 if ( $nt->isKnown() || $currentValue === 0 ) {
130 $plink = "<del>$plink</del>";
131 }
132
133 // Show the current number of category entries if it changed
134 if ( $currentValue !== $cachedValue ) {
135 $nlinks = $this->msg( 'nmemberschanged' )
136 ->numParams( $cachedValue, $currentValue )->escaped();
137 } else {
138 $nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped();
139 }
140 }
141
142 return $this->getLanguage()->specialList( $plink, $nlinks );
143 }
144
145 protected function getGroupName() {
146 return 'maintenance';
147 }
148}
const NS_CATEGORY
Definition Defines.php:78
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
An interface for creating language converters.
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
Represents a title within MediaWiki.
Definition Title.php:82
setDBLoadBalancer(ILoadBalancer $loadBalancer)
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
getContentLanguage()
Shortcut to get content 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(ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory, LanguageConverterFactory $languageConverterFactory)
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.
The shared interface for all language converters.
This class is a delegate to ILBFactory for a given database cluster.