MediaWiki master
SpecialMostInterwikis.php
Go to the documentation of this file.
1<?php
7
8namespace MediaWiki\Specials;
9
10use MediaWiki\Deferred\LinksUpdate\LangLinksTable;
11use MediaWiki\Html\Html;
12use MediaWiki\Linker\Linker;
13use MediaWiki\Page\LinkBatchFactory;
14use MediaWiki\Skin\Skin;
15use MediaWiki\SpecialPage\QueryPage;
16use MediaWiki\Title\NamespaceInfo;
17use MediaWiki\Title\Title;
18use stdClass;
19use Wikimedia\Rdbms\IConnectionProvider;
20use Wikimedia\Rdbms\IReadableDatabase;
21use Wikimedia\Rdbms\IResultWrapper;
22
29
30 public function __construct(
31 private readonly NamespaceInfo $namespaceInfo,
32 IConnectionProvider $dbProvider,
33 LinkBatchFactory $linkBatchFactory,
34 ) {
35 parent::__construct( 'Mostinterwikis' );
36 $this->setDatabaseProvider( $dbProvider );
37 $this->setLinkBatchFactory( $linkBatchFactory );
38 }
39
41 public function isExpensive() {
42 return true;
43 }
44
46 public function isSyndicated() {
47 return false;
48 }
49
51 public function getQueryInfo() {
52 return [
53 'tables' => [ 'langlinks', 'page' ],
54 'fields' => [
55 'namespace' => 'page_namespace',
56 'title' => 'page_title',
57 'value' => 'COUNT(*)'
58 ],
59 'conds' => [ 'page_namespace' => $this->namespaceInfo->getContentNamespaces() ],
60 'join_conds' => [ 'page' => [ 'LEFT JOIN', 'page_id = ll_from' ] ],
61 'options' => [
62 'HAVING' => 'COUNT(*) > 1',
63 'GROUP BY' => [ 'page_namespace', 'page_title' ]
64 ],
65 ];
66 }
67
74 public function preprocessResults( $db, $res ) {
75 $this->executeLBFromResultWrapper( $res );
76 }
77
83 public function formatResult( $skin, $result ) {
84 $title = Title::makeTitleSafe( $result->namespace, $result->title );
85 if ( !$title ) {
86 return Html::element(
87 'span',
88 [ 'class' => 'mw-invalidtitle' ],
89 Linker::getInvalidTitleDescription(
90 $this->getContext(),
91 $result->namespace,
92 $result->title
93 )
94 );
95 }
96
97 $linkRenderer = $this->getLinkRenderer();
98 if ( $this->isCached() ) {
99 $link = $linkRenderer->makeLink( $title );
100 } else {
101 $link = $linkRenderer->makeKnownLink( $title );
102 }
103
104 $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
105
106 return $this->getLanguage()->specialList( $link, $count );
107 }
108
110 protected function getRecacheDB() {
111 return $this->getDatabaseProvider()->getReplicaDatabase(
112 LangLinksTable::VIRTUAL_DOMAIN,
113 'vslow'
114 );
115 }
116
118 protected function getGroupName() {
119 return 'highuse';
120 }
121}
122
123// @codeCoverageIgnoreStart
128class_alias( SpecialMostInterwikis::class, 'SpecialMostInterwikis' );
129// @codeCoverageIgnoreEnd
Factory for LinkBatch objects to batch query page metadata.
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)
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
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)
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 that have the highest interwiki count.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(private readonly NamespaceInfo $namespaceInfo, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory,)
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
preprocessResults( $db, $res)
Pre-fill the link cache.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Provide primary and replica IDatabase connections.
element(SerializerNode $parent, SerializerNode $node, $contents)