MediaWiki master
SpecialMostLinkedCategories.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
25use HtmlArmor;
33use Skin;
34use stdClass;
38
46
47 private ILanguageConverter $languageConverter;
48
54 public function __construct(
55 IConnectionProvider $dbProvider,
56 LinkBatchFactory $linkBatchFactory,
57 LanguageConverterFactory $languageConverterFactory
58 ) {
59 parent::__construct( 'Mostlinkedcategories' );
60 $this->setDatabaseProvider( $dbProvider );
61 $this->setLinkBatchFactory( $linkBatchFactory );
62 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
63 }
64
65 public function isSyndicated() {
66 return false;
67 }
68
69 public function getQueryInfo() {
70 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
71 return [
72 'tables' => [ 'category' ],
73 'fields' => [ 'title' => 'cat_title',
74 'namespace' => NS_CATEGORY,
75 'value' => 'cat_pages' ],
76 'conds' => [ $dbr->expr( 'cat_pages', '>', 0 ) ],
77 ];
78 }
79
80 protected function sortDescending() {
81 return true;
82 }
83
90 public function preprocessResults( $db, $res ) {
91 $this->executeLBFromResultWrapper( $res );
92 }
93
99 public function formatResult( $skin, $result ) {
100 $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
101 if ( !$nt ) {
102 return Html::element(
103 'span',
104 [ 'class' => 'mw-invalidtitle' ],
105 Linker::getInvalidTitleDescription(
106 $this->getContext(),
108 $result->title )
109 );
110 }
111
112 $text = $this->languageConverter->convertHtml( $nt->getText() );
113
114 $plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
115 $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
116
117 return $this->getLanguage()->specialList( $plink, $nlinks );
118 }
119
120 protected function getGroupName() {
121 return 'highuse';
122 }
123}
128class_alias( SpecialMostLinkedCategories::class, 'SpecialMostLinkedCategories' );
const NS_CATEGORY
Definition Defines.php:79
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:56
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: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)
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.
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:59
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:39
Result wrapper for grabbing data queried from an IDatabase object.
element(SerializerNode $parent, SerializerNode $node, $contents)