Revert r35848 per Brion's WONTFIX of bug 14536: "This would just mean that there...
[lhc/web/wiklou.git] / includes / SpecialWantedcategories.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 * A querypage to list the most wanted categories - implements Special:Wantedcategories
9 *
10 * @ingroup SpecialPage
11 *
12 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
13 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
14 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
15 */
16 class WantedCategoriesPage extends QueryPage {
17
18 function getName() {
19 return 'Wantedcategories';
20 }
21
22 function isExpensive() {
23 return true;
24 }
25
26 function isSyndicated() {
27 return false;
28 }
29
30 function getSQL() {
31 $dbr = wfGetDB( DB_SLAVE );
32 list( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
33 $name = $dbr->addQuotes( $this->getName() );
34 return
35 "
36 SELECT
37 $name as type,
38 " . NS_CATEGORY . " as namespace,
39 cl_to as title,
40 COUNT(*) as value
41 FROM $categorylinks
42 LEFT JOIN $page ON cl_to = page_title AND page_namespace = ". NS_CATEGORY ."
43 WHERE page_title IS NULL
44 GROUP BY 1,2,3
45 ";
46 }
47
48 function sortDescending() { return true; }
49
50 /**
51 * Fetch user page links and cache their existence
52 */
53 function preprocessResults( $db, $res ) {
54 $batch = new LinkBatch;
55 while ( $row = $db->fetchObject( $res ) )
56 $batch->add( $row->namespace, $row->title );
57 $batch->execute();
58
59 // Back to start for display
60 if ( $db->numRows( $res ) > 0 )
61 // If there are no rows we get an error seeking.
62 $db->dataSeek( $res, 0 );
63 }
64
65 function formatResult( $skin, $result ) {
66 global $wgLang, $wgContLang;
67
68 $nt = Title::makeTitle( $result->namespace, $result->title );
69 $text = $wgContLang->convert( $nt->getText() );
70
71 $plink = $this->isCached() ?
72 $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
73 $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
74
75 $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
76 $wgLang->formatNum( $result->value ) );
77 return wfSpecialList($plink, $nlinks);
78 }
79 }
80
81 /**
82 * constructor
83 */
84 function wfSpecialWantedCategories() {
85 list( $limit, $offset ) = wfCheckLimits();
86
87 $wpp = new WantedCategoriesPage();
88
89 $wpp->doQuery( $offset, $limit );
90 }