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\ResultWrapper
;
31 * A special page to show pages ordered by the number of pages linking to them.
33 * @ingroup SpecialPage
35 class MostlinkedPage
extends QueryPage
{
36 function __construct( $name = 'Mostlinked' ) {
37 parent
::__construct( $name );
40 public function isExpensive() {
44 function isSyndicated() {
48 public function getQueryInfo() {
50 'tables' => [ 'pagelinks', 'page' ],
52 'namespace' => 'pl_namespace',
53 'title' => 'pl_title',
54 'value' => 'COUNT(*)',
58 'HAVING' => 'COUNT(*) > 1',
60 'pl_namespace', 'pl_title',
68 'page_namespace = pl_namespace',
69 'page_title = pl_title'
77 * Pre-fill the link cache
79 * @param IDatabase $db
80 * @param ResultWrapper $res
82 function preprocessResults( $db, $res ) {
83 $this->executeLBFromResultWrapper( $res );
87 * Make a link to "what links here" for the specified title
89 * @param Title $title Title being queried
90 * @param string $caption Text to display on the link
93 function makeWlhLink( $title, $caption ) {
94 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
96 $linkRenderer = $this->getLinkRenderer();
97 return $linkRenderer->makeKnownLink( $wlh, $caption );
101 * Make links to the page corresponding to the item,
102 * and the "what links here" page for it
104 * @param Skin $skin Skin to be used
105 * @param object $result Result row
108 function formatResult( $skin, $result ) {
109 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
111 return Html
::element(
113 [ 'class' => 'mw-invalidtitle' ],
114 Linker
::getInvalidTitleDescription(
121 $linkRenderer = $this->getLinkRenderer();
122 $link = $linkRenderer->makeLink( $title );
123 $wlh = $this->makeWlhLink(
125 $this->msg( 'nlinks' )->numParams( $result->value
)->text()
128 return $this->getLanguage()->specialList( $link, $wlh );
131 protected function getGroupName() {