MediaWiki master
SpecialProtectedPages.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use MediaWiki\Cache\LinkBatchFactory;
22
29 private LinkBatchFactory $linkBatchFactory;
30 private IConnectionProvider $dbProvider;
31 private CommentStore $commentStore;
32 private RowCommentFormatter $rowCommentFormatter;
33 private RestrictionStore $restrictionStore;
34
35 public function __construct(
36 LinkBatchFactory $linkBatchFactory,
37 IConnectionProvider $dbProvider,
38 CommentStore $commentStore,
39 RowCommentFormatter $rowCommentFormatter,
40 RestrictionStore $restrictionStore
41 ) {
42 parent::__construct( 'Protectedpages' );
43 $this->linkBatchFactory = $linkBatchFactory;
44 $this->dbProvider = $dbProvider;
45 $this->commentStore = $commentStore;
46 $this->rowCommentFormatter = $rowCommentFormatter;
47 $this->restrictionStore = $restrictionStore;
48 }
49
51 public function execute( $par ) {
52 $this->setHeaders();
53 $this->outputHeader();
54 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
55 $this->addHelpLink( 'Help:Protected_pages' );
56
57 $request = $this->getRequest();
58 $type = $request->getVal( 'type' );
59 $level = $request->getVal( 'level' );
60 $sizetype = $request->getVal( 'size-mode' );
61 $size = $request->getIntOrNull( 'size' );
62 $ns = $request->getIntOrNull( 'namespace' );
63
64 $filters = $request->getArray( 'wpfilters', [] );
65 $indefOnly = in_array( 'indefonly', $filters );
66 $cascadeOnly = in_array( 'cascadeonly', $filters );
67 $noRedirect = in_array( 'noredirect', $filters );
68
69 $pager = new ProtectedPagesPager(
70 $this->getContext(),
71 $this->commentStore,
72 $this->linkBatchFactory,
73 $this->getLinkRenderer(),
74 $this->dbProvider,
75 $this->rowCommentFormatter,
76 $type,
77 $level,
78 $ns,
79 $sizetype,
80 $size,
81 $indefOnly,
82 $cascadeOnly,
83 $noRedirect
84 );
85
86 $this->getOutput()->addHTML( $this->showOptions(
87 $type,
88 $level,
89 $filters
90 ) );
91
92 if ( $pager->getNumRows() ) {
93 $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
94 $this->getOutput()->addParserOutputContent(
95 $pager->getFullOutput(),
96 ParserOptions::newFromContext( $this->getContext() )
97 );
98 } else {
99 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
100 }
101 }
102
110 protected function showOptions( $type, $level, $filters ) {
111 $formDescriptor = [
112 'namespace' => [
113 'class' => HTMLSelectNamespace::class,
114 'name' => 'namespace',
115 'id' => 'namespace',
116 'cssclass' => 'namespaceselector',
117 'all' => '',
118 'label' => $this->msg( 'namespace' )->text(),
119 ],
120 'typemenu' => $this->getTypeMenu( $type ),
121 'levelmenu' => $this->getLevelMenu( $level ),
122 'filters' => [
123 'class' => HTMLMultiSelectField::class,
124 'label' => $this->msg( 'protectedpages-filters' )->text(),
125 'flatlist' => true,
126 'options-messages' => [
127 'protectedpages-indef' => 'indefonly',
128 'protectedpages-cascade' => 'cascadeonly',
129 'protectedpages-noredirect' => 'noredirect',
130 ],
131 'default' => $filters,
132 ],
133 'sizelimit' => [
134 'class' => HTMLSizeFilterField::class,
135 'name' => 'size',
136 ]
137 ];
138 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
139 ->setMethod( 'get' )
140 ->setWrapperLegendMsg( 'protectedpages' )
141 ->setSubmitTextMsg( 'protectedpages-submit' );
142
143 return $htmlForm->prepareForm()->getHTML( false );
144 }
145
151 protected function getTypeMenu( $pr_type ) {
152 $m = []; // Temporary array
153 $options = [];
154
155 // First pass to load the log names
156 foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
157 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
158 $text = $this->msg( "restriction-$type" )->text();
159 $m[$text] = $type;
160 }
161
162 // Third pass generates sorted XHTML content
163 foreach ( $m as $text => $type ) {
164 $options[$text] = $type;
165 }
166
167 return [
168 'type' => 'select',
169 'options' => $options,
170 'label' => $this->msg( 'restriction-type' )->text(),
171 'name' => 'type',
172 'id' => 'type',
173 ];
174 }
175
181 protected function getLevelMenu( $pr_level ) {
182 $options = [ 'restriction-level-all' => 0 ];
183
184 // Load the log names as options
185 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
186 if ( $type != '' && $type != '*' ) {
187 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
188 $options["restriction-level-$type"] = $type;
189 }
190 }
191
192 return [
193 'type' => 'select',
194 'options-messages' => $options,
195 'label-message' => 'restriction-level',
196 'name' => 'level',
197 'id' => 'level',
198 ];
199 }
200
202 protected function getGroupName() {
203 return 'maintenance';
204 }
205}
206
211class_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:195
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.This must be overridden by subclasses; it will be made...
Provide primary and replica IDatabase connections.