Debian Codegraph @

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