Debian Codegraph @

includes/specials/SpecialUncategorizedCategories.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\Languages\LanguageConverterFactory;
25 use MediaWiki\Title\NamespaceInfo;
26 use MediaWiki\Title\Title;
27 use Skin;
28 use stdClass;
29 use Wikimedia\Rdbms\IConnectionProvider;
30
31 /**
32 * List of uncategorized category pages.
33 *
34 * @ingroup SpecialPage
35 */
36 class SpecialUncategorizedCategories extends SpecialUncategorizedPages {
37 /**
38 * Holds a list of categories, which shouldn't be listed on this special page,
39 * even if it is uncategorized.
40 * @var array
41 */
42 private $exceptionList = null;
43
44 /**
45 * @param NamespaceInfo $namespaceInfo
46 * @param IConnectionProvider $dbProvider
47 * @param LinkBatchFactory $linkBatchFactory
48 * @param LanguageConverterFactory $languageConverterFactory
49 */
50 public function __construct(
51 NamespaceInfo $namespaceInfo,
52 IConnectionProvider $dbProvider,
53 LinkBatchFactory $linkBatchFactory,
54 LanguageConverterFactory $languageConverterFactory
55 ) {
56 parent::__construct(
57 $namespaceInfo,
58 $dbProvider,
59 $linkBatchFactory,
60 $languageConverterFactory
61 );
62 $this->mName = 'Uncategorizedcategories';
63 $this->requestedNamespace = NS_CATEGORY;
64 }
65
66 /**
67 * Returns an array of category titles (usually without the namespace), which
68 * shouldn't be listed on this page, even if they're uncategorized.
69 *
70 * @return array
71 */
72 private function getExceptionList() {
73 if ( $this->exceptionList === null ) {
74 $this->exceptionList = [];
75 $exList = $this->msg( 'uncategorized-categories-exceptionlist' )
76 ->inContentLanguage()->plain();
77 $proposedTitles = explode( "\n", $exList );
78 foreach ( $proposedTitles as $titleStr ) {
79 if ( !str_starts_with( $titleStr, '*' ) ) {
80 continue;
81 }
82 $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr );
83 $title = Title::newFromText( $titleStr, NS_CATEGORY );
84 if ( $title && $title->getNamespace() !== NS_CATEGORY ) {
85 $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr );
86 }
87 if ( $title ) {
88 $this->exceptionList[] = $title->getDBkey();
89 }
90 }
91 }
92 return $this->exceptionList;
93 }
94
95 public function getQueryInfo() {
96 $query = parent::getQueryInfo();
97 $exceptionList = $this->getExceptionList();
98 if ( $exceptionList ) {
99 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
100 $query['conds'][] = $dbr->expr( 'page_title', '!=', $exceptionList );
101 }
102
103 return $query;
104 }
105
106 /**
107 * Formats the result
108 * @param Skin $skin The current skin
109 * @param stdClass $result The query result
110 * @return string The category link
111 */
112 public function formatResult( $skin, $result ) {
113 $title = Title::makeTitle( NS_CATEGORY, $result->title );
114 $text = $title->getText();
115
116 return $this->getLinkRenderer()->makeKnownLink( $title, $text );
117 }
118 }
119
120 /**
121 * Retain the old class name for backwards compatibility.
122 * @deprecated since 1.41
123 */
124 class_alias( SpecialUncategorizedCategories::class, 'SpecialUncategorizedCategories' );