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>
28 use Wikimedia\Rdbms\IResultWrapper
;
29 use Wikimedia\Rdbms\IDatabase
;
32 * A special page to show pages ordered by the number of pages linking to them.
34 * @ingroup SpecialPage
36 class SpecialMostLinked
extends QueryPage
{
37 function __construct( $name = 'Mostlinked' ) {
38 parent
::__construct( $name );
41 public function isExpensive() {
45 function isSyndicated() {
49 public function getQueryInfo() {
51 'tables' => [ 'pagelinks', 'page' ],
53 'namespace' => 'pl_namespace',
54 'title' => 'pl_title',
55 'value' => 'COUNT(*)',
59 'HAVING' => 'COUNT(*) > 1',
61 'pl_namespace', 'pl_title',
69 'page_namespace = pl_namespace',
70 'page_title = pl_title'
78 * Pre-fill the link cache
80 * @param IDatabase $db
81 * @param IResultWrapper $res
83 function preprocessResults( $db, $res ) {
84 $this->executeLBFromResultWrapper( $res );
88 * Make a link to "what links here" for the specified title
90 * @param Title $title Title being queried
91 * @param string $caption Text to display on the link
94 function makeWlhLink( $title, $caption ) {
95 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
97 $linkRenderer = $this->getLinkRenderer();
98 return $linkRenderer->makeKnownLink( $wlh, $caption );
102 * Make links to the page corresponding to the item,
103 * and the "what links here" page for it
105 * @param Skin $skin Skin to be used
106 * @param object $result Result row
109 function formatResult( $skin, $result ) {
110 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
112 return Html
::element(
114 [ 'class' => 'mw-invalidtitle' ],
115 Linker
::getInvalidTitleDescription(
122 $linkRenderer = $this->getLinkRenderer();
123 $link = $linkRenderer->makeLink( $title );
124 $wlh = $this->makeWlhLink(
126 $this->msg( 'nlinks' )->numParams( $result->value
)->text()
129 return $this->getLanguage()->specialList( $link, $wlh );
132 protected function getGroupName() {