Debian Codegraph @

includes/specials/SpecialMostLinkedCategories.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 HtmlArmor;
26 use MediaWiki\Cache\LinkBatchFactory;
27 use MediaWiki\Html\Html;
28 use MediaWiki\Language\ILanguageConverter;
29 use MediaWiki\Languages\LanguageConverterFactory;
30 use MediaWiki\Linker\Linker;
31 use MediaWiki\SpecialPage\QueryPage;
32 use MediaWiki\Title\Title;
33 use Skin;
34 use stdClass;
35 use Wikimedia\Rdbms\IConnectionProvider;
36 use Wikimedia\Rdbms\IDatabase;
37 use Wikimedia\Rdbms\IResultWrapper;
38
39 /**
40 * List of categories with the most pages in them
41 *
42 * @ingroup SpecialPage
43 * @author Ævar Arnfjörð Bjarmason <[email protected]om>
44 */
45 class SpecialMostLinkedCategories extends QueryPage {
46
47 private ILanguageConverter $languageConverter;
48
49 /**
50 * @param IConnectionProvider $dbProvider
51 * @param LinkBatchFactory $linkBatchFactory
52 * @param LanguageConverterFactory $languageConverterFactory
53 */
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
84 /**
85 * Fetch user page links and cache their existence
86 *
87 * @param IDatabase $db
88 * @param IResultWrapper $res
89 */
90 public function preprocessResults( $db, $res ) {
91 $this->executeLBFromResultWrapper( $res );
92 }
93
94 /**
95 * @param Skin $skin
96 * @param stdClass $result Result row
97 * @return string
98 */
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(),
107 NS_CATEGORY,
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 }
124 /**
125 * Retain the old class name for backwards compatibility.
126 * @deprecated since 1.41
127 */
128 class_alias( SpecialMostLinkedCategories::class, 'SpecialMostLinkedCategories' );