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