4 * A special page to show pages ordered by the number of pages linking to them
7 * @subpackage 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
18 * @subpackage SpecialPage
20 class MostlinkedPage
extends QueryPage
{
22 function getName() { return 'Mostlinked'; }
23 function isExpensive() { return true; }
24 function isSyndicated() { return false; }
27 * Note: Getting page_namespace only works if $this->isCached() is false
30 $dbr =& wfGetDB( DB_SLAVE
);
31 extract( $dbr->tableNames( 'pagelinks', 'page' ) );
33 "SELECT 'Mostlinked' AS type,
34 pl_namespace AS namespace,
39 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
45 * Pre-fill the link cache
47 function preprocessResults( &$dbr, $res ) {
48 if( $dbr->numRows( $res ) > 0 ) {
49 $linkBatch = new LinkBatch();
50 while( $row = $dbr->fetchObject( $res ) )
51 $linkBatch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
52 $dbr->dataSeek( $res, 0 );
53 $linkBatch->execute();
58 * Make a link to "what links here" for the specified title
60 * @param $title Title being queried
61 * @param $skin Skin to use
64 function makeWlhLink( &$title, $caption, &$skin ) {
65 $wlh = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
66 return $skin->makeKnownLinkObj( $wlh, $caption, 'target=' . $title->getPrefixedUrl() );
70 * Make links to the page corresponding to the item, and the "what links here" page for it
72 * @param $skin Skin to be used
73 * @param $result Result row
76 function formatResult( $skin, $result ) {
78 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
79 $link = $skin->makeLinkObj( $title );
80 $wlh = $this->makeWlhLink( $title,
81 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
82 $wgLang->formatNum( $result->value
) ), $skin );
83 return wfSpecialList( $link, $wlh );
90 function wfSpecialMostlinked() {
91 list( $limit, $offset ) = wfCheckLimits();
93 $wpp = new MostlinkedPage();
95 $wpp->doQuery( $offset, $limit );