MediaWiki master
SpecialUnusedTemplates.php
Go to the documentation of this file.
1<?php
27namespace MediaWiki\Specials;
28
33use Skin;
34use stdClass;
36
43
44 private LinksMigration $linksMigration;
45
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
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
140class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' );
const NS_TEMPLATE
Definition Defines.php:74
Service for compat reading of links tables.
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:88
setDatabaseProvider(IConnectionProvider $databaseProvider)
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
A special page that lists unused templates.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
getOrderFields()
Subclasses return an array of fields to order by here.
isExpensive()
Should this query page only be updated offline on large wikis?
sortDescending()
Override to sort by increasing values.
preprocessResults( $db, $res)
Do any necessary preprocessing of the result object.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getPageHeader()
The content returned by this function will be output before any result.
__construct(IConnectionProvider $dbProvider, LinksMigration $linksMigration)
Represents a title within MediaWiki.
Definition Title.php:78
The base class for all skins.
Definition Skin.php:58
Provide primary and replica IDatabase connections.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...