MediaWiki REL1_39
SpecialProtectedpages.php
Go to the documentation of this file.
1<?php
29
36 protected $IdLevel = 'level';
37 protected $IdType = 'type';
38
40 private $linkBatchFactory;
41
43 private $loadBalancer;
44
46 private $commentStore;
47
49 private $userCache;
50
52 private $rowCommentFormatter;
53
55 private $restrictionStore;
56
65 public function __construct(
66 LinkBatchFactory $linkBatchFactory,
67 ILoadBalancer $loadBalancer,
68 CommentStore $commentStore,
69 UserCache $userCache,
70 RowCommentFormatter $rowCommentFormatter,
71 RestrictionStore $restrictionStore
72 ) {
73 parent::__construct( 'Protectedpages' );
74 $this->linkBatchFactory = $linkBatchFactory;
75 $this->loadBalancer = $loadBalancer;
76 $this->commentStore = $commentStore;
77 $this->userCache = $userCache;
78 $this->rowCommentFormatter = $rowCommentFormatter;
79 $this->restrictionStore = $restrictionStore;
80 }
81
82 public function execute( $par ) {
83 $this->setHeaders();
84 $this->outputHeader();
85 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
86 $this->addHelpLink( 'Help:Protected_pages' );
87
88 $request = $this->getRequest();
89 $type = $request->getVal( $this->IdType );
90 $level = $request->getVal( $this->IdLevel );
91 $sizetype = $request->getVal( 'size-mode' );
92 $size = $request->getIntOrNull( 'size' );
93 $ns = $request->getIntOrNull( 'namespace' );
94
95 $filters = $request->getArray( 'wpfilters', [] );
96 $indefOnly = in_array( 'indefonly', $filters );
97 $cascadeOnly = in_array( 'cascadeonly', $filters );
98 $noRedirect = in_array( 'noredirect', $filters );
99
100 $pager = new ProtectedPagesPager(
101 $this->getContext(),
102 $this->commentStore,
103 $this->linkBatchFactory,
104 $this->getLinkRenderer(),
105 $this->loadBalancer,
106 $this->rowCommentFormatter,
107 $this->userCache,
108 [],
109 $type,
110 $level,
111 $ns,
112 $sizetype,
113 $size,
114 $indefOnly,
115 $cascadeOnly,
116 $noRedirect
117 );
118
119 $this->getOutput()->addHTML( $this->showOptions(
120 $ns,
121 $type,
122 $level,
123 $sizetype,
124 $size,
125 $filters
126 ) );
127
128 if ( $pager->getNumRows() ) {
129 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
130 } else {
131 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
132 }
133 }
134
145 protected function showOptions( $namespace, $type, $level, $sizetype,
146 $size, $filters
147 ) {
148 $formDescriptor = [
149 'namespace' => [
150 'class' => HTMLSelectNamespace::class,
151 'name' => 'namespace',
152 'id' => 'namespace',
153 'cssclass' => 'namespaceselector',
154 'all' => '',
155 'label' => $this->msg( 'namespace' )->text(),
156 ],
157 'typemenu' => $this->getTypeMenu( $type ),
158 'levelmenu' => $this->getLevelMenu( $level ),
159 'filters' => [
160 'class' => HTMLMultiSelectField::class,
161 'label' => $this->msg( 'protectedpages-filters' )->text(),
162 'flatlist' => true,
163 'options-messages' => [
164 'protectedpages-indef' => 'indefonly',
165 'protectedpages-cascade' => 'cascadeonly',
166 'protectedpages-noredirect' => 'noredirect',
167 ],
168 'default' => $filters,
169 ],
170 'sizelimit' => [
171 'class' => HTMLSizeFilterField::class,
172 'name' => 'size',
173 ]
174 ];
175 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
176 ->setMethod( 'get' )
177 ->setWrapperLegendMsg( 'protectedpages' )
178 ->setSubmitTextMsg( 'protectedpages-submit' );
179
180 return $htmlForm->prepareForm()->getHTML( false );
181 }
182
188 protected function getTypeMenu( $pr_type ) {
189 $m = []; // Temporary array
190 $options = [];
191
192 // First pass to load the log names
193 foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
194 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
195 $text = $this->msg( "restriction-$type" )->text();
196 $m[$text] = $type;
197 }
198
199 // Third pass generates sorted XHTML content
200 foreach ( $m as $text => $type ) {
201 $options[$text] = $type;
202 }
203
204 return [
205 'type' => 'select',
206 'options' => $options,
207 'label' => $this->msg( 'restriction-type' )->text(),
208 'name' => $this->IdType,
209 'id' => $this->IdType,
210 ];
211 }
212
218 protected function getLevelMenu( $pr_level ) {
219 // Temporary array
220 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
221 $options = [];
222
223 // First pass to load the log names
224 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
225 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
226 if ( $type != '' && $type != '*' ) {
227 $text = $this->msg( "restriction-level-$type" )->text();
228 $m[$text] = $type;
229 }
230 }
231
232 // Third pass generates sorted XHTML content
233 foreach ( $m as $text => $type ) {
234 $options[$text] = $type;
235 }
236
237 return [
238 'type' => 'select',
239 'options' => $options,
240 'label' => $this->msg( 'restriction-level' )->text(),
241 'name' => $this->IdLevel,
242 'id' => $this->IdLevel
243 ];
244 }
245
246 protected function getGroupName() {
247 return 'maintenance';
248 }
249}
Handle database storage of comments such as edit summaries and log reasons.
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
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.
Create and track the database connections and transactions for a given database cluster.