MediaWiki  1.34.0
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 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:792
SpecialProtectedpages\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialProtectedpages.php:37
Title\getFilteredRestrictionTypes
static getFilteredRestrictionTypes( $exists=true)
Get a filtered list of all restriction types supported by this wiki.
Definition: Title.php:2413
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:719
SpecialProtectedpages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialProtectedpages.php:197
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:828
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:758
SpecialProtectedpages
A special page that lists protected pages.
Definition: SpecialProtectedpages.php:29
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:537
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:692
SpecialProtectedpages\getLevelMenu
getLevelMenu( $pr_level)
Creates the input label of the restriction level.
Definition: SpecialProtectedpages.php:169
SpecialProtectedpages\getTypeMenu
getTypeMenu( $pr_type)
Creates the input label of the restriction type.
Definition: SpecialProtectedpages.php:139
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:37
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:709
SpecialProtectedpages\$IdType
$IdType
Definition: SpecialProtectedpages.php:31
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
SpecialProtectedpages\__construct
__construct()
Definition: SpecialProtectedpages.php:33
SpecialProtectedpages\$IdLevel
$IdLevel
Definition: SpecialProtectedpages.php:30
SpecialProtectedpages\showOptions
showOptions( $namespace, $type, $level, $sizetype, $size, $filters)
Definition: SpecialProtectedpages.php:95
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:303
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:639
ProtectedPagesPager
Definition: ProtectedPagesPager.php:25
$type
$type
Definition: testCompression.php:48