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; }
26 $dbr = wfGetDB( DB_SLAVE
);
27 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
29 "SELECT 'Mostlinked' AS type,
30 pl_namespace AS namespace,
34 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
35 GROUP BY pl_namespace, pl_title
40 * Pre-fill the link cache
42 function preprocessResults( $db, $res ) {
43 if( $db->numRows( $res ) > 0 ) {
44 $linkBatch = new LinkBatch();
45 while( $row = $db->fetchObject( $res ) )
46 $linkBatch->add( $row->namespace, $row->title
);
47 $db->dataSeek( $res, 0 );
48 $linkBatch->execute();
53 * Make a link to "what links here" for the specified title
55 * @param $title Title being queried
56 * @param $skin Skin to use
59 function makeWlhLink( &$title, $caption, &$skin ) {
60 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
61 return $skin->linkKnown( $wlh, $caption );
65 * Make links to the page corresponding to the item, and the "what links here" page for it
67 * @param $skin Skin to be used
68 * @param $result Result row
71 function formatResult( $skin, $result ) {
73 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
75 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
77 $link = $skin->link( $title );
78 $wlh = $this->makeWlhLink( $title,
79 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
80 $wgLang->formatNum( $result->value
) ), $skin );
81 return wfSpecialList( $link, $wlh );
88 function wfSpecialMostlinked() {
89 list( $limit, $offset ) = wfCheckLimits();
91 $wpp = new MostlinkedPage();
93 $wpp->doQuery( $offset, $limit );