MediaWiki  1.34.0
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 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:792
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
SpecialWantedCategories\$currentCategoryCounts
$currentCategoryCounts
Definition: SpecialWantedCategories.php:34
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:749
$res
$res
Definition: testCompression.php:52
SpecialWantedCategories
A querypage to list the most wanted categories - implements Special:Wantedcategories.
Definition: SpecialWantedCategories.php:33
QueryPage\isCached
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:258
SpecialWantedCategories\formatResult
formatResult( $skin, $result)
Definition: SpecialWantedCategories.php:92
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:74
SpecialWantedCategories\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialWantedCategories.php:40
SpecialWantedCategories\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialWantedCategories.php:127
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
SpecialWantedCategories\__construct
__construct( $name='Wantedcategories')
Definition: SpecialWantedCategories.php:36
WantedQueryPage
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
Definition: WantedQueryPage.php:32
SpecialWantedCategories\preprocessResults
preprocessResults( $db, $res)
Cache page existence for performance.
Definition: SpecialWantedCategories.php:56