]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/SpecialMostlinkedcategories.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / includes / SpecialMostlinkedcategories.php
1 <?php
2 /**
3  * A querypage to show categories ordered in descending order by the pages  in them
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 MostlinkedCategoriesPage extends QueryPage {
12
13         function getName() { return 'Mostlinkedcategories'; }
14         function isExpensive() { return true; }
15         function isSyndicated() { return false; }
16
17         function getSQL() {
18                 $dbr = wfGetDB( DB_SLAVE );
19                 $categorylinks = $dbr->tableName( 'categorylinks' );
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                         GROUP BY 1,2,3
30                         ";
31         }
32
33         function sortDescending() { return true; }
34
35         /**
36          * Fetch user page links and cache their existence
37          */
38         function preprocessResults( &$db, &$res ) {
39                 $batch = new LinkBatch;
40                 while ( $row = $db->fetchObject( $res ) )
41                         $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
42                 $batch->execute();
43
44                 // Back to start for display
45                 if ( $db->numRows( $res ) > 0 )
46                         // If there are no rows we get an error seeking.
47                         $db->dataSeek( $res, 0 );
48         }
49
50         function formatResult( $skin, $result ) {
51                 global $wgLang, $wgContLang;
52
53                 $nt = Title::makeTitle( $result->namespace, $result->title );
54                 $text = $wgContLang->convert( $nt->getText() );
55
56                 $plink = $skin->makeLinkObj( $nt, htmlspecialchars( $text ) );
57
58                 $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
59                         $wgLang->formatNum( $result->value ) );
60                 return wfSpecialList($plink, $nlinks);
61         }
62 }
63
64 /**
65  * constructor
66  */
67 function wfSpecialMostlinkedCategories() {
68         list( $limit, $offset ) = wfCheckLimits();
69
70         $wpp = new MostlinkedCategoriesPage();
71
72         $wpp->doQuery( $offset, $limit );
73 }
74
75