4 * A special page to show pages ordered by the number of pages linking to them.
5 * Implements Special:Mostlinked
7 * @addtogroup SpecialPage
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @author Rob Church <robchur@gmail.com>
11 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
12 * @copyright © 2006 Rob Church
13 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
15 class MostlinkedPage
extends QueryPage
{
17 function getName() { return 'Mostlinked'; }
18 function isExpensive() { return true; }
19 function isSyndicated() { return false; }
22 * Note: Getting page_namespace only works if $this->isCached() is false
25 $dbr = wfGetDB( DB_SLAVE
);
26 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
28 "SELECT 'Mostlinked' AS type,
29 pl_namespace AS namespace,
34 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_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->addObj( Title
::makeTitleSafe( $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->makeKnownLinkObj( $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
);
74 $link = $skin->makeLinkObj( $title );
75 $wlh = $this->makeWlhLink( $title,
76 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
77 $wgLang->formatNum( $result->value
) ), $skin );
78 return wfSpecialList( $link, $wlh );
85 function wfSpecialMostlinked() {
86 list( $limit, $offset ) = wfCheckLimits();
88 $wpp = new MostlinkedPage();
90 $wpp->doQuery( $offset, $limit );