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