]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialMostlinked.php
MediaWiki 1.16.1-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         function getSQL() {
26                 global $wgMiserMode;
27
28                 $dbr = wfGetDB( DB_SLAVE );
29
30                 # In miser mode, reduce the query cost by adding a threshold for large wikis
31                 if ( $wgMiserMode ) {
32                         $numPages = SiteStats::pages();
33                         if ( $numPages > 10000 ) {
34                                 $cutoff = 100;
35                         } elseif ( $numPages > 100 ) {
36                                 $cutoff = intval( sqrt( $numPages ) );
37                         } else {
38                                 $cutoff = 1;
39                         }
40                 } else {
41                         $cutoff = 1;
42                 }
43
44                 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
45                 return
46                         "SELECT 'Mostlinked' AS type,
47                                 pl_namespace AS namespace,
48                                 pl_title AS title,
49                                 COUNT(*) AS value
50                         FROM $pagelinks
51                         LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
52                         GROUP BY pl_namespace, pl_title
53                         HAVING COUNT(*) > $cutoff";
54         }
55
56         /**
57          * Pre-fill the link cache
58          */
59         function preprocessResults( $db, $res ) {
60                 if( $db->numRows( $res ) > 0 ) {
61                         $linkBatch = new LinkBatch();
62                         while( $row = $db->fetchObject( $res ) )
63                                 $linkBatch->add( $row->namespace, $row->title );
64                         $db->dataSeek( $res, 0 );
65                         $linkBatch->execute();
66                 }
67         }
68
69         /**
70          * Make a link to "what links here" for the specified title
71          *
72          * @param $title Title being queried
73          * @param $caption String: text to display on the link
74          * @param $skin Skin to use
75          * @return String
76          */
77         function makeWlhLink( &$title, $caption, &$skin ) {
78                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
79                 return $skin->linkKnown( $wlh, $caption );
80         }
81
82         /**
83          * Make links to the page corresponding to the item, and the "what links here" page for it
84          *
85          * @param $skin Skin to be used
86          * @param $result Result row
87          * @return string
88          */
89         function formatResult( $skin, $result ) {
90                 global $wgLang;
91                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
92                 if ( !$title ) {
93                         return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
94                 }
95                 $link = $skin->link( $title );
96                 $wlh = $this->makeWlhLink( $title,
97                         wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
98                                 $wgLang->formatNum( $result->value ) ), $skin );
99                 return wfSpecialList( $link, $wlh );
100         }
101 }
102
103 /**
104  * constructor
105  */
106 function wfSpecialMostlinked() {
107         list( $limit, $offset ) = wfCheckLimits();
108
109         $wpp = new MostlinkedPage();
110
111         $wpp->doQuery( $offset, $limit );
112 }