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