MediaWiki master
SpecialMostLinked.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
11use MediaWiki\Cache\LinkBatchFactory;
20use stdClass;
24
33
34 private LinksMigration $linksMigration;
35
36 public function __construct(
37 IConnectionProvider $dbProvider,
38 LinkBatchFactory $linkBatchFactory,
39 LinksMigration $linksMigration
40 ) {
41 parent::__construct( 'Mostlinked' );
42 $this->setDatabaseProvider( $dbProvider );
43 $this->setLinkBatchFactory( $linkBatchFactory );
44 $this->linksMigration = $linksMigration;
45 }
46
48 public function isExpensive() {
49 return true;
50 }
51
53 public function isSyndicated() {
54 return false;
55 }
56
58 public function getQueryInfo() {
59 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' );
60 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
61 return [
62 'tables' => $queryInfo['tables'],
63 'fields' => [
64 'namespace' => $ns,
65 'title' => $title,
66 'value' => 'COUNT(*)'
67 ],
68 'options' => [
69 'HAVING' => 'COUNT(*) > 1',
70 'GROUP BY' => [ $ns, $title ],
71 ],
72 'join_conds' => $queryInfo['joins'],
73 ];
74 }
75
77 protected function getRecacheDB() {
78 return $this->getDatabaseProvider()->getReplicaDatabase(
79 PageLinksTable::VIRTUAL_DOMAIN,
80 'vslow'
81 );
82 }
83
90 public function preprocessResults( $db, $res ) {
91 $this->executeLBFromResultWrapper( $res );
92 }
93
101 private function makeWlhLink( $title, $caption ) {
102 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
103
104 $linkRenderer = $this->getLinkRenderer();
105 return $linkRenderer->makeKnownLink( $wlh, $caption );
106 }
107
116 public function formatResult( $skin, $result ) {
117 $title = Title::makeTitleSafe( $result->namespace, $result->title );
118 if ( !$title ) {
119 return Html::element(
120 'span',
121 [ 'class' => 'mw-invalidtitle' ],
122 Linker::getInvalidTitleDescription(
123 $this->getContext(),
124 $result->namespace,
125 $result->title )
126 );
127 }
128
129 $linkRenderer = $this->getLinkRenderer();
130 $link = $linkRenderer->makeLink( $title );
131 $wlh = $this->makeWlhLink(
132 $title,
133 $this->msg( 'nlinks' )->numParams( $result->value )->text()
134 );
135
136 return $this->getLanguage()->specialList( $link, $wlh );
137 }
138
140 protected function getGroupName() {
141 return 'highuse';
142 }
143}
144
149class_alias( SpecialMostLinked::class, 'SpecialMostLinked' );
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 pages ordered by the number of pages linking to them.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
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.
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: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)