MediaWiki  master
SpecialMostLinkedCategories.php
Go to the documentation of this file.
1 <?php
27 namespace MediaWiki\Specials;
28 
29 use HtmlArmor;
36 use QueryPage;
37 use Skin;
38 use stdClass;
42 
49 
51  private $languageConverter;
52 
58  public function __construct(
59  IConnectionProvider $dbProvider,
60  LinkBatchFactory $linkBatchFactory,
61  LanguageConverterFactory $languageConverterFactory
62  ) {
63  parent::__construct( 'Mostlinkedcategories' );
64  $this->setDatabaseProvider( $dbProvider );
65  $this->setLinkBatchFactory( $linkBatchFactory );
66  $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
67  }
68 
69  public function isSyndicated() {
70  return false;
71  }
72 
73  public function getQueryInfo() {
74  return [
75  'tables' => [ 'category' ],
76  'fields' => [ 'title' => 'cat_title',
77  'namespace' => NS_CATEGORY,
78  'value' => 'cat_pages' ],
79  'conds' => [ 'cat_pages > 0' ],
80  ];
81  }
82 
83  protected function sortDescending() {
84  return true;
85  }
86 
93  public function preprocessResults( $db, $res ) {
95  }
96 
102  public function formatResult( $skin, $result ) {
103  $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
104  if ( !$nt ) {
105  return Html::element(
106  'span',
107  [ 'class' => 'mw-invalidtitle' ],
109  $this->getContext(),
110  NS_CATEGORY,
111  $result->title )
112  );
113  }
114 
115  $text = $this->languageConverter->convertHtml( $nt->getText() );
116 
117  $plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
118  $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
119 
120  return $this->getLanguage()->specialList( $plink, $nlinks );
121  }
122 
123  protected function getGroupName() {
124  return 'highuse';
125  }
126 }
131 class_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:55
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:240
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:67
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:225
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:82
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:719
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:65
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition: QueryPage.php:964
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:925
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:162
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:57
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.
getContentLanguage()
Shortcut to get content language.
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.