3 * Implements Special:Mostlinked
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup SpecialPage
24 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
25 * @author Rob Church <robchur@gmail.com>
29 * A special page to show pages ordered by the number of pages linking to them.
31 * @ingroup SpecialPage
33 class MostlinkedPage
extends QueryPage
{
35 function __construct( $name = 'Mostlinked' ) {
36 parent
::__construct( $name );
39 function isExpensive() { return true; }
40 function isSyndicated() { return false; }
42 function getQueryInfo() {
44 'tables' => array ( 'pagelinks', 'page' ),
45 'fields' => array ( 'pl_namespace AS namespace',
49 'options' => array ( 'HAVING' => 'COUNT(*) > 1',
50 'GROUP BY' => array( 'pl_namespace', 'pl_title',
52 'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
53 array ( 'page_namespace = pl_namespace',
54 'page_title = pl_title' ) ) )
59 * Pre-fill the link cache
61 * @param $db DatabaseBase
64 function preprocessResults( $db, $res ) {
65 if ( $res->numRows() > 0 ) {
66 $linkBatch = new LinkBatch();
67 foreach ( $res as $row ) {
68 $linkBatch->add( $row->namespace, $row->title
);
71 $linkBatch->execute();
76 * Make a link to "what links here" for the specified title
78 * @param $title Title being queried
79 * @param $caption String: text to display on the link
82 function makeWlhLink( $title, $caption ) {
83 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
84 return Linker
::linkKnown( $wlh, $caption );
88 * Make links to the page corresponding to the item, and the "what links here" page for it
90 * @param $skin Skin to be used
91 * @param $result Result row
94 function formatResult( $skin, $result ) {
95 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
97 return Html
::element( 'span', array( 'class' => 'mw-invalidtitle' ),
98 Linker
::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title
) );
100 $link = Linker
::link( $title );
101 $wlh = $this->makeWlhLink( $title,
102 $this->msg( 'nlinks' )->numParams( $result->value
)->escaped() );
103 return $this->getLanguage()->specialList( $link, $wlh );