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; }
28 $dbr = wfGetDB( DB_SLAVE
);
30 # In miser mode, reduce the query cost by adding a threshold for large wikis
32 $numPages = SiteStats
::pages();
33 if ( $numPages > 10000 ) {
35 } elseif ( $numPages > 100 ) {
36 $cutoff = intval( sqrt( $numPages ) );
44 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
46 "SELECT 'Mostlinked' AS type,
47 pl_namespace AS namespace,
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";
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();
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
77 function makeWlhLink( &$title, $caption, &$skin ) {
78 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
79 return $skin->linkKnown( $wlh, $caption );
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
89 function formatResult( $skin, $result ) {
91 $title = Title
::makeTitleSafe( $result->namespace, $result->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 );
106 function wfSpecialMostlinked() {
107 list( $limit, $offset ) = wfCheckLimits();
109 $wpp = new MostlinkedPage();
111 $wpp->doQuery( $offset, $limit );