MediaWiki master
SpecialMostLinked.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
32use Skin;
33use stdClass;
37
46
47 private LinksMigration $linksMigration;
48
54 public function __construct(
55 IConnectionProvider $dbProvider,
56 LinkBatchFactory $linkBatchFactory,
57 LinksMigration $linksMigration
58 ) {
59 parent::__construct( 'Mostlinked' );
60 $this->setDatabaseProvider( $dbProvider );
61 $this->setLinkBatchFactory( $linkBatchFactory );
62 $this->linksMigration = $linksMigration;
63 }
64
65 public function isExpensive() {
66 return true;
67 }
68
69 public function isSyndicated() {
70 return false;
71 }
72
73 public function getQueryInfo() {
74 [ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' );
75 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
76 return [
77 'tables' => $queryInfo['tables'],
78 'fields' => [
79 'namespace' => $ns,
80 'title' => $title,
81 'value' => 'COUNT(*)'
82 ],
83 'options' => [
84 'HAVING' => 'COUNT(*) > 1',
85 'GROUP BY' => [ $ns, $title ],
86 ],
87 'join_conds' => $queryInfo['joins'],
88 ];
89 }
90
97 public function preprocessResults( $db, $res ) {
98 $this->executeLBFromResultWrapper( $res );
99 }
100
108 private function makeWlhLink( $title, $caption ) {
109 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
110
111 $linkRenderer = $this->getLinkRenderer();
112 return $linkRenderer->makeKnownLink( $wlh, $caption );
113 }
114
123 public function formatResult( $skin, $result ) {
124 $title = Title::makeTitleSafe( $result->namespace, $result->title );
125 if ( !$title ) {
126 return Html::element(
127 'span',
128 [ 'class' => 'mw-invalidtitle' ],
129 Linker::getInvalidTitleDescription(
130 $this->getContext(),
131 $result->namespace,
132 $result->title )
133 );
134 }
135
136 $linkRenderer = $this->getLinkRenderer();
137 $link = $linkRenderer->makeLink( $title );
138 $wlh = $this->makeWlhLink(
139 $title,
140 $this->msg( 'nlinks' )->numParams( $result->value )->text()
141 );
142
143 return $this->getLanguage()->specialList( $link, $wlh );
144 }
145
146 protected function getGroupName() {
147 return 'highuse';
148 }
149}
150
155class_alias( SpecialMostLinked::class, 'SpecialMostLinked' );
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:87
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.
__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.
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?
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Represents a title within MediaWiki.
Definition Title.php:78
The base class for all skins.
Definition Skin.php:64
Provide primary and replica IDatabase connections.
Interface to a relational database.
Definition IDatabase.php:48
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)