MediaWiki REL1_35
SpecialWantedCategories.php
Go to the documentation of this file.
1<?php
33
34 public function __construct( $name = 'Wantedcategories' ) {
35 parent::__construct( $name );
36 }
37
38 public function getQueryInfo() {
39 return [
40 'tables' => [ 'categorylinks', 'page' ],
41 'fields' => [
42 'namespace' => NS_CATEGORY,
43 'title' => 'cl_to',
44 'value' => 'COUNT(*)'
45 ],
46 'conds' => [ 'page_title IS NULL' ],
47 'options' => [ 'GROUP BY' => 'cl_to' ],
48 'join_conds' => [ 'page' => [ 'LEFT JOIN',
49 [ 'page_title = cl_to',
50 'page_namespace' => NS_CATEGORY ] ] ]
51 ];
52 }
53
54 public function preprocessResults( $db, $res ) {
55 parent::preprocessResults( $db, $res );
56
57 $this->currentCategoryCounts = [];
58
59 if ( !$res->numRows() || !$this->isCached() ) {
60 return;
61 }
62
63 // Fetch (hopefully) up-to-date numbers of pages in each category.
64 // This should be fast enough as we limit the list to a reasonable length.
65
66 $allCategories = [];
67 foreach ( $res as $row ) {
68 $allCategories[] = $row->title;
69 }
70
71 $categoryRes = $db->select(
72 'category',
73 [ 'cat_title', 'cat_pages' ],
74 [ 'cat_title' => $allCategories ],
75 __METHOD__
76 );
77 foreach ( $categoryRes as $row ) {
78 $this->currentCategoryCounts[$row->cat_title] = intval( $row->cat_pages );
79 }
80
81 // Back to start for display
82 $res->seek( 0 );
83 }
84
90 public function formatResult( $skin, $result ) {
91 $nt = Title::makeTitle( $result->namespace, $result->title );
92
93 $text = new HtmlArmor( $this->getLanguageConverter()->convertHtml( $nt->getText() ) );
94
95 if ( !$this->isCached() ) {
96 // We can assume the freshest data
97 $plink = $this->getLinkRenderer()->makeBrokenLink(
98 $nt,
99 $text
100 );
101 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
102 } else {
103 $plink = $this->getLinkRenderer()->makeLink( $nt, $text );
104
105 $currentValue = $this->currentCategoryCounts[$result->title] ?? 0;
106 $cachedValue = intval( $result->value ); // T76910
107
108 // If the category has been created or emptied since the list was refreshed, strike it
109 if ( $nt->isKnown() || $currentValue === 0 ) {
110 $plink = "<del>$plink</del>";
111 }
112
113 // Show the current number of category entries if it changed
114 if ( $currentValue !== $cachedValue ) {
115 $nlinks = $this->msg( 'nmemberschanged' )
116 ->numParams( $cachedValue, $currentValue )->escaped();
117 } else {
118 $nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped();
119 }
120 }
121
122 return $this->getLanguage()->specialList( $plink, $nlinks );
123 }
124
125 protected function getGroupName() {
126 return 'maintenance';
127 }
128}
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
getLanguageConverter()
Shortcut to get language's converter.
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 Stable to override.
__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 Stable to extend.
const NS_CATEGORY
Definition Defines.php:84