MediaWiki master
SpecialProtectedTitles.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
30
37 protected $IdLevel = 'level';
38 protected $IdType = 'type';
39
40 private LinkBatchFactory $linkBatchFactory;
41 private IConnectionProvider $dbProvider;
42
47 public function __construct(
48 LinkBatchFactory $linkBatchFactory,
49 IConnectionProvider $dbProvider
50 ) {
51 parent::__construct( 'Protectedtitles' );
52 $this->linkBatchFactory = $linkBatchFactory;
53 $this->dbProvider = $dbProvider;
54 }
55
56 public function execute( $par ) {
57 $this->setHeaders();
58 $this->outputHeader();
59 $this->addHelpLink( 'Help:Protected_pages' );
60
61 $request = $this->getRequest();
62 $type = $request->getVal( $this->IdType );
63 $level = $request->getVal( $this->IdLevel );
64 $sizetype = $request->getVal( 'sizetype' );
65 $size = $request->getIntOrNull( 'size' );
66 $NS = $request->getIntOrNull( 'namespace' );
67
68 $pager = new ProtectedTitlesPager(
69 $this->getContext(),
70 $this->getLinkRenderer(),
71 $this->linkBatchFactory,
72 $this->dbProvider,
73 [],
74 $type,
75 $level,
76 $NS,
77 $sizetype,
78 $size
79 );
80
81 $this->getOutput()->addHTML( $this->showOptions() );
82
83 if ( $pager->getNumRows() ) {
84 $this->getOutput()->addHTML(
85 $pager->getNavigationBar() .
86 '<ul>' . $pager->getBody() . '</ul>' .
87 $pager->getNavigationBar()
88 );
89 } else {
90 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
91 }
92 }
93
97 private function showOptions() {
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 'levelmenu' => $this->getLevelMenu()
108 ];
109
110 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
111 ->setMethod( 'get' )
112 ->setWrapperLegendMsg( 'protectedtitles' )
113 ->setSubmitTextMsg( 'protectedtitles-submit' );
114
115 return $htmlForm->prepareForm()->getHTML( false );
116 }
117
121 private function getLevelMenu() {
122 $options = [ 'restriction-level-all' => 0 ];
123
124 // Load the log names as options
125 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
126 if ( $type != '' && $type != '*' ) {
127 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
128 $options["restriction-level-$type"] = $type;
129 }
130 }
131
132 // Is there only one level (aside from "all")?
133 if ( count( $options ) <= 2 ) {
134 return '';
135 }
136
137 return [
138 'type' => 'select',
139 'options-messages' => $options,
140 'label-message' => 'restriction-level',
141 'name' => $this->IdLevel,
142 'id' => $this->IdLevel
143 ];
144 }
145
146 protected function getGroupName() {
147 return 'maintenance';
148 }
149}
150
155class_alias( SpecialProtectedTitles::class, 'SpecialProtectedtitles' );
Wrapper for Html::namespaceSelector to use in HTMLForm.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
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.