* plural support for nlinks
[lhc/web/wiklou.git] / includes / SpecialMostlinked.php
1 <?php
2
3 /**
4 * A special page to show pages ordered by the number of pages linking to them
5 *
6 * @package MediaWiki
7 * @subpackage SpecialPage
8 *
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @author Rob Church <robchur@gmail.com>
11 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
12 * @copyright © 2006 Rob Church
13 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
14 */
15
16 /* */
17 require_once 'QueryPage.php';
18
19 /**
20 * @package MediaWiki
21 * @subpackage SpecialPage
22 */
23 class MostlinkedPage extends QueryPage {
24
25 function getName() { return 'Mostlinked'; }
26 function isExpensive() { return true; }
27 function isSyndicated() { return false; }
28
29 /**
30 * Note: Getting page_namespace only works if $this->isCached() is false
31 */
32 function getSQL() {
33 $dbr =& wfGetDB( DB_SLAVE );
34 extract( $dbr->tableNames( 'pagelinks', 'page' ) );
35 return
36 "SELECT 'Mostlinked' AS type,
37 pl_namespace AS namespace,
38 pl_title AS title,
39 COUNT(*) AS value,
40 page_namespace
41 FROM $pagelinks
42 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
43 GROUP BY pl_namespace,pl_title
44 HAVING COUNT(*) > 1";
45 }
46
47 /**
48 * Pre-fill the link cache
49 */
50 function preprocessResults( &$dbr, $res ) {
51 if( $dbr->numRows( $res ) > 0 ) {
52 $linkBatch = new LinkBatch();
53 while( $row = $dbr->fetchObject( $res ) )
54 $linkBatch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
55 $dbr->dataSeek( $res, 0 );
56 $linkBatch->execute();
57 }
58 }
59
60 /**
61 * Make a link to "what links here" for the specified title
62 *
63 * @param $title Title being queried
64 * @param $skin Skin to use
65 * @return string
66 */
67 function makeWlhLink( &$title, $caption, &$skin ) {
68 $wlh = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
69 return $skin->makeKnownLinkObj( $wlh, $caption, 'target=' . $title->getPrefixedUrl() );
70 }
71
72 /**
73 * Make links to the page corresponding to the item, and the "what links here" page for it
74 *
75 * @param $skin Skin to be used
76 * @param $result Result row
77 * @return string
78 */
79 function formatResult( $skin, $result ) {
80 global $wgLang;
81 $title = Title::makeTitleSafe( $result->namespace, $result->title );
82 $link = $skin->makeLinkObj( $title );
83 $wlh = $this->makeWlhLink( $title,
84 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
85 $wgLang->formatNum( $result->value ) ), $skin );
86 return wfSpecialList( $link, $wlh );
87 }
88 }
89
90 /**
91 * constructor
92 */
93 function wfSpecialMostlinked() {
94 list( $limit, $offset ) = wfCheckLimits();
95
96 $wpp = new MostlinkedPage();
97
98 $wpp->doQuery( $offset, $limit );
99 }
100
101 ?>