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 $tableFields = $this->linksMigration->getTitleFields( 'pagelinks' );
75 $fields = [
76 'namespace' => $tableFields[0],
77 'title' => $tableFields[1],
78 ];
79 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
80 return [
81 'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ),
82 'fields' => array_merge( [ 'value' => 'COUNT(*)', 'page_namespace' ], $fields ),
83 'options' => [
84 'HAVING' => 'COUNT(*) > 1',
85 'GROUP BY' => array_merge( $tableFields, [ 'page_namespace' ] )
86 ],
87 'join_conds' => array_merge( $queryInfo['joins'], [
88 'page' => [
89 'LEFT JOIN',
90 [
91 'page_namespace = ' . $fields['namespace'],
92 'page_title = ' . $fields['title']
93 ]
94 ] ] )
95 ];
96 }
97
104 public function preprocessResults( $db, $res ) {
105 $this->executeLBFromResultWrapper( $res );
106 }
107
115 private function makeWlhLink( $title, $caption ) {
116 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
117
118 $linkRenderer = $this->getLinkRenderer();
119 return $linkRenderer->makeKnownLink( $wlh, $caption );
120 }
121
130 public function formatResult( $skin, $result ) {
131 $title = Title::makeTitleSafe( $result->namespace, $result->title );
132 if ( !$title ) {
133 return Html::element(
134 'span',
135 [ 'class' => 'mw-invalidtitle' ],
136 Linker::getInvalidTitleDescription(
137 $this->getContext(),
138 $result->namespace,
139 $result->title )
140 );
141 }
142
143 $linkRenderer = $this->getLinkRenderer();
144 $link = $linkRenderer->makeLink( $title );
145 $wlh = $this->makeWlhLink(
146 $title,
147 $this->msg( 'nlinks' )->numParams( $result->value )->text()
148 );
149
150 return $this->getLanguage()->specialList( $link, $wlh );
151 }
152
153 protected function getGroupName() {
154 return 'highuse';
155 }
156}
157
162class_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:89
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:79
The base class for all skins.
Definition Skin.php:59
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)