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