Debian Codegraph @

includes/specials/SpecialMostCategories.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2005 Ævar Arnfjörð Bjarmason
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Specials;
24
25 use MediaWiki\Cache\LinkBatchFactory;
26 use MediaWiki\Html\Html;
27 use MediaWiki\Linker\Linker;
28 use MediaWiki\SpecialPage\QueryPage;
29 use MediaWiki\Title\NamespaceInfo;
30 use MediaWiki\Title\Title;
31 use Skin;
32 use stdClass;
33 use Wikimedia\Rdbms\IConnectionProvider;
34 use Wikimedia\Rdbms\IDatabase;
35 use Wikimedia\Rdbms\IResultWrapper;
36
37 /**
38 * List of pages that have the highest category count.
39 *
40 * @ingroup SpecialPage
41 * @author Ævar Arnfjörð Bjarmason <[email protected]om>
42 */
43 class SpecialMostCategories extends QueryPage {
44
45 private NamespaceInfo $namespaceInfo;
46
47 /**
48 * @param NamespaceInfo $namespaceInfo
49 * @param IConnectionProvider $dbProvider
50 * @param LinkBatchFactory $linkBatchFactory
51 */
52 public function __construct(
53 NamespaceInfo $namespaceInfo,
54 IConnectionProvider $dbProvider,
55 LinkBatchFactory $linkBatchFactory
56 ) {
57 parent::__construct( 'Mostcategories' );
58 $this->namespaceInfo = $namespaceInfo;
59 $this->setDatabaseProvider( $dbProvider );
60 $this->setLinkBatchFactory( $linkBatchFactory );
61 }
62
63 public function isExpensive() {
64 return true;
65 }
66
67 public function isSyndicated() {
68 return false;
69 }
70
71 public function getQueryInfo() {
72 return [
73 'tables' => [ 'categorylinks', 'page' ],
74 'fields' => [
75 'namespace' => 'page_namespace',
76 'title' => 'page_title',
77 'value' => 'COUNT(*)'
78 ],
79 'conds' => [
80 'page_namespace' => $this->namespaceInfo->getContentNamespaces()
81 ],
82 'options' => [
83 'HAVING' => 'COUNT(*) > 1',
84 'GROUP BY' => [ 'page_namespace', 'page_title' ]
85 ],
86 'join_conds' => [
87 'page' => [
88 'LEFT JOIN',
89 'page_id = cl_from'
90 ]
91 ]
92 ];
93 }
94
95 /**
96 * @param IDatabase $db
97 * @param IResultWrapper $res
98 */
99 public function preprocessResults( $db, $res ) {
100 $this->executeLBFromResultWrapper( $res );
101 }
102
103 /**
104 * @param Skin $skin
105 * @param stdClass $result Result row
106 * @return string
107 */
108 public function formatResult( $skin, $result ) {
109 $title = Title::makeTitleSafe( $result->namespace, $result->title );
110 if ( !$title ) {
111 return Html::element(
112 'span',
113 [ 'class' => 'mw-invalidtitle' ],
114 Linker::getInvalidTitleDescription(
115 $this->getContext(),
116 $result->namespace,
117 $result->title
118 )
119 );
120 }
121
122 $linkRenderer = $this->getLinkRenderer();
123 if ( $this->isCached() ) {
124 $link = $linkRenderer->makeLink( $title );
125 } else {
126 $link = $linkRenderer->makeKnownLink( $title );
127 }
128
129 $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
130
131 return $this->getLanguage()->specialList( $link, $count );
132 }
133
134 protected function getGroupName() {
135 return 'highuse';
136 }
137 }
138
139 /**
140 * Retain the old class name for backwards compatibility.
141 * @deprecated since 1.41
142 */
143 class_alias( SpecialMostCategories::class, 'SpecialMostCategories' );