MediaWiki 1.40.4
SpecialProtectedpages.php
Go to the documentation of this file.
1<?php
30
37 protected $IdLevel = 'level';
38 protected $IdType = 'type';
39
41 private $linkBatchFactory;
42
44 private $loadBalancer;
45
47 private $commentStore;
48
50 private $userCache;
51
53 private $rowCommentFormatter;
54
56 private $restrictionStore;
57
66 public function __construct(
67 LinkBatchFactory $linkBatchFactory,
68 ILoadBalancer $loadBalancer,
69 CommentStore $commentStore,
70 UserCache $userCache,
71 RowCommentFormatter $rowCommentFormatter,
72 RestrictionStore $restrictionStore
73 ) {
74 parent::__construct( 'Protectedpages' );
75 $this->linkBatchFactory = $linkBatchFactory;
76 $this->loadBalancer = $loadBalancer;
77 $this->commentStore = $commentStore;
78 $this->userCache = $userCache;
79 $this->rowCommentFormatter = $rowCommentFormatter;
80 $this->restrictionStore = $restrictionStore;
81 }
82
83 public function execute( $par ) {
84 $this->setHeaders();
85 $this->outputHeader();
86 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
87 $this->addHelpLink( 'Help:Protected_pages' );
88
89 $request = $this->getRequest();
90 $type = $request->getVal( $this->IdType );
91 $level = $request->getVal( $this->IdLevel );
92 $sizetype = $request->getVal( 'size-mode' );
93 $size = $request->getIntOrNull( 'size' );
94 $ns = $request->getIntOrNull( 'namespace' );
95
96 $filters = $request->getArray( 'wpfilters', [] );
97 $indefOnly = in_array( 'indefonly', $filters );
98 $cascadeOnly = in_array( 'cascadeonly', $filters );
99 $noRedirect = in_array( 'noredirect', $filters );
100
101 $pager = new ProtectedPagesPager(
102 $this->getContext(),
103 $this->commentStore,
104 $this->linkBatchFactory,
105 $this->getLinkRenderer(),
106 $this->loadBalancer,
107 $this->rowCommentFormatter,
108 $this->userCache,
109 [],
110 $type,
111 $level,
112 $ns,
113 $sizetype,
114 $size,
115 $indefOnly,
116 $cascadeOnly,
117 $noRedirect
118 );
119
120 $this->getOutput()->addHTML( $this->showOptions(
121 $ns,
122 $type,
123 $level,
124 $sizetype,
125 $size,
126 $filters
127 ) );
128
129 if ( $pager->getNumRows() ) {
130 $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
131 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
132 } else {
133 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
134 }
135 }
136
147 protected function showOptions( $namespace, $type, $level, $sizetype,
148 $size, $filters
149 ) {
150 $formDescriptor = [
151 'namespace' => [
152 'class' => HTMLSelectNamespace::class,
153 'name' => 'namespace',
154 'id' => 'namespace',
155 'cssclass' => 'namespaceselector',
156 'all' => '',
157 'label' => $this->msg( 'namespace' )->text(),
158 ],
159 'typemenu' => $this->getTypeMenu( $type ),
160 'levelmenu' => $this->getLevelMenu( $level ),
161 'filters' => [
162 'class' => HTMLMultiSelectField::class,
163 'label' => $this->msg( 'protectedpages-filters' )->text(),
164 'flatlist' => true,
165 'options-messages' => [
166 'protectedpages-indef' => 'indefonly',
167 'protectedpages-cascade' => 'cascadeonly',
168 'protectedpages-noredirect' => 'noredirect',
169 ],
170 'default' => $filters,
171 ],
172 'sizelimit' => [
173 'class' => HTMLSizeFilterField::class,
174 'name' => 'size',
175 ]
176 ];
177 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
178 ->setMethod( 'get' )
179 ->setWrapperLegendMsg( 'protectedpages' )
180 ->setSubmitTextMsg( 'protectedpages-submit' );
181
182 return $htmlForm->prepareForm()->getHTML( false );
183 }
184
190 protected function getTypeMenu( $pr_type ) {
191 $m = []; // Temporary array
192 $options = [];
193
194 // First pass to load the log names
195 foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
196 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
197 $text = $this->msg( "restriction-$type" )->text();
198 $m[$text] = $type;
199 }
200
201 // Third pass generates sorted XHTML content
202 foreach ( $m as $text => $type ) {
203 $options[$text] = $type;
204 }
205
206 return [
207 'type' => 'select',
208 'options' => $options,
209 'label' => $this->msg( 'restriction-type' )->text(),
210 'name' => $this->IdType,
211 'id' => $this->IdType,
212 ];
213 }
214
220 protected function getLevelMenu( $pr_level ) {
221 // Temporary array
222 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
223 $options = [];
224
225 // First pass to load the log names
226 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
227 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
228 if ( $type != '' && $type != '*' ) {
229 $text = $this->msg( "restriction-level-$type" )->text();
230 $m[$text] = $type;
231 }
232 }
233
234 // Third pass generates sorted XHTML content
235 foreach ( $m as $text => $type ) {
236 $options[$text] = $type;
237 }
238
239 return [
240 'type' => 'select',
241 'options' => $options,
242 'label' => $this->msg( 'restriction-level' )->text(),
243 'name' => $this->IdLevel,
244 'id' => $this->IdLevel
245 ];
246 }
247
248 protected function getGroupName() {
249 return 'maintenance';
250 }
251}
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.
A class containing constants representing the names of configuration variables.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists protected pages.
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, CommentStore $commentStore, UserCache $userCache, RowCommentFormatter $rowCommentFormatter, RestrictionStore $restrictionStore)
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...
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
execute( $par)
Default execute method Checks user permissions.
This class is a delegate to ILBFactory for a given database cluster.