MediaWiki master
SpecialProtectedPages.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
26use HTMLMultiSelectField;
27use HTMLSelectNamespace;
28use HTMLSizeFilterField;
37use UserCache;
39
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
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
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
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
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
239class_alias( SpecialProtectedPages::class, 'SpecialProtectedpages' );
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Handle database storage of comments such as edit summaries and log reasons.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
A class containing constants representing the names of configuration variables.
const RestrictionLevels
Name constant for the RestrictionLevels setting, for use with Config::get()
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists protected pages.
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
getLevelMenu( $pr_level)
Creates the input label of the restriction level.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, CommentStore $commentStore, UserCache $userCache, RowCommentFormatter $rowCommentFormatter, RestrictionStore $restrictionStore)
execute( $par)
Default execute method Checks user permissions.
Provide primary and replica IDatabase connections.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...