Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
SpecialUnusedTemplates | |
0.00% |
0 / 44 |
|
0.00% |
0 / 10 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
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 | |||
sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOrderFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
6 | |||
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getPageHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Unusedtemplates |
4 | * |
5 | * Copyright © 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 Rob Church <robchur@gmail.com> |
25 | */ |
26 | |
27 | namespace MediaWiki\Specials; |
28 | |
29 | use MediaWiki\Linker\LinksMigration; |
30 | use MediaWiki\SpecialPage\QueryPage; |
31 | use MediaWiki\SpecialPage\SpecialPage; |
32 | use MediaWiki\Title\Title; |
33 | use Skin; |
34 | use stdClass; |
35 | use Wikimedia\Rdbms\IConnectionProvider; |
36 | |
37 | /** |
38 | * A special page that lists unused templates |
39 | * |
40 | * @ingroup SpecialPage |
41 | */ |
42 | class SpecialUnusedTemplates extends QueryPage { |
43 | |
44 | private LinksMigration $linksMigration; |
45 | |
46 | /** |
47 | * @param IConnectionProvider $dbProvider |
48 | * @param LinksMigration $linksMigration |
49 | */ |
50 | public function __construct( |
51 | IConnectionProvider $dbProvider, |
52 | LinksMigration $linksMigration |
53 | ) { |
54 | parent::__construct( 'Unusedtemplates' ); |
55 | $this->setDatabaseProvider( $dbProvider ); |
56 | $this->linksMigration = $linksMigration; |
57 | } |
58 | |
59 | public function isExpensive() { |
60 | return true; |
61 | } |
62 | |
63 | public function isSyndicated() { |
64 | return false; |
65 | } |
66 | |
67 | protected function sortDescending() { |
68 | return false; |
69 | } |
70 | |
71 | protected function getOrderFields() { |
72 | return [ 'title' ]; |
73 | } |
74 | |
75 | public function getQueryInfo() { |
76 | $queryInfo = $this->linksMigration->getQueryInfo( |
77 | 'templatelinks', |
78 | 'templatelinks', |
79 | 'LEFT JOIN' |
80 | ); |
81 | [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' ); |
82 | $joinConds = []; |
83 | $templatelinksJoin = [ |
84 | 'LEFT JOIN', [ "$title = page_title", |
85 | "$ns = page_namespace" ] ]; |
86 | if ( in_array( 'linktarget', $queryInfo['tables'] ) ) { |
87 | $joinConds['linktarget'] = $templatelinksJoin; |
88 | } else { |
89 | $joinConds['templatelinks'] = $templatelinksJoin; |
90 | } |
91 | return [ |
92 | 'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ), |
93 | 'fields' => [ |
94 | 'namespace' => 'page_namespace', |
95 | 'title' => 'page_title', |
96 | ], |
97 | 'conds' => [ |
98 | 'page_namespace' => NS_TEMPLATE, |
99 | 'tl_from' => null, |
100 | 'page_is_redirect' => 0 |
101 | ], |
102 | 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] ) |
103 | ]; |
104 | } |
105 | |
106 | public function preprocessResults( $db, $res ) { |
107 | $this->executeLBFromResultWrapper( $res ); |
108 | } |
109 | |
110 | /** |
111 | * @param Skin $skin |
112 | * @param stdClass $result Result row |
113 | * @return string |
114 | */ |
115 | public function formatResult( $skin, $result ) { |
116 | $linkRenderer = $this->getLinkRenderer(); |
117 | $title = Title::makeTitle( NS_TEMPLATE, $result->title ); |
118 | $pageLink = $linkRenderer->makeKnownLink( $title ); |
119 | $wlhLink = $linkRenderer->makeKnownLink( |
120 | SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ), |
121 | $this->msg( 'unusedtemplateswlh' )->text() |
122 | ); |
123 | |
124 | return $this->getLanguage()->specialList( $pageLink, $wlhLink ); |
125 | } |
126 | |
127 | protected function getPageHeader() { |
128 | return $this->msg( 'unusedtemplatestext' )->parseAsBlock(); |
129 | } |
130 | |
131 | protected function getGroupName() { |
132 | return 'maintenance'; |
133 | } |
134 | } |
135 | |
136 | /** |
137 | * Retain the old class name for backwards compatibility. |
138 | * @deprecated since 1.41 |
139 | */ |
140 | class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' ); |