* Truncate summary of page moves in revision comment field to avoid broken multibyte...
[mediawiki.git] / includes / specials / SpecialMostlinked.php
blobf112ae17a8a1b841dd946cf440184e3a96b51e25
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
7 /**
8 * A special page to show pages ordered by the number of pages linking to them.
9 * Implements Special:Mostlinked
11 * @ingroup SpecialPage
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
19 class MostlinkedPage extends QueryPage {
21 function getName() { return 'Mostlinked'; }
22 function isExpensive() { return true; }
23 function isSyndicated() { return false; }
25 function getSQL() {
26 global $wgMiserMode;
28 $dbr = wfGetDB( DB_SLAVE );
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;
40 } else {
41 $cutoff = 1;
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";
56 /**
57 * Pre-fill the link cache
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();
69 /**
70 * Make a link to "what links here" for the specified title
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
77 function makeWlhLink( &$title, $caption, &$skin ) {
78 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
79 return $skin->linkKnown( $wlh, $caption );
82 /**
83 * Make links to the page corresponding to the item, and the "what links here" page for it
85 * @param $skin Skin to be used
86 * @param $result Result row
87 * @return string
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]]" ) . ' -->';
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 );
104 * constructor
106 function wfSpecialMostlinked() {
107 list( $limit, $offset ) = wfCheckLimits();
109 $wpp = new MostlinkedPage();
111 $wpp->doQuery( $offset, $limit );