MediaWiki master
SpecialMostCategories.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
31use Skin;
32use stdClass;
36
44
45 private NamespaceInfo $namespaceInfo;
46
52 public function __construct(
53 NamespaceInfo $namespaceInfo,
54 IConnectionProvider $dbProvider,
55 LinkBatchFactory $linkBatchFactory
56 ) {
57 parent::__construct( 'Mostcategories' );
58 $this->namespaceInfo = $namespaceInfo;
59 $this->setDatabaseProvider( $dbProvider );
60 $this->setLinkBatchFactory( $linkBatchFactory );
61 }
62
63 public function isExpensive() {
64 return true;
65 }
66
67 public function isSyndicated() {
68 return false;
69 }
70
71 public function getQueryInfo() {
72 return [
73 'tables' => [ 'categorylinks', 'page' ],
74 'fields' => [
75 'namespace' => 'page_namespace',
76 'title' => 'page_title',
77 'value' => 'COUNT(*)'
78 ],
79 'conds' => [
80 'page_namespace' => $this->namespaceInfo->getContentNamespaces()
81 ],
82 'options' => [
83 'HAVING' => 'COUNT(*) > 1',
84 'GROUP BY' => [ 'page_namespace', 'page_title' ]
85 ],
86 'join_conds' => [
87 'page' => [
88 'LEFT JOIN',
89 'page_id = cl_from'
90 ]
91 ]
92 ];
93 }
94
99 public function preprocessResults( $db, $res ) {
100 $this->executeLBFromResultWrapper( $res );
101 }
102
108 public function formatResult( $skin, $result ) {
109 $title = Title::makeTitleSafe( $result->namespace, $result->title );
110 if ( !$title ) {
111 return Html::element(
112 'span',
113 [ 'class' => 'mw-invalidtitle' ],
114 Linker::getInvalidTitleDescription(
115 $this->getContext(),
116 $result->namespace,
117 $result->title
118 )
119 );
120 }
121
122 $linkRenderer = $this->getLinkRenderer();
123 if ( $this->isCached() ) {
124 $link = $linkRenderer->makeLink( $title );
125 } else {
126 $link = $linkRenderer->makeKnownLink( $title );
127 }
128
129 $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
130
131 return $this->getLanguage()->specialList( $link, $count );
132 }
133
134 protected function getGroupName() {
135 return 'highuse';
136 }
137}
138
143class_alias( SpecialMostCategories::class, 'SpecialMostCategories' );
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
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)
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.
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...
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
__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: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)