]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialMostlinked.php
MediaWiki 1.15.4-scripts
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialMostlinked.php
1 <?php
2 /**
3  * @file
4  * @ingroup SpecialPage
5  */
6
7 /**
8  * A special page to show pages ordered by the number of pages linking to them.
9  * Implements Special:Mostlinked
10  *
11  * @ingroup SpecialPage
12  *
13  * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
14  * @author Rob Church <robchur@gmail.com>
15  * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
16  * @copyright © 2006 Rob Church
17  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
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                 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
31                 return
32                         "SELECT 'Mostlinked' AS type,
33                                 pl_namespace AS namespace,
34                                 pl_title AS title,
35                                 COUNT(*) AS value,
36                                 page_namespace
37                         FROM $pagelinks
38                         LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
39                         GROUP BY pl_namespace, pl_title, page_namespace
40                         HAVING COUNT(*) > 1";
41         }
42
43         /**
44          * Pre-fill the link cache
45          */
46         function preprocessResults( $db, $res ) {
47                 if( $db->numRows( $res ) > 0 ) {
48                         $linkBatch = new LinkBatch();
49                         while( $row = $db->fetchObject( $res ) )
50                                 $linkBatch->add( $row->namespace, $row->title );
51                         $db->dataSeek( $res, 0 );
52                         $linkBatch->execute();
53                 }
54         }
55
56         /**
57          * Make a link to "what links here" for the specified title
58          *
59          * @param $title Title being queried
60          * @param $skin Skin to use
61          * @return string
62          */
63         function makeWlhLink( &$title, $caption, &$skin ) {
64                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
65                 return $skin->makeKnownLinkObj( $wlh, $caption );
66         }
67
68         /**
69          * Make links to the page corresponding to the item, and the "what links here" page for it
70          *
71          * @param $skin Skin to be used
72          * @param $result Result row
73          * @return string
74          */
75         function formatResult( $skin, $result ) {
76                 global $wgLang;
77                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
78                 $link = $skin->makeLinkObj( $title );
79                 $wlh = $this->makeWlhLink( $title,
80                         wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
81                                 $wgLang->formatNum( $result->value ) ), $skin );
82                 return wfSpecialList( $link, $wlh );
83         }
84 }
85
86 /**
87  * constructor
88  */
89 function wfSpecialMostlinked() {
90         list( $limit, $offset ) = wfCheckLimits();
91
92         $wpp = new MostlinkedPage();
93
94         $wpp->doQuery( $offset, $limit );
95 }