MediaWiki  master
SpecialMostCategories.php
Go to the documentation of this file.
1 <?php
31 
38 
40  private $namespaceInfo;
41 
47  public function __construct(
51  ) {
52  parent::__construct( 'Mostcategories' );
53  $this->namespaceInfo = $namespaceInfo;
54  $this->setDBLoadBalancer( $loadBalancer );
55  $this->setLinkBatchFactory( $linkBatchFactory );
56  }
57 
58  public function isExpensive() {
59  return true;
60  }
61 
62  public function isSyndicated() {
63  return false;
64  }
65 
66  public function getQueryInfo() {
67  return [
68  'tables' => [ 'categorylinks', 'page' ],
69  'fields' => [
70  'namespace' => 'page_namespace',
71  'title' => 'page_title',
72  'value' => 'COUNT(*)'
73  ],
74  'conds' => [
75  'page_namespace' => $this->namespaceInfo->getContentNamespaces()
76  ],
77  'options' => [
78  'HAVING' => 'COUNT(*) > 1',
79  'GROUP BY' => [ 'page_namespace', 'page_title' ]
80  ],
81  'join_conds' => [
82  'page' => [
83  'LEFT JOIN',
84  'page_id = cl_from'
85  ]
86  ]
87  ];
88  }
89 
94  public function preprocessResults( $db, $res ) {
96  }
97 
103  public function formatResult( $skin, $result ) {
104  $title = Title::makeTitleSafe( $result->namespace, $result->title );
105  if ( !$title ) {
106  return Html::element(
107  'span',
108  [ 'class' => 'mw-invalidtitle' ],
110  $this->getContext(),
111  $result->namespace,
112  $result->title
113  )
114  );
115  }
116 
117  $linkRenderer = $this->getLinkRenderer();
118  if ( $this->isCached() ) {
119  $link = $linkRenderer->makeLink( $title );
120  } else {
121  $link = $linkRenderer->makeKnownLink( $title );
122  }
123 
124  $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
125 
126  return $this->getLanguage()->specialList( $link, $count );
127  }
128 
129  protected function getGroupName() {
130  return 'highuse';
131  }
132 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialMostCategories\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialMostCategories.php:66
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:185
$res
$res
Definition: testCompression.php:57
SpecialMostCategories
A special page that list pages that have highest category count.
Definition: SpecialMostCategories.php:37
QueryPage
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:41
QueryPage\executeLBFromResultWrapper
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:874
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:135
SpecialMostCategories\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialMostCategories.php:129
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
QueryPage\isCached
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:297
SpecialMostCategories\formatResult
formatResult( $skin, $result)
Definition: SpecialMostCategories.php:103
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialMostCategories\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialMostCategories.php:40
SpecialMostCategories\isSyndicated
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
Definition: SpecialMostCategories.php:62
$title
$title
Definition: testCompression.php:38
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:689
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialMostCategories\__construct
__construct(NamespaceInfo $namespaceInfo, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
Definition: SpecialMostCategories.php:47
SpecialMostCategories\preprocessResults
preprocessResults( $db, $res)
Definition: SpecialMostCategories.php:94
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
SpecialMostCategories\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialMostCategories.php:58
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81