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