MediaWiki master
SpecialMostCategories.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
19use stdClass;
23
31
32 public function __construct(
33 private readonly NamespaceInfo $namespaceInfo,
34 IConnectionProvider $dbProvider,
35 LinkBatchFactory $linkBatchFactory
36 ) {
37 parent::__construct( 'Mostcategories' );
38 $this->setDatabaseProvider( $dbProvider );
39 $this->setLinkBatchFactory( $linkBatchFactory );
40 }
41
43 public function isExpensive() {
44 return true;
45 }
46
48 public function isSyndicated() {
49 return false;
50 }
51
53 public function getQueryInfo() {
54 return [
55 'tables' => [ 'categorylinks', 'page' ],
56 'fields' => [
57 'namespace' => 'page_namespace',
58 'title' => 'page_title',
59 'value' => 'COUNT(*)'
60 ],
61 'conds' => [
62 'page_namespace' => $this->namespaceInfo->getContentNamespaces()
63 ],
64 'options' => [
65 'HAVING' => 'COUNT(*) > 1',
66 'GROUP BY' => [ 'page_namespace', 'page_title' ]
67 ],
68 'join_conds' => [
69 'page' => [
70 'LEFT JOIN',
71 'page_id = cl_from'
72 ]
73 ]
74 ];
75 }
76
78 protected function getRecacheDB() {
79 return $this->getDatabaseProvider()->getReplicaDatabase(
80 CategoryLinksTable::VIRTUAL_DOMAIN,
81 'vslow'
82 );
83 }
84
89 public function preprocessResults( $db, $res ) {
90 $this->executeLBFromResultWrapper( $res );
91 }
92
98 public function formatResult( $skin, $result ) {
99 $title = Title::makeTitleSafe( $result->namespace, $result->title );
100 if ( !$title ) {
101 return Html::element(
102 'span',
103 [ 'class' => 'mw-invalidtitle' ],
104 Linker::getInvalidTitleDescription(
105 $this->getContext(),
106 $result->namespace,
107 $result->title
108 )
109 );
110 }
111
112 $linkRenderer = $this->getLinkRenderer();
113 if ( $this->isCached() ) {
114 $link = $linkRenderer->makeLink( $title );
115 } else {
116 $link = $linkRenderer->makeKnownLink( $title );
117 }
118
119 $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
120
121 return $this->getLanguage()->specialList( $link, $count );
122 }
123
125 protected function getGroupName() {
126 return 'highuse';
127 }
128}
129
134class_alias( SpecialMostCategories::class, 'SpecialMostCategories' );
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Some internal bits split of from Skin.php.
Definition Linker.php:47
Factory for LinkBatch objects to batch query page metadata.
The base class for all skins.
Definition Skin.php:54
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 category count.
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
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...
__construct(private readonly NamespaceInfo $namespaceInfo, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory)
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
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...
Represents a title within MediaWiki.
Definition Title.php:69
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)