MediaWiki REL1_34
SpecialProtectedpages.php
Go to the documentation of this file.
1<?php
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
32
33 public function __construct() {
34 parent::__construct( 'Protectedpages' );
35 }
36
37 public function execute( $par ) {
38 $this->setHeaders();
39 $this->outputHeader();
40 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
41 $this->addHelpLink( 'Help:Protected_pages' );
42
43 $request = $this->getRequest();
44 $type = $request->getVal( $this->IdType );
45 $level = $request->getVal( $this->IdLevel );
46 $sizetype = $request->getVal( 'size-mode' );
47 $size = $request->getIntOrNull( 'size' );
48 $ns = $request->getIntOrNull( 'namespace' );
49
50 $filters = $request->getArray( 'wpfilters', [] );
51 $indefOnly = in_array( 'indefonly', $filters );
52 $cascadeOnly = in_array( 'cascadeonly', $filters );
53 $noRedirect = in_array( 'noredirect', $filters );
54
55 $pager = new ProtectedPagesPager(
56 $this,
57 [],
58 $type,
59 $level,
60 $ns,
61 $sizetype,
62 $size,
63 $indefOnly,
64 $cascadeOnly,
65 $noRedirect,
66 $this->getLinkRenderer()
67 );
68
69 $this->getOutput()->addHTML( $this->showOptions(
70 $ns,
71 $type,
72 $level,
73 $sizetype,
74 $size,
75 $filters
76 ) );
77
78 if ( $pager->getNumRows() ) {
79 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
80 } else {
81 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
82 }
83 }
84
95 protected function showOptions( $namespace, $type, $level, $sizetype,
96 $size, $filters
97 ) {
98 $formDescriptor = [
99 'namespace' => [
100 'class' => HTMLSelectNamespace::class,
101 'name' => 'namespace',
102 'id' => 'namespace',
103 'cssclass' => 'namespaceselector',
104 'all' => '',
105 'label' => $this->msg( 'namespace' )->text(),
106 ],
107 'typemenu' => $this->getTypeMenu( $type ),
108 'levelmenu' => $this->getLevelMenu( $level ),
109 'filters' => [
110 'class' => 'HTMLMultiSelectField',
111 'label' => $this->msg( 'protectedpages-filters' )->text(),
112 'flatlist' => true,
113 'options-messages' => [
114 'protectedpages-indef' => 'indefonly',
115 'protectedpages-cascade' => 'cascadeonly',
116 'protectedpages-noredirect' => 'noredirect',
117 ],
118 'default' => $filters,
119 ],
120 'sizelimit' => [
121 'class' => HTMLSizeFilterField::class,
122 'name' => 'size',
123 ]
124 ];
125 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
126 $htmlForm
127 ->setMethod( 'get' )
128 ->setWrapperLegendMsg( 'protectedpages' )
129 ->setSubmitText( $this->msg( 'protectedpages-submit' )->text() );
130
131 return $htmlForm->prepareForm()->getHTML( false );
132 }
133
139 protected function getTypeMenu( $pr_type ) {
140 $m = []; // Temporary array
141 $options = [];
142
143 // First pass to load the log names
144 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
145 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
146 $text = $this->msg( "restriction-$type" )->text();
147 $m[$text] = $type;
148 }
149
150 // Third pass generates sorted XHTML content
151 foreach ( $m as $text => $type ) {
152 $options[$text] = $type;
153 }
154
155 return [
156 'type' => 'select',
157 'options' => $options,
158 'label' => $this->msg( 'restriction-type' )->text(),
159 'name' => $this->IdType,
160 'id' => $this->IdType,
161 ];
162 }
163
169 protected function getLevelMenu( $pr_level ) {
170 // Temporary array
171 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
172 $options = [];
173
174 // First pass to load the log names
175 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
176 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
177 if ( $type != '' && $type != '*' ) {
178 $text = $this->msg( "restriction-level-$type" )->text();
179 $m[$text] = $type;
180 }
181 }
182
183 // Third pass generates sorted XHTML content
184 foreach ( $m as $text => $type ) {
185 $options[$text] = $type;
186 }
187
188 return [
189 'type' => 'select',
190 'options' => $options,
191 'label' => $this->msg( 'restriction-level' )->text(),
192 'name' => $this->IdLevel,
193 'id' => $this->IdLevel
194 ];
195 }
196
197 protected function getGroupName() {
198 return 'maintenance';
199 }
200}
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists protected pages.
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
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...
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
execute( $par)
Default execute method Checks user permissions.