Correct the address of the FSF in some of the GPL headers
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinkedcategories.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * @file
22 * @ingroup SpecialPage
23 */
24
25 /**
26 * A querypage to show categories ordered in descending order by the pages in them
27 *
28 * @ingroup SpecialPage
29 *
30 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
31 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
32 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
33 */
34 class MostlinkedCategoriesPage extends QueryPage {
35
36 function getName() { return 'Mostlinkedcategories'; }
37 function isExpensive() { return true; }
38 function isSyndicated() { return false; }
39
40 function getSQL() {
41 $dbr = wfGetDB( DB_SLAVE );
42 $categorylinks = $dbr->tableName( 'categorylinks' );
43 $name = $dbr->addQuotes( $this->getName() );
44 return
45 "
46 SELECT
47 $name as type,
48 " . NS_CATEGORY . " as namespace,
49 cl_to as title,
50 COUNT(*) as value
51 FROM $categorylinks
52 GROUP BY cl_to
53 ";
54 }
55
56 function sortDescending() { return true; }
57
58 /**
59 * Fetch user page links and cache their existence
60 */
61 function preprocessResults( $db, $res ) {
62 $batch = new LinkBatch;
63 while ( $row = $db->fetchObject( $res ) )
64 $batch->add( $row->namespace, $row->title );
65 $batch->execute();
66
67 // Back to start for display
68 if ( $db->numRows( $res ) > 0 )
69 // If there are no rows we get an error seeking.
70 $db->dataSeek( $res, 0 );
71 }
72
73 function formatResult( $skin, $result ) {
74 global $wgLang, $wgContLang;
75
76 $nt = Title::makeTitle( $result->namespace, $result->title );
77 $text = $wgContLang->convert( $nt->getText() );
78
79 $plink = $skin->link( $nt, htmlspecialchars( $text ) );
80
81 $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
82 $wgLang->formatNum( $result->value ) );
83 return wfSpecialList($plink, $nlinks);
84 }
85 }
86
87 /**
88 * constructor
89 */
90 function wfSpecialMostlinkedCategories() {
91 list( $limit, $offset ) = wfCheckLimits();
92
93 $wpp = new MostlinkedCategoriesPage();
94
95 $wpp->doQuery( $offset, $limit );
96 }