MediaWiki master
SpecialMostLinked.php
Go to the documentation of this file.
1<?php
28namespace MediaWiki\Specials;
29
37use Skin;
38use stdClass;
42
49
50 private LinksMigration $linksMigration;
51
57 public function __construct(
58 IConnectionProvider $dbProvider,
59 LinkBatchFactory $linkBatchFactory,
60 LinksMigration $linksMigration
61 ) {
62 parent::__construct( 'Mostlinked' );
63 $this->setDatabaseProvider( $dbProvider );
64 $this->setLinkBatchFactory( $linkBatchFactory );
65 $this->linksMigration = $linksMigration;
66 }
67
68 public function isExpensive() {
69 return true;
70 }
71
72 public function isSyndicated() {
73 return false;
74 }
75
76 public function getQueryInfo() {
77 $tableFields = $this->linksMigration->getTitleFields( 'pagelinks' );
78 $fields = [
79 'namespace' => $tableFields[0],
80 'title' => $tableFields[1],
81 ];
82 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' );
83 return [
84 'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ),
85 'fields' => array_merge( [ 'value' => 'COUNT(*)', 'page_namespace' ], $fields ),
86 'options' => [
87 'HAVING' => 'COUNT(*) > 1',
88 'GROUP BY' => array_merge( $tableFields, [ 'page_namespace' ] )
89 ],
90 'join_conds' => array_merge( $queryInfo['joins'], [
91 'page' => [
92 'LEFT JOIN',
93 [
94 'page_namespace = ' . $fields['namespace'],
95 'page_title = ' . $fields['title']
96 ]
97 ] ] )
98 ];
99 }
100
107 public function preprocessResults( $db, $res ) {
108 $this->executeLBFromResultWrapper( $res );
109 }
110
118 private function makeWlhLink( $title, $caption ) {
119 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
120
121 $linkRenderer = $this->getLinkRenderer();
122 return $linkRenderer->makeKnownLink( $wlh, $caption );
123 }
124
133 public function formatResult( $skin, $result ) {
134 $title = Title::makeTitleSafe( $result->namespace, $result->title );
135 if ( !$title ) {
136 return Html::element(
137 'span',
138 [ 'class' => 'mw-invalidtitle' ],
139 Linker::getInvalidTitleDescription(
140 $this->getContext(),
141 $result->namespace,
142 $result->title )
143 );
144 }
145
146 $linkRenderer = $this->getLinkRenderer();
147 $link = $linkRenderer->makeLink( $title );
148 $wlh = $this->makeWlhLink(
149 $title,
150 $this->msg( 'nlinks' )->numParams( $result->value )->text()
151 );
152
153 return $this->getLanguage()->specialList( $link, $wlh );
154 }
155
156 protected function getGroupName() {
157 return 'highuse';
158 }
159}
160
165class_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:65
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:88
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.
A special page to show 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:58
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...