MediaWiki master
SpecialProtectedTitles.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
26use HTMLSelectNamespace;
33
40 protected $IdLevel = 'level';
41 protected $IdType = 'type';
42
43 private LinkBatchFactory $linkBatchFactory;
44 private IConnectionProvider $dbProvider;
45
50 public function __construct(
51 LinkBatchFactory $linkBatchFactory,
52 IConnectionProvider $dbProvider
53 ) {
54 parent::__construct( 'Protectedtitles' );
55 $this->linkBatchFactory = $linkBatchFactory;
56 $this->dbProvider = $dbProvider;
57 }
58
59 public function execute( $par ) {
60 $this->setHeaders();
61 $this->outputHeader();
62 $this->addHelpLink( 'Help:Protected_pages' );
63
64 $request = $this->getRequest();
65 $type = $request->getVal( $this->IdType );
66 $level = $request->getVal( $this->IdLevel );
67 $sizetype = $request->getVal( 'sizetype' );
68 $size = $request->getIntOrNull( 'size' );
69 $NS = $request->getIntOrNull( 'namespace' );
70
71 $pager = new ProtectedTitlesPager(
72 $this->getContext(),
73 $this->getLinkRenderer(),
74 $this->linkBatchFactory,
75 $this->dbProvider,
76 [],
77 $type,
78 $level,
79 $NS,
80 $sizetype,
81 $size
82 );
83
84 $this->getOutput()->addHTML( $this->showOptions() );
85
86 if ( $pager->getNumRows() ) {
87 $this->getOutput()->addHTML(
88 $pager->getNavigationBar() .
89 '<ul>' . $pager->getBody() . '</ul>' .
90 $pager->getNavigationBar()
91 );
92 } else {
93 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
94 }
95 }
96
100 private function showOptions() {
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 'levelmenu' => $this->getLevelMenu()
111 ];
112
113 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
114 ->setMethod( 'get' )
115 ->setWrapperLegendMsg( 'protectedtitles' )
116 ->setSubmitTextMsg( 'protectedtitles-submit' );
117
118 return $htmlForm->prepareForm()->getHTML( false );
119 }
120
124 private function getLevelMenu() {
125 $options = [ 'restriction-level-all' => 0 ];
126
127 // Load the log names as options
128 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
129 if ( $type != '' && $type != '*' ) {
130 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
131 $options["restriction-level-$type"] = $type;
132 }
133 }
134
135 // Is there only one level (aside from "all")?
136 if ( count( $options ) <= 2 ) {
137 return '';
138 }
139
140 return [
141 'type' => 'select',
142 'options-messages' => $options,
143 'label-message' => 'restriction-level',
144 'name' => $this->IdLevel,
145 'id' => $this->IdLevel
146 ];
147 }
148
149 protected function getGroupName() {
150 return 'maintenance';
151 }
152}
153
158class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' );
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 list protected titles from creation.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Default execute method Checks user permissions.
__construct(LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider)
Provide primary and replica IDatabase connections.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...