MediaWiki REL1_37
SpecialProtectedpages.php
Go to the documentation of this file.
1<?php
26
33 protected $IdLevel = 'level';
34 protected $IdType = 'type';
35
38
41
44
46 private $userCache;
47
54 public function __construct(
59 ) {
60 parent::__construct( 'Protectedpages' );
61 $this->linkBatchFactory = $linkBatchFactory;
62 $this->loadBalancer = $loadBalancer;
63 $this->commentStore = $commentStore;
64 $this->userCache = $userCache;
65 }
66
67 public function execute( $par ) {
68 $this->setHeaders();
69 $this->outputHeader();
70 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
71 $this->addHelpLink( 'Help:Protected_pages' );
72
73 $request = $this->getRequest();
74 $type = $request->getVal( $this->IdType );
75 $level = $request->getVal( $this->IdLevel );
76 $sizetype = $request->getVal( 'size-mode' );
77 $size = $request->getIntOrNull( 'size' );
78 $ns = $request->getIntOrNull( 'namespace' );
79
80 $filters = $request->getArray( 'wpfilters', [] );
81 $indefOnly = in_array( 'indefonly', $filters );
82 $cascadeOnly = in_array( 'cascadeonly', $filters );
83 $noRedirect = in_array( 'noredirect', $filters );
84
85 $pager = new ProtectedPagesPager(
86 $this,
87 [],
88 $type,
89 $level,
90 $ns,
91 $sizetype,
92 $size,
93 $indefOnly,
94 $cascadeOnly,
95 $noRedirect,
96 $this->getLinkRenderer(),
97 $this->linkBatchFactory,
98 $this->loadBalancer,
99 $this->commentStore,
100 $this->userCache
101 );
102
103 $this->getOutput()->addHTML( $this->showOptions(
104 $ns,
105 $type,
106 $level,
107 $sizetype,
108 $size,
109 $filters
110 ) );
111
112 if ( $pager->getNumRows() ) {
113 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
114 } else {
115 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
116 }
117 }
118
129 protected function showOptions( $namespace, $type, $level, $sizetype,
130 $size, $filters
131 ) {
132 $formDescriptor = [
133 'namespace' => [
134 'class' => HTMLSelectNamespace::class,
135 'name' => 'namespace',
136 'id' => 'namespace',
137 'cssclass' => 'namespaceselector',
138 'all' => '',
139 'label' => $this->msg( 'namespace' )->text(),
140 ],
141 'typemenu' => $this->getTypeMenu( $type ),
142 'levelmenu' => $this->getLevelMenu( $level ),
143 'filters' => [
144 'class' => HTMLMultiSelectField::class,
145 'label' => $this->msg( 'protectedpages-filters' )->text(),
146 'flatlist' => true,
147 'options-messages' => [
148 'protectedpages-indef' => 'indefonly',
149 'protectedpages-cascade' => 'cascadeonly',
150 'protectedpages-noredirect' => 'noredirect',
151 ],
152 'default' => $filters,
153 ],
154 'sizelimit' => [
155 'class' => HTMLSizeFilterField::class,
156 'name' => 'size',
157 ]
158 ];
159 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
160 ->setMethod( 'get' )
161 ->setWrapperLegendMsg( 'protectedpages' )
162 ->setSubmitTextMsg( 'protectedpages-submit' );
163
164 return $htmlForm->prepareForm()->getHTML( false );
165 }
166
172 protected function getTypeMenu( $pr_type ) {
173 $m = []; // Temporary array
174 $options = [];
175
176 // First pass to load the log names
177 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
178 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
179 $text = $this->msg( "restriction-$type" )->text();
180 $m[$text] = $type;
181 }
182
183 // Third pass generates sorted XHTML content
184 foreach ( $m as $text => $type ) {
185 $options[$text] = $type;
186 }
187
188 return [
189 'type' => 'select',
190 'options' => $options,
191 'label' => $this->msg( 'restriction-type' )->text(),
192 'name' => $this->IdType,
193 'id' => $this->IdType,
194 ];
195 }
196
202 protected function getLevelMenu( $pr_level ) {
203 // Temporary array
204 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
205 $options = [];
206
207 // First pass to load the log names
208 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
209 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
210 if ( $type != '' && $type != '*' ) {
211 $text = $this->msg( "restriction-level-$type" )->text();
212 $m[$text] = $type;
213 }
214 }
215
216 // Third pass generates sorted XHTML content
217 foreach ( $m as $text => $type ) {
218 $options[$text] = $type;
219 }
220
221 return [
222 'type' => 'select',
223 'options' => $options,
224 'label' => $this->msg( 'restriction-level' )->text(),
225 'name' => $this->IdLevel,
226 'id' => $this->IdLevel
227 ];
228 }
229
230 protected function getGroupName() {
231 return 'maintenance';
232 }
233}
Handle database storage of comments such as edit summaries and log reasons.
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.
LinkBatchFactory $linkBatchFactory
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
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.
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, CommentStore $commentStore, UserCache $userCache)
Database cluster connection, tracking, load balancing, and transaction manager interface.