MediaWiki  master
SpecialUnusedTemplates.php
Go to the documentation of this file.
1 <?php
27 namespace MediaWiki\Specials;
28 
33 use Skin;
34 use 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(
119  $title,
120  null,
121  [],
122  [ 'redirect' => 'no' ]
123  );
124  $wlhLink = $linkRenderer->makeKnownLink(
125  SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ),
126  $this->msg( 'unusedtemplateswlh' )->text()
127  );
128 
129  return $this->getLanguage()->specialList( $pageLink, $wlhLink );
130  }
131 
132  protected function getPageHeader() {
133  return $this->msg( 'unusedtemplatestext' )->parseAsBlock();
134  }
135 
136  protected function getGroupName() {
137  return 'maintenance';
138  }
139 }
140 
145 class_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)
Definition: QueryPage.php:985
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:946
Parent class for all special pages.
Definition: SpecialPage.php:65
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:76
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:624
The base class for all skins.
Definition: Skin.php:60
Provide primary and replica IDatabase connections.