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
17 require_once 'QueryPage.php';
21 * @subpackage SpecialPage
23 class MostlinkedPage
extends QueryPage
{
25 function getName() { return 'Mostlinked'; }
26 function isExpensive() { return true; }
27 function isSyndicated() { return false; }
30 * Note: Getting page_namespace only works if $this->isCached() is false
33 $dbr =& wfGetDB( DB_SLAVE
);
34 extract( $dbr->tableNames( 'pagelinks', 'page' ) );
36 "SELECT 'Mostlinked' AS type,
37 pl_namespace AS namespace,
42 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
43 GROUP BY pl_namespace,pl_title
48 * Pre-fill the link cache
50 function preprocessResults( &$dbr, $res ) {
51 if( $dbr->numRows( $res ) > 0 ) {
52 $linkBatch = new LinkBatch();
53 while( $row = $dbr->fetchObject( $res ) )
54 $linkBatch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
55 $dbr->dataSeek( $res, 0 );
56 $linkBatch->execute();
61 * Make a link to "what links here" for the specified title
63 * @param $title Title being queried
64 * @param $skin Skin to use
67 function makeWlhLink( &$title, $caption, &$skin ) {
68 $wlh = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
69 return $skin->makeKnownLinkObj( $wlh, $caption, 'target=' . $title->getPrefixedUrl() );
73 * Make links to the page corresponding to the item, and the "what links here" page for it
75 * @param $skin Skin to be used
76 * @param $result Result row
79 function formatResult( $skin, $result ) {
81 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
82 $link = $skin->makeLinkObj( $title );
83 $wlh = $this->makeWlhLink( $title,
84 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
85 $wgLang->formatNum( $result->value
) ), $skin );
86 return wfSpecialList( $link, $wlh );
93 function wfSpecialMostlinked() {
94 list( $limit, $offset ) = wfCheckLimits();
96 $wpp = new MostlinkedPage();
98 $wpp->doQuery( $offset, $limit );