MediaWiki master
SpecialMostLinkedTemplates.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
30use Skin;
31use stdClass;
35
44
45 private LinksMigration $linksMigration;
46
52 public function __construct(
53 IConnectionProvider $dbProvider,
54 LinkBatchFactory $linkBatchFactory,
55 LinksMigration $linksMigration
56 ) {
57 parent::__construct( 'Mostlinkedtemplates' );
58 $this->setDatabaseProvider( $dbProvider );
59 $this->setLinkBatchFactory( $linkBatchFactory );
60 $this->linksMigration = $linksMigration;
61 }
62
68 public function isExpensive() {
69 return true;
70 }
71
77 public function isSyndicated() {
78 return false;
79 }
80
86 public function sortDescending() {
87 return true;
88 }
89
90 public function getQueryInfo() {
91 $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
92 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
93 return [
94 'tables' => $queryInfo['tables'],
95 'fields' => [
96 'namespace' => $ns,
97 'title' => $title,
98 'value' => 'COUNT(*)'
99 ],
100 'options' => [ 'GROUP BY' => [ $ns, $title ] ],
101 'join_conds' => $queryInfo['joins']
102 ];
103 }
104
111 public function preprocessResults( $db, $res ) {
112 $this->executeLBFromResultWrapper( $res );
113 }
114
122 public function formatResult( $skin, $result ) {
123 $title = Title::makeTitleSafe( $result->namespace, $result->title );
124 if ( !$title ) {
125 return Html::element(
126 'span',
127 [ 'class' => 'mw-invalidtitle' ],
128 Linker::getInvalidTitleDescription(
129 $this->getContext(),
130 $result->namespace,
131 $result->title
132 )
133 );
134 }
135
136 return $this->getLanguage()->specialList(
137 $this->getLinkRenderer()->makeLink( $title ),
138 $this->makeWlhLink( $title, $result )
139 );
140 }
141
149 private function makeWlhLink( $title, $result ) {
150 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
151 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
152
153 return $this->getLinkRenderer()->makeLink( $wlh, $label );
154 }
155
156 protected function getGroupName() {
157 return 'highuse';
158 }
159}
160
165class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Some internal bits split of from Skin.php.
Definition Linker.php:63
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...
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
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,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
List of templates with a large number of transclusion links, i.e.
isExpensive()
Is this report expensive, i.e should it be cached?
preprocessResults( $db, $res)
Pre-cache page existence to speed up link generation.
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
sortDescending()
Sort the results in descending order?
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Represents a title within MediaWiki.
Definition Title.php:78
The base class for all skins.
Definition Skin.php:59
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)