Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialMostInterwikis
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 7
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 isExpensive
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isSyndicated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
2
 preprocessResults
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 formatResult
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
12
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Implements Special:Mostinterwikis
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24namespace MediaWiki\Specials;
25
26use MediaWiki\Cache\LinkBatchFactory;
27use MediaWiki\Html\Html;
28use MediaWiki\Linker\Linker;
29use MediaWiki\SpecialPage\QueryPage;
30use MediaWiki\Title\NamespaceInfo;
31use MediaWiki\Title\Title;
32use Skin;
33use stdClass;
34use Wikimedia\Rdbms\IConnectionProvider;
35use Wikimedia\Rdbms\IDatabase;
36use Wikimedia\Rdbms\IResultWrapper;
37
38/**
39 * A special page that listed pages that have highest interwiki count
40 *
41 * @ingroup SpecialPage
42 */
43class SpecialMostInterwikis extends QueryPage {
44
45    private NamespaceInfo $namespaceInfo;
46
47    /**
48     * @param NamespaceInfo $namespaceInfo
49     * @param IConnectionProvider $dbProvider
50     * @param LinkBatchFactory $linkBatchFactory
51     */
52    public function __construct(
53        NamespaceInfo $namespaceInfo,
54        IConnectionProvider $dbProvider,
55        LinkBatchFactory $linkBatchFactory
56    ) {
57        parent::__construct( 'Mostinterwikis' );
58        $this->namespaceInfo = $namespaceInfo;
59        $this->setDatabaseProvider( $dbProvider );
60        $this->setLinkBatchFactory( $linkBatchFactory );
61    }
62
63    public function isExpensive() {
64        return true;
65    }
66
67    public function isSyndicated() {
68        return false;
69    }
70
71    public function getQueryInfo() {
72        return [
73            'tables' => [
74                'langlinks',
75                'page'
76            ], 'fields' => [
77                'namespace' => 'page_namespace',
78                'title' => 'page_title',
79                'value' => 'COUNT(*)'
80            ], 'conds' => [
81                'page_namespace' => $this->namespaceInfo->getContentNamespaces()
82            ], 'options' => [
83                'HAVING' => 'COUNT(*) > 1',
84                'GROUP BY' => [
85                    'page_namespace',
86                    'page_title'
87                ]
88            ], 'join_conds' => [
89                'page' => [
90                    'LEFT JOIN',
91                    'page_id = ll_from'
92                ]
93            ]
94        ];
95    }
96
97    /**
98     * Pre-fill the link cache
99     *
100     * @param IDatabase $db
101     * @param IResultWrapper $res
102     */
103    public function preprocessResults( $db, $res ) {
104        $this->executeLBFromResultWrapper( $res );
105    }
106
107    /**
108     * @param Skin $skin
109     * @param stdClass $result
110     * @return string
111     */
112    public function formatResult( $skin, $result ) {
113        $title = Title::makeTitleSafe( $result->namespace, $result->title );
114        if ( !$title ) {
115            return Html::element(
116                'span',
117                [ 'class' => 'mw-invalidtitle' ],
118                Linker::getInvalidTitleDescription(
119                    $this->getContext(),
120                    $result->namespace,
121                    $result->title
122                )
123            );
124        }
125
126        $linkRenderer = $this->getLinkRenderer();
127        if ( $this->isCached() ) {
128            $link = $linkRenderer->makeLink( $title );
129        } else {
130            $link = $linkRenderer->makeKnownLink( $title );
131        }
132
133        $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
134
135        return $this->getLanguage()->specialList( $link, $count );
136    }
137
138    protected function getGroupName() {
139        return 'highuse';
140    }
141}
142
143/**
144 * Retain the old class name for backwards compatibility.
145 * @deprecated since 1.41
146 */
147class_alias( SpecialMostInterwikis::class, 'SpecialMostInterwikis' );