Merge "Document parser cache key control."
[lhc/web/wiklou.git] / includes / specials / SpecialWantedcategories.php
1 <?php
2 /**
3 * Implements Special:Wantedcategories
4 *
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 /**
27 * A querypage to list the most wanted categories - implements Special:Wantedcategories
28 *
29 * @ingroup SpecialPage
30 */
31 class WantedCategoriesPage extends WantedQueryPage {
32 private $currentCategoryCounts;
33
34 function __construct( $name = 'Wantedcategories' ) {
35 parent::__construct( $name );
36 }
37
38 function getQueryInfo() {
39 return array(
40 'tables' => array( 'categorylinks', 'page' ),
41 'fields' => array( 'namespace' => NS_CATEGORY,
42 'title' => 'cl_to',
43 'value' => 'COUNT(*)' ),
44 'conds' => array( 'page_title IS NULL' ),
45 'options' => array( 'GROUP BY' => 'cl_to' ),
46 'join_conds' => array( 'page' => array( 'LEFT JOIN',
47 array( 'page_title = cl_to',
48 'page_namespace' => NS_CATEGORY ) ) )
49 );
50 }
51
52 function preprocessResults( $db, $res ) {
53 parent::preprocessResults( $db, $res );
54
55 $this->currentCategoryCounts = array();
56
57 if ( !$res->numRows() || !$this->isCached() ) {
58 return;
59 }
60
61 // Fetch (hopefully) up-to-date numbers of pages in each category.
62 // This should be fast enough as we limit the list to a reasonable length.
63
64 $allCategories = array();
65 foreach ( $res as $row ) {
66 $allCategories[] = $row->title;
67 }
68
69 $categoryRes = $db->select(
70 'category',
71 array( 'cat_title', 'cat_pages' ),
72 array( 'cat_title' => $allCategories ),
73 __METHOD__
74 );
75 foreach ( $categoryRes as $row ) {
76 $this->currentCategoryCounts[ $row->cat_title ] = intval( $row->cat_pages );
77 }
78
79 // Back to start for display
80 $res->seek( 0 );
81 }
82
83 /**
84 * @param Skin $skin
85 * @param object $result Result row
86 * @return string
87 */
88 function formatResult( $skin, $result ) {
89 global $wgContLang;
90
91 $nt = Title::makeTitle( $result->namespace, $result->title );
92 $text = htmlspecialchars( $wgContLang->convert( $nt->getText() ) );
93
94 if ( !$this->isCached() ) {
95 // We can assume the freshest data
96 $plink = Linker::link(
97 $nt,
98 $text,
99 array(),
100 array(),
101 array( 'broken' )
102 );
103 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
104 } else {
105 $plink = Linker::link( $nt, $text );
106
107 $currentValue = isset( $this->currentCategoryCounts[ $result->title ] )
108 ? $this->currentCategoryCounts[ $result->title ]
109 : 0;
110
111 // If the category has been created or emptied since the list was refreshed, strike it
112 if ( $nt->isKnown() || $currentValue === 0 ) {
113 $plink = "<del>$plink</del>";
114 }
115
116 // Show the current number of category entries if it changed
117 if ( $currentValue !== $result->value ) {
118 $nlinks = $this->msg( 'nmemberschanged' )
119 ->numParams( $result->value, $currentValue )->escaped();
120 } else {
121 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
122 }
123 }
124
125 return $this->getLanguage()->specialList( $plink, $nlinks );
126 }
127
128 protected function getGroupName() {
129 return 'maintenance';
130 }
131 }