MediaWiki master
SpecialMostLinkedCategories.php
Go to the documentation of this file.
1<?php
27namespace MediaWiki\Specials;
28
29use HtmlArmor;
37use Skin;
38use stdClass;
42
49
50 private ILanguageConverter $languageConverter;
51
57 public function __construct(
58 IConnectionProvider $dbProvider,
59 LinkBatchFactory $linkBatchFactory,
60 LanguageConverterFactory $languageConverterFactory
61 ) {
62 parent::__construct( 'Mostlinkedcategories' );
63 $this->setDatabaseProvider( $dbProvider );
64 $this->setLinkBatchFactory( $linkBatchFactory );
65 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
66 }
67
68 public function isSyndicated() {
69 return false;
70 }
71
72 public function getQueryInfo() {
73 return [
74 'tables' => [ 'category' ],
75 'fields' => [ 'title' => 'cat_title',
76 'namespace' => NS_CATEGORY,
77 'value' => 'cat_pages' ],
78 'conds' => [ 'cat_pages > 0' ],
79 ];
80 }
81
82 protected function sortDescending() {
83 return true;
84 }
85
92 public function preprocessResults( $db, $res ) {
93 $this->executeLBFromResultWrapper( $res );
94 }
95
101 public function formatResult( $skin, $result ) {
102 $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
103 if ( !$nt ) {
104 return Html::element(
105 'span',
106 [ 'class' => 'mw-invalidtitle' ],
107 Linker::getInvalidTitleDescription(
108 $this->getContext(),
110 $result->title )
111 );
112 }
113
114 $text = $this->languageConverter->convertHtml( $nt->getText() );
115
116 $plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
117 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
118
119 return $this->getLanguage()->specialList( $plink, $nlinks );
120 }
121
122 protected function getGroupName() {
123 return 'highuse';
124 }
125}
130class_alias( SpecialMostLinkedCategories::class, 'SpecialMostLinkedCategories' );
const NS_CATEGORY
Definition Defines.php:78
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
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: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)
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.
A querypage to show categories ordered in descending order by the pages in them.
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.
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LanguageConverterFactory $languageConverterFactory)
preprocessResults( $db, $res)
Fetch user page links and cache their existence.
sortDescending()
Override to sort by increasing values.
Represents a title within MediaWiki.
Definition Title.php:79
The base class for all skins.
Definition Skin.php:60
The shared interface for all language converters.
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.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...