Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 56 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialProtectedTitles | |
0.00% |
0 / 55 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
showOptions | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
getLevelMenu | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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\HTMLForm\Field\HTMLSelectNamespace; |
25 | use MediaWiki\HTMLForm\HTMLForm; |
26 | use MediaWiki\MainConfigNames; |
27 | use MediaWiki\Pager\ProtectedTitlesPager; |
28 | use MediaWiki\SpecialPage\SpecialPage; |
29 | use Wikimedia\Rdbms\IConnectionProvider; |
30 | |
31 | /** |
32 | * A special page that list protected titles from creation |
33 | * |
34 | * @ingroup SpecialPage |
35 | */ |
36 | class SpecialProtectedTitles extends SpecialPage { |
37 | |
38 | private LinkBatchFactory $linkBatchFactory; |
39 | private IConnectionProvider $dbProvider; |
40 | |
41 | public function __construct( |
42 | LinkBatchFactory $linkBatchFactory, |
43 | IConnectionProvider $dbProvider |
44 | ) { |
45 | parent::__construct( 'Protectedtitles' ); |
46 | $this->linkBatchFactory = $linkBatchFactory; |
47 | $this->dbProvider = $dbProvider; |
48 | } |
49 | |
50 | public function execute( $par ) { |
51 | $this->setHeaders(); |
52 | $this->outputHeader(); |
53 | $this->addHelpLink( 'Help:Protected_pages' ); |
54 | |
55 | $request = $this->getRequest(); |
56 | $level = $request->getVal( 'level' ); |
57 | $NS = $request->getIntOrNull( 'namespace' ); |
58 | |
59 | $pager = new ProtectedTitlesPager( |
60 | $this->getContext(), |
61 | $this->getLinkRenderer(), |
62 | $this->linkBatchFactory, |
63 | $this->dbProvider, |
64 | $level, |
65 | $NS |
66 | ); |
67 | |
68 | $this->getOutput()->addHTML( $this->showOptions() ); |
69 | |
70 | if ( $pager->getNumRows() ) { |
71 | $this->getOutput()->addHTML( |
72 | $pager->getNavigationBar() . |
73 | '<ul>' . $pager->getBody() . '</ul>' . |
74 | $pager->getNavigationBar() |
75 | ); |
76 | } else { |
77 | $this->getOutput()->addWikiMsg( 'protectedtitlesempty' ); |
78 | } |
79 | } |
80 | |
81 | /** |
82 | * @return string |
83 | */ |
84 | private function showOptions() { |
85 | $formDescriptor = [ |
86 | 'namespace' => [ |
87 | 'class' => HTMLSelectNamespace::class, |
88 | 'name' => 'namespace', |
89 | 'id' => 'namespace', |
90 | 'cssclass' => 'namespaceselector', |
91 | 'all' => '', |
92 | 'label' => $this->msg( 'namespace' )->text() |
93 | ], |
94 | 'levelmenu' => $this->getLevelMenu() |
95 | ]; |
96 | |
97 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
98 | ->setMethod( 'get' ) |
99 | ->setWrapperLegendMsg( 'protectedtitles' ) |
100 | ->setSubmitTextMsg( 'protectedtitles-submit' ); |
101 | |
102 | return $htmlForm->prepareForm()->getHTML( false ); |
103 | } |
104 | |
105 | /** |
106 | * @return string|array |
107 | */ |
108 | private function getLevelMenu() { |
109 | $options = [ 'restriction-level-all' => 0 ]; |
110 | |
111 | // Load the log names as options |
112 | foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) { |
113 | if ( $type != '' && $type != '*' ) { |
114 | // Messages: restriction-level-sysop, restriction-level-autoconfirmed |
115 | $options["restriction-level-$type"] = $type; |
116 | } |
117 | } |
118 | |
119 | // Is there only one level (aside from "all")? |
120 | if ( count( $options ) <= 2 ) { |
121 | return ''; |
122 | } |
123 | |
124 | return [ |
125 | 'type' => 'select', |
126 | 'options-messages' => $options, |
127 | 'label-message' => 'restriction-level', |
128 | 'name' => 'level', |
129 | 'id' => 'level', |
130 | ]; |
131 | } |
132 | |
133 | protected function getGroupName() { |
134 | return 'maintenance'; |
135 | } |
136 | } |
137 | |
138 | /** |
139 | * Retain the old class name for backwards compatibility. |
140 | * @deprecated since 1.41 |
141 | */ |
142 | class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' ); |