Debian Codegraph @

includes/specials/SpecialUnusedTemplates.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2006 Rob Church
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 */
22
23 namespace MediaWiki\Specials;
24
25 use MediaWiki\Linker\LinksMigration;
26 use MediaWiki\SpecialPage\QueryPage;
27 use MediaWiki\SpecialPage\SpecialPage;
28 use MediaWiki\Title\Title;
29 use Skin;
30 use stdClass;
31 use Wikimedia\Rdbms\IConnectionProvider;
32
33 /**
34 * Lists of unused templates
35 *
36 * @see SpecialMostLinkedTemplates
37 * @ingroup SpecialPage
38 * @author Rob Church <[email protected]>
39 */
40 class SpecialUnusedTemplates extends QueryPage {
41
42 private LinksMigration $linksMigration;
43
44 /**
45 * @param IConnectionProvider $dbProvider
46 * @param LinksMigration $linksMigration
47 */
48 public function __construct(
49 IConnectionProvider $dbProvider,
50 LinksMigration $linksMigration
51 ) {
52 parent::__construct( 'Unusedtemplates' );
53 $this->setDatabaseProvider( $dbProvider );
54 $this->linksMigration = $linksMigration;
55 }
56
57 public function isExpensive() {
58 return true;
59 }
60
61 public function isSyndicated() {
62 return false;
63 }
64
65 protected function sortDescending() {
66 return false;
67 }
68
69 protected function getOrderFields() {
70 return [ 'title' ];
71 }
72
73 public function getQueryInfo() {
74 $queryInfo = $this->linksMigration->getQueryInfo(
75 'templatelinks',
76 'templatelinks',
77 'LEFT JOIN'
78 );
79 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
80 $joinConds = [];
81 $templatelinksJoin = [
82 'LEFT JOIN', [ "$title = page_title",
83 "$ns = page_namespace" ] ];
84 if ( in_array( 'linktarget', $queryInfo['tables'] ) ) {
85 $joinConds['linktarget'] = $templatelinksJoin;
86 } else {
87 $joinConds['templatelinks'] = $templatelinksJoin;
88 }
89 $joinConds['page_props'] = [ 'LEFT JOIN', [ 'page_id = pp_page', 'pp_propname' => 'expectunusedtemplate' ] ];
90 return [
91 'tables' => array_merge( $queryInfo['tables'], [ 'page' ], [ 'page_props' ] ),
92 'fields' => [
93 'namespace' => 'page_namespace',
94 'title' => 'page_title',
95 ],
96 'conds' => [
97 'page_namespace' => NS_TEMPLATE,
98 'tl_from' => null,
99 'page_is_redirect' => 0,
100 'pp_page' => null
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' );