Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / includes / specials / SpecialMostinterwikis.php
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
24 use Wikimedia\Rdbms\ResultWrapper;
25 use Wikimedia\Rdbms\IDatabase;
26
27 /**
28 * A special page that listed pages that have highest interwiki count
29 *
30 * @ingroup SpecialPage
31 */
32 class MostinterwikisPage extends QueryPage {
33 function __construct( $name = 'Mostinterwikis' ) {
34 parent::__construct( $name );
35 }
36
37 public function isExpensive() {
38 return true;
39 }
40
41 function isSyndicated() {
42 return false;
43 }
44
45 public function getQueryInfo() {
46 return [
47 'tables' => [
48 'langlinks',
49 'page'
50 ], 'fields' => [
51 'namespace' => 'page_namespace',
52 'title' => 'page_title',
53 'value' => 'COUNT(*)'
54 ], 'conds' => [
55 'page_namespace' => MWNamespace::getContentNamespaces()
56 ], 'options' => [
57 'HAVING' => 'COUNT(*) > 1',
58 'GROUP BY' => [
59 'page_namespace',
60 'page_title'
61 ]
62 ], 'join_conds' => [
63 'page' => [
64 'LEFT JOIN',
65 'page_id = ll_from'
66 ]
67 ]
68 ];
69 }
70
71 /**
72 * Pre-fill the link cache
73 *
74 * @param IDatabase $db
75 * @param ResultWrapper $res
76 */
77 function preprocessResults( $db, $res ) {
78 $this->executeLBFromResultWrapper( $res );
79 }
80
81 /**
82 * @param Skin $skin
83 * @param object $result
84 * @return string
85 */
86 function formatResult( $skin, $result ) {
87 $title = Title::makeTitleSafe( $result->namespace, $result->title );
88 if ( !$title ) {
89 return Html::element(
90 'span',
91 [ 'class' => 'mw-invalidtitle' ],
92 Linker::getInvalidTitleDescription(
93 $this->getContext(),
94 $result->namespace,
95 $result->title
96 )
97 );
98 }
99
100 $linkRenderer = $this->getLinkRenderer();
101 if ( $this->isCached() ) {
102 $link = $linkRenderer->makeLink( $title );
103 } else {
104 $link = $linkRenderer->makeKnownLink( $title );
105 }
106
107 $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
108
109 return $this->getLanguage()->specialList( $link, $count );
110 }
111
112 protected function getGroupName() {
113 return 'highuse';
114 }
115 }