MediaWiki master
SpecialMostLinkedTemplates.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
18use stdClass;
22
31
32 public function __construct(
33 IConnectionProvider $dbProvider,
34 LinkBatchFactory $linkBatchFactory,
35 private readonly LinksMigration $linksMigration,
36 ) {
37 parent::__construct( 'Mostlinkedtemplates' );
38 $this->setDatabaseProvider( $dbProvider );
39 $this->setLinkBatchFactory( $linkBatchFactory );
40 }
41
47 public function isExpensive() {
48 return true;
49 }
50
56 public function isSyndicated() {
57 return false;
58 }
59
65 public function sortDescending() {
66 return true;
67 }
68
70 public function getQueryInfo() {
71 $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
72 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
73 return [
74 'tables' => $queryInfo['tables'],
75 'fields' => [
76 'namespace' => $ns,
77 'title' => $title,
78 'value' => 'COUNT(*)'
79 ],
80 'options' => [ 'GROUP BY' => [ $ns, $title ] ],
81 'join_conds' => $queryInfo['joins']
82 ];
83 }
84
91 public function preprocessResults( $db, $res ) {
92 $this->executeLBFromResultWrapper( $res );
93 }
94
102 public function formatResult( $skin, $result ) {
103 $title = Title::makeTitleSafe( $result->namespace, $result->title );
104 if ( !$title ) {
105 return Html::element(
106 'span',
107 [ 'class' => 'mw-invalidtitle' ],
108 Linker::getInvalidTitleDescription(
109 $this->getContext(),
110 $result->namespace,
111 $result->title
112 )
113 );
114 }
115
116 return $this->getLanguage()->specialList(
117 $this->getLinkRenderer()->makeLink( $title ),
118 $this->makeWlhLink( $title, $result )
119 );
120 }
121
129 private function makeWlhLink( $title, $result ) {
130 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
131 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
132
133 return $this->getLinkRenderer()->makeLink( $wlh, $label );
134 }
135
137 protected function getGroupName() {
138 return 'highuse';
139 }
140
142 protected function getRecacheDB() {
143 return $this->getDatabaseProvider()->getReplicaDatabase(
144 TemplateLinksTable::VIRTUAL_DOMAIN,
145 'vslow'
146 );
147 }
148}
149
154class_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.
Factory for LinkBatch objects to batch query page metadata.
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.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, private readonly LinksMigration $linksMigration,)
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:69
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)