MediaWiki master
SpecialMostLinked.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
20use stdClass;
24
33
34 public function __construct(
35 IConnectionProvider $dbProvider,
36 LinkBatchFactory $linkBatchFactory,
37 private readonly LinksMigration $linksMigration,
38 ) {
39 parent::__construct( 'Mostlinked' );
40 $this->setDatabaseProvider( $dbProvider );
41 $this->setLinkBatchFactory( $linkBatchFactory );
42 }
43
45 public function isExpensive() {
46 return true;
47 }
48
50 public function isSyndicated() {
51 return false;
52 }
53
55 public function getQueryInfo() {
56 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' );
57 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
58 return [
59 'tables' => $queryInfo['tables'],
60 'fields' => [
61 'namespace' => $ns,
62 'title' => $title,
63 'value' => 'COUNT(*)'
64 ],
65 'options' => [
66 'HAVING' => 'COUNT(*) > 1',
67 'GROUP BY' => [ $ns, $title ],
68 ],
69 'join_conds' => $queryInfo['joins'],
70 ];
71 }
72
74 protected function getRecacheDB() {
75 return $this->getDatabaseProvider()->getReplicaDatabase(
76 PageLinksTable::VIRTUAL_DOMAIN,
77 'vslow'
78 );
79 }
80
87 public function preprocessResults( $db, $res ) {
88 $this->executeLBFromResultWrapper( $res );
89 }
90
98 private function makeWlhLink( $title, $caption ) {
99 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
100
101 $linkRenderer = $this->getLinkRenderer();
102 return $linkRenderer->makeKnownLink( $wlh, $caption );
103 }
104
113 public function formatResult( $skin, $result ) {
114 $title = Title::makeTitleSafe( $result->namespace, $result->title );
115 if ( !$title ) {
116 return Html::element(
117 'span',
118 [ 'class' => 'mw-invalidtitle' ],
119 Linker::getInvalidTitleDescription(
120 $this->getContext(),
121 $result->namespace,
122 $result->title )
123 );
124 }
125
126 $linkRenderer = $this->getLinkRenderer();
127 $link = $linkRenderer->makeLink( $title );
128 $wlh = $this->makeWlhLink(
129 $title,
130 $this->msg( 'nlinks' )->numParams( $result->value )->text()
131 );
132
133 return $this->getLanguage()->specialList( $link, $wlh );
134 }
135
137 protected function getGroupName() {
138 return 'highuse';
139 }
140}
141
146class_alias( SpecialMostLinked::class, 'SpecialMostLinked' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
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:54
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 pages ordered by the number of pages linking to them.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
preprocessResults( $db, $res)
Pre-fill the link cache.
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
formatResult( $skin, $result)
Make links to the page corresponding to the item, and the "what links here" page for it.
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, private readonly LinksMigration $linksMigration,)
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
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)