MediaWiki master
SpecialUnusedTemplates.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
30use stdClass;
32
41
42 private LinksMigration $linksMigration;
43
44 public function __construct(
45 IConnectionProvider $dbProvider,
46 LinksMigration $linksMigration
47 ) {
48 parent::__construct( 'Unusedtemplates' );
49 $this->setDatabaseProvider( $dbProvider );
50 $this->linksMigration = $linksMigration;
51 }
52
53 public function isExpensive() {
54 return true;
55 }
56
57 public function isSyndicated() {
58 return false;
59 }
60
61 protected function sortDescending() {
62 return false;
63 }
64
65 protected function getOrderFields() {
66 return [ 'title' ];
67 }
68
69 public function getQueryInfo() {
70 $queryInfo = $this->linksMigration->getQueryInfo(
71 'templatelinks',
72 'templatelinks',
73 'LEFT JOIN'
74 );
75 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
76 $joinConds = [];
77 $templatelinksJoin = [
78 'LEFT JOIN', [ "$title = page_title",
79 "$ns = page_namespace" ] ];
80 if ( in_array( 'linktarget', $queryInfo['tables'] ) ) {
81 $joinConds['linktarget'] = $templatelinksJoin;
82 } else {
83 $joinConds['templatelinks'] = $templatelinksJoin;
84 }
85 $joinConds['page_props'] = [ 'LEFT JOIN', [ 'page_id = pp_page', 'pp_propname' => 'expectunusedtemplate' ] ];
86 return [
87 'tables' => array_merge( $queryInfo['tables'], [ 'page' ], [ 'page_props' ] ),
88 'fields' => [
89 'namespace' => 'page_namespace',
90 'title' => 'page_title',
91 ],
92 'conds' => [
93 'page_namespace' => NS_TEMPLATE,
94 'tl_from' => null,
95 'page_is_redirect' => 0,
96 'pp_page' => null
97 ],
98 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] )
99 ];
100 }
101
102 public function preprocessResults( $db, $res ) {
103 $this->executeLBFromResultWrapper( $res );
104 }
105
111 public function formatResult( $skin, $result ) {
112 $linkRenderer = $this->getLinkRenderer();
113 $title = Title::makeTitle( NS_TEMPLATE, $result->title );
114 $pageLink = $linkRenderer->makeKnownLink( $title );
115 $wlhLink = $linkRenderer->makeKnownLink(
116 SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ),
117 $this->msg( 'unusedtemplateswlh' )->text()
118 );
119
120 return $this->getLanguage()->specialList( $pageLink, $wlhLink );
121 }
122
123 protected function getPageHeader() {
124 return $this->msg( 'unusedtemplatestext' )->parseAsBlock();
125 }
126
127 protected function getGroupName() {
128 return 'maintenance';
129 }
130}
131
136class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' );
const NS_TEMPLATE
Definition Defines.php:75
Service for compat reading of links tables.
The base class for all skins.
Definition Skin.php:58
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:87
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.
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
Provide primary and replica IDatabase connections.