* A querypage to show the most linked to categories
[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 require_once 'QueryPage.php';
15
16 /**
17 * @package MediaWiki
18 * @subpackage SpecialPage
19 */
20 class MostlinkedCategoriesPage extends QueryPage {
21
22 function getName() { return 'Mostlinkedcategories'; }
23 function isExpensive() { return true; }
24 function isSyndicated() { return false; }
25
26 function getSQL() {
27 $dbr =& wfGetDB( DB_SLAVE );
28 extract( $dbr->tableNames( 'categorylinks', 'page' ) );
29 $name = $dbr->addQuotes( $this->getName() );
30 return
31 "
32 SELECT
33 $name as type,
34 " . NS_CATEGORY . " as namespace,
35 cl_to as title,
36 COUNT(*) as value
37 FROM $categorylinks
38 GROUP BY cl_to
39 ";
40 }
41
42 function sortDescending() { return true; }
43
44 /**
45 * Fetch user page links and cache their existence
46 */
47 function preprocessResults( &$db, &$res ) {
48 global $wgLinkCache;
49
50 $batch = new LinkBatch;
51 while ( $row = $db->fetchObject( $res ) )
52 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->title ) );
53 $batch->execute( $wgLinkCache );
54
55 // Back to start for display
56 if ( $db->numRows( $res ) > 0 )
57 // If there are no rows we get an error seeking.
58 $db->dataSeek( $res, 0 );
59 }
60
61 function formatResult( $skin, $result ) {
62 global $wgContLang;
63
64 $nt = Title::makeTitle( $result->namespace, $result->title );
65 $text = $wgContLang->convert( $nt->getText() );
66
67 $plink = $skin->makeLinkObj( $nt, htmlspecialchars( $text ) );
68
69 $nlinks = wfMsg( 'ncategories', $result->value );
70 return "$plink ($nlinks)";
71 }
72 }
73
74 /**
75 * constructor
76 */
77 function wfSpecialMostlinkedCategories() {
78 list( $limit, $offset ) = wfCheckLimits();
79
80 $wpp = new MostlinkedCategoriesPage();
81
82 $wpp->doQuery( $offset, $limit );
83 }
84
85 ?>