MediaWiki master
SpecialMostLinkedTemplates.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use MediaWiki\Cache\LinkBatchFactory;
18use stdClass;
22
31
32 private LinksMigration $linksMigration;
33
34 public function __construct(
35 IConnectionProvider $dbProvider,
36 LinkBatchFactory $linkBatchFactory,
37 LinksMigration $linksMigration
38 ) {
39 parent::__construct( 'Mostlinkedtemplates' );
40 $this->setDatabaseProvider( $dbProvider );
41 $this->setLinkBatchFactory( $linkBatchFactory );
42 $this->linksMigration = $linksMigration;
43 }
44
50 public function isExpensive() {
51 return true;
52 }
53
59 public function isSyndicated() {
60 return false;
61 }
62
68 public function sortDescending() {
69 return true;
70 }
71
73 public function getQueryInfo() {
74 $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
75 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
76 return [
77 'tables' => $queryInfo['tables'],
78 'fields' => [
79 'namespace' => $ns,
80 'title' => $title,
81 'value' => 'COUNT(*)'
82 ],
83 'options' => [ 'GROUP BY' => [ $ns, $title ] ],
84 'join_conds' => $queryInfo['joins']
85 ];
86 }
87
94 public function preprocessResults( $db, $res ) {
95 $this->executeLBFromResultWrapper( $res );
96 }
97
105 public function formatResult( $skin, $result ) {
106 $title = Title::makeTitleSafe( $result->namespace, $result->title );
107 if ( !$title ) {
108 return Html::element(
109 'span',
110 [ 'class' => 'mw-invalidtitle' ],
111 Linker::getInvalidTitleDescription(
112 $this->getContext(),
113 $result->namespace,
114 $result->title
115 )
116 );
117 }
118
119 return $this->getLanguage()->specialList(
120 $this->getLinkRenderer()->makeLink( $title ),
121 $this->makeWlhLink( $title, $result )
122 );
123 }
124
132 private function makeWlhLink( $title, $result ) {
133 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
134 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
135
136 return $this->getLinkRenderer()->makeLink( $wlh, $label );
137 }
138
140 protected function getGroupName() {
141 return 'highuse';
142 }
143
145 protected function getRecacheDB() {
146 return $this->getDatabaseProvider()->getReplicaDatabase(
147 TemplateLinksTable::VIRTUAL_DOMAIN,
148 'vslow'
149 );
150 }
151}
152
157class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
Some internal bits split of from Skin.php.
Definition Linker.php:47
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...
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.
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
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:70
Provide primary and replica IDatabase connections.
A database connection without write operations.
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)