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