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