MediaWiki master
SpecialProtectedPages.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
17use MediaWiki\Pager\ProtectedPagesPager;
22
29 public function __construct(
30 private readonly LinkBatchFactory $linkBatchFactory,
31 private readonly IConnectionProvider $dbProvider,
32 private readonly CommentStore $commentStore,
33 private readonly RowCommentFormatter $rowCommentFormatter,
34 private readonly RestrictionStore $restrictionStore,
35 ) {
36 parent::__construct( 'Protectedpages' );
37 }
38
40 public function execute( $par ) {
41 $this->setHeaders();
42 $this->outputHeader();
43 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
44 $this->addHelpLink( 'Help:Protected_pages' );
45
46 $request = $this->getRequest();
47 $type = $request->getVal( 'type' );
48 $level = $request->getVal( 'level' );
49 $sizetype = $request->getVal( 'size-mode' );
50 $size = $request->getIntOrNull( 'size' );
51 $ns = $request->getIntOrNull( 'namespace' );
52
53 $filters = $request->getArray( 'wpfilters', [] );
54 $indefOnly = in_array( 'indefonly', $filters );
55 $cascadeOnly = in_array( 'cascadeonly', $filters );
56 $noRedirect = in_array( 'noredirect', $filters );
57
58 $pager = new ProtectedPagesPager(
59 $this->getContext(),
60 $this->commentStore,
61 $this->linkBatchFactory,
62 $this->getLinkRenderer(),
63 $this->dbProvider,
64 $this->rowCommentFormatter,
65 $type,
66 $level,
67 $ns,
68 $sizetype,
69 $size,
70 $indefOnly,
71 $cascadeOnly,
72 $noRedirect
73 );
74
75 $this->getOutput()->addHTML( $this->showOptions(
76 $type,
77 $level,
78 $filters
79 ) );
80
81 if ( $pager->getNumRows() ) {
82 $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
83 $this->getOutput()->addParserOutputContent(
84 $pager->getFullOutput(),
85 ParserOptions::newFromContext( $this->getContext() )
86 );
87 } else {
88 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
89 }
90 }
91
99 protected function showOptions( $type, $level, $filters ) {
100 $formDescriptor = [
101 'namespace' => [
102 'class' => HTMLSelectNamespace::class,
103 'name' => 'namespace',
104 'id' => 'namespace',
105 'cssclass' => 'namespaceselector',
106 'all' => '',
107 'label' => $this->msg( 'namespace' )->text(),
108 ],
109 'typemenu' => $this->getTypeMenu( $type ),
110 'levelmenu' => $this->getLevelMenu( $level ),
111 'filters' => [
112 'class' => HTMLMultiSelectField::class,
113 'label' => $this->msg( 'protectedpages-filters' )->text(),
114 'flatlist' => true,
115 'options-messages' => [
116 'protectedpages-indef' => 'indefonly',
117 'protectedpages-cascade' => 'cascadeonly',
118 'protectedpages-noredirect' => 'noredirect',
119 ],
120 'default' => $filters,
121 ],
122 'sizelimit' => [
123 'class' => HTMLSizeFilterField::class,
124 'name' => 'size',
125 ]
126 ];
127 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
128 ->setMethod( 'get' )
129 ->setWrapperLegendMsg( 'protectedpages' )
130 ->setSubmitTextMsg( 'protectedpages-submit' );
131
132 return $htmlForm->prepareForm()->getHTML( false );
133 }
134
140 protected function getTypeMenu( $pr_type ) {
141 $m = []; // Temporary array
142 $options = [];
143
144 // First pass to load the log names
145 foreach ( $this->restrictionStore->listAllRestrictionTypes( true ) as $type ) {
146 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
147 $text = $this->msg( "restriction-$type" )->text();
148 $m[$text] = $type;
149 }
150
151 // Third pass generates sorted XHTML content
152 foreach ( $m as $text => $type ) {
153 $options[$text] = $type;
154 }
155
156 return [
157 'type' => 'select',
158 'options' => $options,
159 'label' => $this->msg( 'restriction-type' )->text(),
160 'name' => 'type',
161 'id' => 'type',
162 ];
163 }
164
170 protected function getLevelMenu( $pr_level ) {
171 $options = [ 'restriction-level-all' => 0 ];
172
173 // Load the log names as options
174 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
175 if ( $type != '' && $type != '*' ) {
176 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
177 $options["restriction-level-$type"] = $type;
178 }
179 }
180
181 return [
182 'type' => 'select',
183 'options-messages' => $options,
184 'label-message' => 'restriction-level',
185 'name' => 'level',
186 'id' => 'level',
187 ];
188 }
189
191 protected function getGroupName() {
192 return 'maintenance';
193 }
194}
195
200class_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:207
A class containing constants representing the names of configuration variables.
const RestrictionLevels
Name constant for the RestrictionLevels setting, for use with Config::get()
Factory for LinkBatch objects to batch query page metadata.
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(private readonly LinkBatchFactory $linkBatchFactory, private readonly IConnectionProvider $dbProvider, private readonly CommentStore $commentStore, private readonly RowCommentFormatter $rowCommentFormatter, private readonly 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.