MediaWiki master
SpecialProtectedPages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
35
42 protected $IdLevel = 'level';
43 protected $IdType = 'type';
44
45 private LinkBatchFactory $linkBatchFactory;
46 private IConnectionProvider $dbProvider;
47 private CommentStore $commentStore;
48 private RowCommentFormatter $rowCommentFormatter;
49 private RestrictionStore $restrictionStore;
50
58 public function __construct(
59 LinkBatchFactory $linkBatchFactory,
60 IConnectionProvider $dbProvider,
61 CommentStore $commentStore,
62 RowCommentFormatter $rowCommentFormatter,
63 RestrictionStore $restrictionStore
64 ) {
65 parent::__construct( 'Protectedpages' );
66 $this->linkBatchFactory = $linkBatchFactory;
67 $this->dbProvider = $dbProvider;
68 $this->commentStore = $commentStore;
69 $this->rowCommentFormatter = $rowCommentFormatter;
70 $this->restrictionStore = $restrictionStore;
71 }
72
73 public function execute( $par ) {
74 $this->setHeaders();
75 $this->outputHeader();
76 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
77 $this->addHelpLink( 'Help:Protected_pages' );
78
79 $request = $this->getRequest();
80 $type = $request->getVal( $this->IdType );
81 $level = $request->getVal( $this->IdLevel );
82 $sizetype = $request->getVal( 'size-mode' );
83 $size = $request->getIntOrNull( 'size' );
84 $ns = $request->getIntOrNull( 'namespace' );
85
86 $filters = $request->getArray( 'wpfilters', [] );
87 $indefOnly = in_array( 'indefonly', $filters );
88 $cascadeOnly = in_array( 'cascadeonly', $filters );
89 $noRedirect = in_array( 'noredirect', $filters );
90
91 $pager = new ProtectedPagesPager(
92 $this->getContext(),
93 $this->commentStore,
94 $this->linkBatchFactory,
95 $this->getLinkRenderer(),
96 $this->dbProvider,
97 $this->rowCommentFormatter,
98 [],
99 $type,
100 $level,
101 $ns,
102 $sizetype,
103 $size,
104 $indefOnly,
105 $cascadeOnly,
106 $noRedirect
107 );
108
109 $this->getOutput()->addHTML( $this->showOptions(
110 $type,
111 $level,
112 $filters
113 ) );
114
115 if ( $pager->getNumRows() ) {
116 $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
117 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
118 } else {
119 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
120 }
121 }
122
130 protected function showOptions( $type, $level, $filters ) {
131 $formDescriptor = [
132 'namespace' => [
133 'class' => HTMLSelectNamespace::class,
134 'name' => 'namespace',
135 'id' => 'namespace',
136 'cssclass' => 'namespaceselector',
137 'all' => '',
138 'label' => $this->msg( 'namespace' )->text(),
139 ],
140 'typemenu' => $this->getTypeMenu( $type ),
141 'levelmenu' => $this->getLevelMenu( $level ),
142 'filters' => [
143 'class' => HTMLMultiSelectField::class,
144 'label' => $this->msg( 'protectedpages-filters' )->text(),
145 'flatlist' => true,
146 'options-messages' => [
147 'protectedpages-indef' => 'indefonly',
148 'protectedpages-cascade' => 'cascadeonly',
149 'protectedpages-noredirect' => 'noredirect',
150 ],
151 'default' => $filters,
152 ],
153 'sizelimit' => [
154 'class' => HTMLSizeFilterField::class,
155 'name' => 'size',
156 ]
157 ];
158 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
159 ->setMethod( 'get' )
160 ->setWrapperLegendMsg( 'protectedpages' )
161 ->setSubmitTextMsg( 'protectedpages-submit' );
162
163 return $htmlForm->prepareForm()->getHTML( false );
164 }
165
171 protected function getTypeMenu( $pr_type ) {
172 $m = []; // Temporary array
173 $options = [];
174
175 // First pass to load the log names
176 foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
177 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
178 $text = $this->msg( "restriction-$type" )->text();
179 $m[$text] = $type;
180 }
181
182 // Third pass generates sorted XHTML content
183 foreach ( $m as $text => $type ) {
184 $options[$text] = $type;
185 }
186
187 return [
188 'type' => 'select',
189 'options' => $options,
190 'label' => $this->msg( 'restriction-type' )->text(),
191 'name' => $this->IdType,
192 'id' => $this->IdType,
193 ];
194 }
195
201 protected function getLevelMenu( $pr_level ) {
202 $options = [ 'restriction-level-all' => 0 ];
203
204 // Load the log names as options
205 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
206 if ( $type != '' && $type != '*' ) {
207 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
208 $options["restriction-level-$type"] = $type;
209 }
210 }
211
212 return [
213 'type' => 'select',
214 'options-messages' => $options,
215 'label-message' => 'restriction-level',
216 'name' => $this->IdLevel,
217 'id' => $this->IdLevel
218 ];
219 }
220
221 protected function getGroupName() {
222 return 'maintenance';
223 }
224}
225
230class_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.
Wrapper for Html::namespaceSelector to use in HTMLForm.
A size filter field for use on query-type special pages.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
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 By default the message key is the canonical name of...
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.
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, CommentStore $commentStore, 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...
execute( $par)
Default execute method Checks user permissions.
Provide primary and replica IDatabase connections.