MediaWiki master
SpecialMostLinkedCategories.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
19use stdClass;
24
32
33 private readonly ILanguageConverter $languageConverter;
34
35 public function __construct(
36 IConnectionProvider $dbProvider,
37 LinkBatchFactory $linkBatchFactory,
38 LanguageConverterFactory $languageConverterFactory,
39 ) {
40 parent::__construct( 'Mostlinkedcategories' );
41 $this->setDatabaseProvider( $dbProvider );
42 $this->setLinkBatchFactory( $linkBatchFactory );
43 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
44 }
45
47 public function isSyndicated() {
48 return false;
49 }
50
52 public function getQueryInfo() {
53 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
54 return [
55 'tables' => [ 'category' ],
56 'fields' => [ 'title' => 'cat_title',
57 'namespace' => NS_CATEGORY,
58 'value' => 'cat_pages' ],
59 'conds' => [ $dbr->expr( 'cat_pages', '>', 0 ) ],
60 ];
61 }
62
64 protected function sortDescending() {
65 return true;
66 }
67
74 public function preprocessResults( $db, $res ) {
75 $this->executeLBFromResultWrapper( $res );
76 }
77
83 public function formatResult( $skin, $result ) {
84 $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
85 if ( !$nt ) {
86 return Html::element(
87 'span',
88 [ 'class' => 'mw-invalidtitle' ],
89 Linker::getInvalidTitleDescription(
90 $this->getContext(),
92 $result->title )
93 );
94 }
95
96 $text = $this->languageConverter->convertHtml( $nt->getText() );
97
98 $plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
99 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
100
101 return $this->getLanguage()->specialList( $plink, $nlinks );
102 }
103
105 protected function getGroupName() {
106 return 'highuse';
107 }
108}
113class_alias( SpecialMostLinkedCategories::class, 'SpecialMostLinkedCategories' );
const NS_CATEGORY
Definition Defines.php:65
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
An interface for creating language converters.
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
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)
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.
getContentLanguage()
Shortcut to get content language.
getLanguage()
Shortcut to get user's language.
List of categories with the most pages in them.
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LanguageConverterFactory $languageConverterFactory,)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
preprocessResults( $db, $res)
Fetch user page links and cache their existence.
sortDescending()
Override to sort by increasing values.to override bool
Represents a title within MediaWiki.
Definition Title.php:69
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:18
The shared interface for all language converters.
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)