Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 107 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
SpecialProtectedPages | |
0.00% |
0 / 106 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
6 | |||
showOptions | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
2 | |||
getTypeMenu | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
getLevelMenu | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:Protectedpages |
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 HTMLMultiSelectField; |
27 | use HTMLSelectNamespace; |
28 | use HTMLSizeFilterField; |
29 | use MediaWiki\Cache\LinkBatchFactory; |
30 | use MediaWiki\Cache\UserCache; |
31 | use MediaWiki\CommentFormatter\RowCommentFormatter; |
32 | use MediaWiki\CommentStore\CommentStore; |
33 | use MediaWiki\HTMLForm\HTMLForm; |
34 | use MediaWiki\MainConfigNames; |
35 | use MediaWiki\Pager\ProtectedPagesPager; |
36 | use MediaWiki\Permissions\RestrictionStore; |
37 | use MediaWiki\SpecialPage\SpecialPage; |
38 | use Wikimedia\Rdbms\IConnectionProvider; |
39 | |
40 | /** |
41 | * A special page that lists protected pages |
42 | * |
43 | * @ingroup SpecialPage |
44 | */ |
45 | class SpecialProtectedPages extends SpecialPage { |
46 | protected $IdLevel = 'level'; |
47 | protected $IdType = 'type'; |
48 | |
49 | private LinkBatchFactory $linkBatchFactory; |
50 | private IConnectionProvider $dbProvider; |
51 | private CommentStore $commentStore; |
52 | private UserCache $userCache; |
53 | private RowCommentFormatter $rowCommentFormatter; |
54 | private RestrictionStore $restrictionStore; |
55 | |
56 | /** |
57 | * @param LinkBatchFactory $linkBatchFactory |
58 | * @param IConnectionProvider $dbProvider |
59 | * @param CommentStore $commentStore |
60 | * @param UserCache $userCache |
61 | * @param RowCommentFormatter $rowCommentFormatter |
62 | * @param RestrictionStore $restrictionStore |
63 | */ |
64 | public function __construct( |
65 | LinkBatchFactory $linkBatchFactory, |
66 | IConnectionProvider $dbProvider, |
67 | CommentStore $commentStore, |
68 | UserCache $userCache, |
69 | RowCommentFormatter $rowCommentFormatter, |
70 | RestrictionStore $restrictionStore |
71 | ) { |
72 | parent::__construct( 'Protectedpages' ); |
73 | $this->linkBatchFactory = $linkBatchFactory; |
74 | $this->dbProvider = $dbProvider; |
75 | $this->commentStore = $commentStore; |
76 | $this->userCache = $userCache; |
77 | $this->rowCommentFormatter = $rowCommentFormatter; |
78 | $this->restrictionStore = $restrictionStore; |
79 | } |
80 | |
81 | public function execute( $par ) { |
82 | $this->setHeaders(); |
83 | $this->outputHeader(); |
84 | $this->getOutput()->addModuleStyles( 'mediawiki.special' ); |
85 | $this->addHelpLink( 'Help:Protected_pages' ); |
86 | |
87 | $request = $this->getRequest(); |
88 | $type = $request->getVal( $this->IdType ); |
89 | $level = $request->getVal( $this->IdLevel ); |
90 | $sizetype = $request->getVal( 'size-mode' ); |
91 | $size = $request->getIntOrNull( 'size' ); |
92 | $ns = $request->getIntOrNull( 'namespace' ); |
93 | |
94 | $filters = $request->getArray( 'wpfilters', [] ); |
95 | $indefOnly = in_array( 'indefonly', $filters ); |
96 | $cascadeOnly = in_array( 'cascadeonly', $filters ); |
97 | $noRedirect = in_array( 'noredirect', $filters ); |
98 | |
99 | $pager = new ProtectedPagesPager( |
100 | $this->getContext(), |
101 | $this->commentStore, |
102 | $this->linkBatchFactory, |
103 | $this->getLinkRenderer(), |
104 | $this->dbProvider, |
105 | $this->rowCommentFormatter, |
106 | $this->userCache, |
107 | [], |
108 | $type, |
109 | $level, |
110 | $ns, |
111 | $sizetype, |
112 | $size, |
113 | $indefOnly, |
114 | $cascadeOnly, |
115 | $noRedirect |
116 | ); |
117 | |
118 | $this->getOutput()->addHTML( $this->showOptions( |
119 | $type, |
120 | $level, |
121 | $filters |
122 | ) ); |
123 | |
124 | if ( $pager->getNumRows() ) { |
125 | $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' ); |
126 | $this->getOutput()->addParserOutputContent( $pager->getFullOutput() ); |
127 | } else { |
128 | $this->getOutput()->addWikiMsg( 'protectedpagesempty' ); |
129 | } |
130 | } |
131 | |
132 | /** |
133 | * @param string $type Restriction type |
134 | * @param string $level Restriction level |
135 | * @param array $filters Filters set for the pager: indefOnly, |
136 | * cascadeOnly, noRedirect |
137 | * @return string Input form |
138 | */ |
139 | protected function showOptions( $type, $level, $filters ) { |
140 | $formDescriptor = [ |
141 | 'namespace' => [ |
142 | 'class' => HTMLSelectNamespace::class, |
143 | 'name' => 'namespace', |
144 | 'id' => 'namespace', |
145 | 'cssclass' => 'namespaceselector', |
146 | 'all' => '', |
147 | 'label' => $this->msg( 'namespace' )->text(), |
148 | ], |
149 | 'typemenu' => $this->getTypeMenu( $type ), |
150 | 'levelmenu' => $this->getLevelMenu( $level ), |
151 | 'filters' => [ |
152 | 'class' => HTMLMultiSelectField::class, |
153 | 'label' => $this->msg( 'protectedpages-filters' )->text(), |
154 | 'flatlist' => true, |
155 | 'options-messages' => [ |
156 | 'protectedpages-indef' => 'indefonly', |
157 | 'protectedpages-cascade' => 'cascadeonly', |
158 | 'protectedpages-noredirect' => 'noredirect', |
159 | ], |
160 | 'default' => $filters, |
161 | ], |
162 | 'sizelimit' => [ |
163 | 'class' => HTMLSizeFilterField::class, |
164 | 'name' => 'size', |
165 | ] |
166 | ]; |
167 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
168 | ->setMethod( 'get' ) |
169 | ->setWrapperLegendMsg( 'protectedpages' ) |
170 | ->setSubmitTextMsg( 'protectedpages-submit' ); |
171 | |
172 | return $htmlForm->prepareForm()->getHTML( false ); |
173 | } |
174 | |
175 | /** |
176 | * Creates the input label of the restriction type |
177 | * @param string $pr_type Protection type |
178 | * @return array |
179 | */ |
180 | protected function getTypeMenu( $pr_type ) { |
181 | $m = []; // Temporary array |
182 | $options = []; |
183 | |
184 | // First pass to load the log names |
185 | foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) { |
186 | // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload |
187 | $text = $this->msg( "restriction-$type" )->text(); |
188 | $m[$text] = $type; |
189 | } |
190 | |
191 | // Third pass generates sorted XHTML content |
192 | foreach ( $m as $text => $type ) { |
193 | $options[$text] = $type; |
194 | } |
195 | |
196 | return [ |
197 | 'type' => 'select', |
198 | 'options' => $options, |
199 | 'label' => $this->msg( 'restriction-type' )->text(), |
200 | 'name' => $this->IdType, |
201 | 'id' => $this->IdType, |
202 | ]; |
203 | } |
204 | |
205 | /** |
206 | * Creates the input label of the restriction level |
207 | * @param string $pr_level Protection level |
208 | * @return array |
209 | */ |
210 | protected function getLevelMenu( $pr_level ) { |
211 | $options = [ 'restriction-level-all' => 0 ]; |
212 | |
213 | // Load the log names as options |
214 | foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) { |
215 | if ( $type != '' && $type != '*' ) { |
216 | // Messages: restriction-level-sysop, restriction-level-autoconfirmed |
217 | $options["restriction-level-$type"] = $type; |
218 | } |
219 | } |
220 | |
221 | return [ |
222 | 'type' => 'select', |
223 | 'options-messages' => $options, |
224 | 'label-message' => 'restriction-level', |
225 | 'name' => $this->IdLevel, |
226 | 'id' => $this->IdLevel |
227 | ]; |
228 | } |
229 | |
230 | protected function getGroupName() { |
231 | return 'maintenance'; |
232 | } |
233 | } |
234 | |
235 | /** |
236 | * Retain the old class name for backwards compatibility. |
237 | * @deprecated since 1.41 |
238 | */ |
239 | class_alias( SpecialProtectedPages::class, 'SpecialProtectedpages' ); |