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