MediaWiki master
SpecialMostCategories.php
Go to the documentation of this file.
1<?php
27namespace MediaWiki\Specials;
28
35use Skin;
36use stdClass;
40
47
48 private NamespaceInfo $namespaceInfo;
49
55 public function __construct(
56 NamespaceInfo $namespaceInfo,
57 IConnectionProvider $dbProvider,
58 LinkBatchFactory $linkBatchFactory
59 ) {
60 parent::__construct( 'Mostcategories' );
61 $this->namespaceInfo = $namespaceInfo;
62 $this->setDatabaseProvider( $dbProvider );
63 $this->setLinkBatchFactory( $linkBatchFactory );
64 }
65
66 public function isExpensive() {
67 return true;
68 }
69
70 public function isSyndicated() {
71 return false;
72 }
73
74 public function getQueryInfo() {
75 return [
76 'tables' => [ 'categorylinks', 'page' ],
77 'fields' => [
78 'namespace' => 'page_namespace',
79 'title' => 'page_title',
80 'value' => 'COUNT(*)'
81 ],
82 'conds' => [
83 'page_namespace' => $this->namespaceInfo->getContentNamespaces()
84 ],
85 'options' => [
86 'HAVING' => 'COUNT(*) > 1',
87 'GROUP BY' => [ 'page_namespace', 'page_title' ]
88 ],
89 'join_conds' => [
90 'page' => [
91 'LEFT JOIN',
92 'page_id = cl_from'
93 ]
94 ]
95 ];
96 }
97
102 public function preprocessResults( $db, $res ) {
103 $this->executeLBFromResultWrapper( $res );
104 }
105
111 public function formatResult( $skin, $result ) {
112 $title = Title::makeTitleSafe( $result->namespace, $result->title );
113 if ( !$title ) {
114 return Html::element(
115 'span',
116 [ 'class' => 'mw-invalidtitle' ],
117 Linker::getInvalidTitleDescription(
118 $this->getContext(),
119 $result->namespace,
120 $result->title
121 )
122 );
123 }
124
125 $linkRenderer = $this->getLinkRenderer();
126 if ( $this->isCached() ) {
127 $link = $linkRenderer->makeLink( $title );
128 } else {
129 $link = $linkRenderer->makeKnownLink( $title );
130 }
131
132 $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
133
134 return $this->getLanguage()->specialList( $link, $count );
135 }
136
137 protected function getGroupName() {
138 return 'highuse';
139 }
140}
141
146class_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:65
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)
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.
A special page that list pages that have 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: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...