Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
18.18% |
6 / 33 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
SpecialUncategorizedCategories | |
18.75% |
6 / 32 |
|
25.00% |
1 / 4 |
75.90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getExceptionList | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
56 | |||
getQueryInfo | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Uncategorizedcategories |
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 | * @ingroup SpecialPage |
22 | */ |
23 | |
24 | namespace MediaWiki\Specials; |
25 | |
26 | use MediaWiki\Cache\LinkBatchFactory; |
27 | use MediaWiki\Languages\LanguageConverterFactory; |
28 | use MediaWiki\Title\NamespaceInfo; |
29 | use MediaWiki\Title\Title; |
30 | use Skin; |
31 | use stdClass; |
32 | use Wikimedia\Rdbms\IConnectionProvider; |
33 | |
34 | /** |
35 | * A special page that lists uncategorized categories |
36 | * |
37 | * @ingroup SpecialPage |
38 | */ |
39 | class SpecialUncategorizedCategories extends SpecialUncategorizedPages { |
40 | /** |
41 | * Holds a list of categories, which shouldn't be listed on this special page, |
42 | * even if it is uncategorized. |
43 | * @var array |
44 | */ |
45 | private $exceptionList = null; |
46 | |
47 | /** |
48 | * @param NamespaceInfo $namespaceInfo |
49 | * @param IConnectionProvider $dbProvider |
50 | * @param LinkBatchFactory $linkBatchFactory |
51 | * @param LanguageConverterFactory $languageConverterFactory |
52 | */ |
53 | public function __construct( |
54 | NamespaceInfo $namespaceInfo, |
55 | IConnectionProvider $dbProvider, |
56 | LinkBatchFactory $linkBatchFactory, |
57 | LanguageConverterFactory $languageConverterFactory |
58 | ) { |
59 | parent::__construct( |
60 | $namespaceInfo, |
61 | $dbProvider, |
62 | $linkBatchFactory, |
63 | $languageConverterFactory |
64 | ); |
65 | $this->mName = 'Uncategorizedcategories'; |
66 | $this->requestedNamespace = NS_CATEGORY; |
67 | } |
68 | |
69 | /** |
70 | * Returns an array of category titles (usually without the namespace), which |
71 | * shouldn't be listed on this page, even if they're uncategorized. |
72 | * |
73 | * @return array |
74 | */ |
75 | private function getExceptionList() { |
76 | if ( $this->exceptionList === null ) { |
77 | $this->exceptionList = []; |
78 | $exList = $this->msg( 'uncategorized-categories-exceptionlist' ) |
79 | ->inContentLanguage()->plain(); |
80 | $proposedTitles = explode( "\n", $exList ); |
81 | foreach ( $proposedTitles as $titleStr ) { |
82 | if ( !str_starts_with( $titleStr, '*' ) ) { |
83 | continue; |
84 | } |
85 | $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr ); |
86 | $title = Title::newFromText( $titleStr, NS_CATEGORY ); |
87 | if ( $title && $title->getNamespace() !== NS_CATEGORY ) { |
88 | $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr ); |
89 | } |
90 | if ( $title ) { |
91 | $this->exceptionList[] = $title->getDBkey(); |
92 | } |
93 | } |
94 | } |
95 | return $this->exceptionList; |
96 | } |
97 | |
98 | public function getQueryInfo() { |
99 | $query = parent::getQueryInfo(); |
100 | $exceptionList = $this->getExceptionList(); |
101 | if ( $exceptionList ) { |
102 | $dbr = $this->getDatabaseProvider()->getReplicaDatabase(); |
103 | $query['conds'][] = $dbr->expr( 'page_title', '!=', $exceptionList ); |
104 | } |
105 | |
106 | return $query; |
107 | } |
108 | |
109 | /** |
110 | * Formats the result |
111 | * @param Skin $skin The current skin |
112 | * @param stdClass $result The query result |
113 | * @return string The category link |
114 | */ |
115 | public function formatResult( $skin, $result ) { |
116 | $title = Title::makeTitle( NS_CATEGORY, $result->title ); |
117 | $text = $title->getText(); |
118 | |
119 | return $this->getLinkRenderer()->makeKnownLink( $title, $text ); |
120 | } |
121 | } |
122 | |
123 | /** |
124 | * Retain the old class name for backwards compatibility. |
125 | * @deprecated since 1.41 |
126 | */ |
127 | class_alias( SpecialUncategorizedCategories::class, 'SpecialUncategorizedCategories' ); |