MediaWiki master
SpecialUnusedTemplates.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
17use stdClass;
19
28
29 private LinksMigration $linksMigration;
30
31 public function __construct(
32 IConnectionProvider $dbProvider,
33 LinksMigration $linksMigration
34 ) {
35 parent::__construct( 'Unusedtemplates' );
36 $this->setDatabaseProvider( $dbProvider );
37 $this->linksMigration = $linksMigration;
38 }
39
41 public function isExpensive() {
42 return true;
43 }
44
46 public function isSyndicated() {
47 return false;
48 }
49
51 protected function sortDescending() {
52 return false;
53 }
54
56 protected function getOrderFields() {
57 return [ 'title' ];
58 }
59
61 public function getQueryInfo() {
62 $queryInfo = $this->linksMigration->getQueryInfo(
63 'templatelinks',
64 'templatelinks',
65 'LEFT JOIN'
66 );
67 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
68 $joinConds = [];
69 $templatelinksJoin = [
70 'LEFT JOIN', [ "$title = page_title",
71 "$ns = page_namespace" ] ];
72 if ( in_array( 'linktarget', $queryInfo['tables'] ) ) {
73 $joinConds['linktarget'] = $templatelinksJoin;
74 } else {
75 $joinConds['templatelinks'] = $templatelinksJoin;
76 }
77 $joinConds['page_props'] = [ 'LEFT JOIN', [ 'page_id = pp_page', 'pp_propname' => 'expectunusedtemplate' ] ];
78 return [
79 'tables' => array_merge( $queryInfo['tables'], [ 'page' ], [ 'page_props' ] ),
80 'fields' => [
81 'namespace' => 'page_namespace',
82 'title' => 'page_title',
83 ],
84 'conds' => [
85 'page_namespace' => NS_TEMPLATE,
86 'tl_from' => null,
87 'page_is_redirect' => 0,
88 'pp_page' => null
89 ],
90 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] )
91 ];
92 }
93
95 public function preprocessResults( $db, $res ) {
96 $this->executeLBFromResultWrapper( $res );
97 }
98
104 public function formatResult( $skin, $result ) {
105 $linkRenderer = $this->getLinkRenderer();
106 $title = Title::makeTitle( NS_TEMPLATE, $result->title );
107 $pageLink = $linkRenderer->makeKnownLink( $title );
108 $wlhLink = $linkRenderer->makeKnownLink(
109 SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ),
110 $this->msg( 'unusedtemplateswlh' )->text()
111 );
112
113 return $this->getLanguage()->specialList( $pageLink, $wlhLink );
114 }
115
117 protected function getPageHeader() {
118 return $this->msg( 'unusedtemplatestext' )->parseAsBlock();
119 }
120
122 protected function getGroupName() {
123 return 'maintenance';
124 }
125
127 protected function getRecacheDB() {
128 return $this->getDatabaseProvider()->getReplicaDatabase(
129 TemplateLinksTable::VIRTUAL_DOMAIN,
130 'vslow'
131 );
132 }
133}
134
139class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' );
const NS_TEMPLATE
Definition Defines.php:61
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
Service for compat reading of links tables.
The base class for all skins.
Definition Skin.php:52
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:77
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.to override bool
getOrderFields()
Subclasses return an array of fields to order by here.Don't append DESC to the field names,...
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
sortDescending()
Override to sort by increasing values.to override bool
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
preprocessResults( $db, $res)
Do any necessary preprocessing of the result object.to override
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.to override string
__construct(IConnectionProvider $dbProvider, LinksMigration $linksMigration)
Represents a title within MediaWiki.
Definition Title.php:69
Provide primary and replica IDatabase connections.