4 * A special page to show pages ordered by the number of pages linking to them
6 * @addtogroup SpecialPage
8 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 * @author Rob Church <robchur@gmail.com>
10 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
11 * @copyright © 2006 Rob Church
12 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
16 * @addtogroup SpecialPage
18 class MostlinkedPage
extends QueryPage
{
20 function getName() { return 'Mostlinked'; }
21 function isExpensive() { return true; }
22 function isSyndicated() { return false; }
25 * Note: Getting page_namespace only works if $this->isCached() is false
28 $dbr = wfGetDB( DB_SLAVE
);
29 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
31 "SELECT 'Mostlinked' AS type,
32 pl_namespace AS namespace,
37 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
43 * Pre-fill the link cache
45 function preprocessResults( &$db, &$res ) {
46 if( $db->numRows( $res ) > 0 ) {
47 $linkBatch = new LinkBatch();
48 while( $row = $db->fetchObject( $res ) )
49 $linkBatch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
50 $db->dataSeek( $res, 0 );
51 $linkBatch->execute();
56 * Make a link to "what links here" for the specified title
58 * @param $title Title being queried
59 * @param $skin Skin to use
62 function makeWlhLink( &$title, $caption, &$skin ) {
63 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
64 return $skin->makeKnownLinkObj( $wlh, $caption );
68 * Make links to the page corresponding to the item, and the "what links here" page for it
70 * @param $skin Skin to be used
71 * @param $result Result row
74 function formatResult( $skin, $result ) {
76 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
77 $link = $skin->makeLinkObj( $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 );