* Documentation
[lhc/web/wiklou.git] / includes / SpecialMostlinked.php
1 <?php
2 /**
3 * A special page to show pages ordered by the number of pages linking to them
4 *
5 * @package MediaWiki
6 * @subpackage SpecialPage
7 *
8 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
10 */
11
12 /* */
13 require_once 'QueryPage.php';
14
15 /**
16 * @package MediaWiki
17 * @subpackage SpecialPage
18 */
19 class MostlinkedPage extends QueryPage {
20
21 function getName() { return 'Mostlinked'; }
22 function isExpensive() { return true; }
23 function isSyndicated() { return false; }
24
25 /**
26 * Note: Getting page_namespace only works if $this->isCached() is false
27 */
28 function getSQL() {
29 $dbr =& wfGetDB( DB_SLAVE );
30 extract( $dbr->tableNames( 'pagelinks', 'page' ) );
31 return
32 "SELECT 'Mostlinked' AS type,
33 pl_namespace AS namespace,
34 pl_title AS title,
35 COUNT(*) AS value,
36
37 page_namespace
38 FROM $pagelinks
39 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
40 GROUP BY pl_namespace,pl_title
41 HAVING COUNT(*) > 1";
42 }
43
44 function formatResult( $skin, $result ) {
45 global $wgContLang;
46
47 $nt = Title::makeTitle( $result->namespace, $result->title );
48 $text = $wgContLang->convert( $nt->getPrefixedText() );
49
50 if ( $this->isCached() )
51 $plink = $skin->makeKnownLink( $nt->getPrefixedText(), $text );
52 else {
53 $plink = is_null( $result->page_namespace )
54 ? $skin->makeBrokenLink( $nt->getPrefixedText(), $text )
55 : $skin->makeKnownLink( $nt->getPrefixedText(), $text );
56 }
57
58 $nl = wfMsg( 'nlinks', $result->value );
59 $nlink = $skin->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ), $nl, 'target=' . $nt->getPrefixedURL() );
60
61 return "{$plink} ({$nlink})";
62 }
63 }
64
65 /**
66 * constructor
67 */
68 function wfSpecialMostlinked() {
69 list( $limit, $offset ) = wfCheckLimits();
70
71 $wpp = new MostlinkedPage();
72
73 $wpp->doQuery( $offset, $limit );
74 }
75
76 ?>