MediaWiki master
SpecialUnusedTemplates.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
29use Skin;
30use stdClass;
32
41
42 private LinksMigration $linksMigration;
43
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 return [
90 'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ),
91 'fields' => [
92 'namespace' => 'page_namespace',
93 'title' => 'page_title',
94 ],
95 'conds' => [
96 'page_namespace' => NS_TEMPLATE,
97 'tl_from' => null,
98 'page_is_redirect' => 0
99 ],
100 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] )
101 ];
102 }
103
104 public function preprocessResults( $db, $res ) {
105 $this->executeLBFromResultWrapper( $res );
106 }
107
113 public function formatResult( $skin, $result ) {
114 $linkRenderer = $this->getLinkRenderer();
115 $title = Title::makeTitle( NS_TEMPLATE, $result->title );
116 $pageLink = $linkRenderer->makeKnownLink( $title );
117 $wlhLink = $linkRenderer->makeKnownLink(
118 SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ),
119 $this->msg( 'unusedtemplateswlh' )->text()
120 );
121
122 return $this->getLanguage()->specialList( $pageLink, $wlhLink );
123 }
124
125 protected function getPageHeader() {
126 return $this->msg( 'unusedtemplatestext' )->parseAsBlock();
127 }
128
129 protected function getGroupName() {
130 return 'maintenance';
131 }
132}
133
138class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' );
const NS_TEMPLATE
Definition Defines.php:75
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:89
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:79
The base class for all skins.
Definition Skin.php:59
Provide primary and replica IDatabase connections.