Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialMostLinked | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 | |||
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeWlhLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Mostlinked |
4 | * |
5 | * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church |
6 | * |
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. |
11 | * |
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. |
16 | * |
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 |
21 | * |
22 | * @file |
23 | * @ingroup SpecialPage |
24 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
25 | * @author Rob Church <robchur@gmail.com> |
26 | */ |
27 | |
28 | namespace MediaWiki\Specials; |
29 | |
30 | use MediaWiki\Cache\LinkBatchFactory; |
31 | use MediaWiki\Html\Html; |
32 | use MediaWiki\Linker\Linker; |
33 | use MediaWiki\Linker\LinksMigration; |
34 | use MediaWiki\SpecialPage\QueryPage; |
35 | use MediaWiki\SpecialPage\SpecialPage; |
36 | use MediaWiki\Title\Title; |
37 | use Skin; |
38 | use stdClass; |
39 | use Wikimedia\Rdbms\IConnectionProvider; |
40 | use Wikimedia\Rdbms\IDatabase; |
41 | use Wikimedia\Rdbms\IResultWrapper; |
42 | |
43 | /** |
44 | * A special page to show pages ordered by the number of pages linking to them. |
45 | * |
46 | * @ingroup SpecialPage |
47 | */ |
48 | class SpecialMostLinked extends QueryPage { |
49 | |
50 | private LinksMigration $linksMigration; |
51 | |
52 | /** |
53 | * @param IConnectionProvider $dbProvider |
54 | * @param LinkBatchFactory $linkBatchFactory |
55 | * @param LinksMigration $linksMigration |
56 | */ |
57 | public function __construct( |
58 | IConnectionProvider $dbProvider, |
59 | LinkBatchFactory $linkBatchFactory, |
60 | LinksMigration $linksMigration |
61 | ) { |
62 | parent::__construct( 'Mostlinked' ); |
63 | $this->setDatabaseProvider( $dbProvider ); |
64 | $this->setLinkBatchFactory( $linkBatchFactory ); |
65 | $this->linksMigration = $linksMigration; |
66 | } |
67 | |
68 | public function isExpensive() { |
69 | return true; |
70 | } |
71 | |
72 | public function isSyndicated() { |
73 | return false; |
74 | } |
75 | |
76 | public function getQueryInfo() { |
77 | $tableFields = $this->linksMigration->getTitleFields( 'pagelinks' ); |
78 | $fields = [ |
79 | 'namespace' => $tableFields[0], |
80 | 'title' => $tableFields[1], |
81 | ]; |
82 | $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' ); |
83 | return [ |
84 | 'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ), |
85 | 'fields' => array_merge( [ 'value' => 'COUNT(*)', 'page_namespace' ], $fields ), |
86 | 'options' => [ |
87 | 'HAVING' => 'COUNT(*) > 1', |
88 | 'GROUP BY' => array_merge( $tableFields, [ 'page_namespace' ] ) |
89 | ], |
90 | 'join_conds' => array_merge( $queryInfo['joins'], [ |
91 | 'page' => [ |
92 | 'LEFT JOIN', |
93 | [ |
94 | 'page_namespace = ' . $fields['namespace'], |
95 | 'page_title = ' . $fields['title'] |
96 | ] |
97 | ] ] ) |
98 | ]; |
99 | } |
100 | |
101 | /** |
102 | * Pre-fill the link cache |
103 | * |
104 | * @param IDatabase $db |
105 | * @param IResultWrapper $res |
106 | */ |
107 | public function preprocessResults( $db, $res ) { |
108 | $this->executeLBFromResultWrapper( $res ); |
109 | } |
110 | |
111 | /** |
112 | * Make a link to "what links here" for the specified title |
113 | * |
114 | * @param Title $title Title being queried |
115 | * @param string $caption Text to display on the link |
116 | * @return string |
117 | */ |
118 | private function makeWlhLink( $title, $caption ) { |
119 | $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() ); |
120 | |
121 | $linkRenderer = $this->getLinkRenderer(); |
122 | return $linkRenderer->makeKnownLink( $wlh, $caption ); |
123 | } |
124 | |
125 | /** |
126 | * Make links to the page corresponding to the item, |
127 | * and the "what links here" page for it |
128 | * |
129 | * @param Skin $skin Skin to be used |
130 | * @param stdClass $result Result row |
131 | * @return string |
132 | */ |
133 | public function formatResult( $skin, $result ) { |
134 | $title = Title::makeTitleSafe( $result->namespace, $result->title ); |
135 | if ( !$title ) { |
136 | return Html::element( |
137 | 'span', |
138 | [ 'class' => 'mw-invalidtitle' ], |
139 | Linker::getInvalidTitleDescription( |
140 | $this->getContext(), |
141 | $result->namespace, |
142 | $result->title ) |
143 | ); |
144 | } |
145 | |
146 | $linkRenderer = $this->getLinkRenderer(); |
147 | $link = $linkRenderer->makeLink( $title ); |
148 | $wlh = $this->makeWlhLink( |
149 | $title, |
150 | $this->msg( 'nlinks' )->numParams( $result->value )->text() |
151 | ); |
152 | |
153 | return $this->getLanguage()->specialList( $link, $wlh ); |
154 | } |
155 | |
156 | protected function getGroupName() { |
157 | return 'highuse'; |
158 | } |
159 | } |
160 | |
161 | /** |
162 | * Retain the old class name for backwards compatibility. |
163 | * @deprecated since 1.41 |
164 | */ |
165 | class_alias( SpecialMostLinked::class, 'SpecialMostLinked' ); |