MediaWiki 1.43.1
SpecialProtectedTitles.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
30
37 private LinkBatchFactory $linkBatchFactory;
38 private IConnectionProvider $dbProvider;
39
44 public function __construct(
45 LinkBatchFactory $linkBatchFactory,
46 IConnectionProvider $dbProvider
47 ) {
48 parent::__construct( 'Protectedtitles' );
49 $this->linkBatchFactory = $linkBatchFactory;
50 $this->dbProvider = $dbProvider;
51 }
52
53 public function execute( $par ) {
54 $this->setHeaders();
55 $this->outputHeader();
56 $this->addHelpLink( 'Help:Protected_pages' );
57
58 $request = $this->getRequest();
59 $level = $request->getVal( 'level' );
60 $NS = $request->getIntOrNull( 'namespace' );
61
62 $pager = new ProtectedTitlesPager(
63 $this->getContext(),
64 $this->getLinkRenderer(),
65 $this->linkBatchFactory,
66 $this->dbProvider,
67 $level,
68 $NS
69 );
70
71 $this->getOutput()->addHTML( $this->showOptions() );
72
73 if ( $pager->getNumRows() ) {
74 $this->getOutput()->addHTML(
75 $pager->getNavigationBar() .
76 '<ul>' . $pager->getBody() . '</ul>' .
77 $pager->getNavigationBar()
78 );
79 } else {
80 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
81 }
82 }
83
87 private function showOptions() {
88 $formDescriptor = [
89 'namespace' => [
90 'class' => HTMLSelectNamespace::class,
91 'name' => 'namespace',
92 'id' => 'namespace',
93 'cssclass' => 'namespaceselector',
94 'all' => '',
95 'label' => $this->msg( 'namespace' )->text()
96 ],
97 'levelmenu' => $this->getLevelMenu()
98 ];
99
100 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
101 ->setMethod( 'get' )
102 ->setWrapperLegendMsg( 'protectedtitles' )
103 ->setSubmitTextMsg( 'protectedtitles-submit' );
104
105 return $htmlForm->prepareForm()->getHTML( false );
106 }
107
111 private function getLevelMenu() {
112 $options = [ 'restriction-level-all' => 0 ];
113
114 // Load the log names as options
115 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
116 if ( $type != '' && $type != '*' ) {
117 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
118 $options["restriction-level-$type"] = $type;
119 }
120 }
121
122 // Is there only one level (aside from "all")?
123 if ( count( $options ) <= 2 ) {
124 return '';
125 }
126
127 return [
128 'type' => 'select',
129 'options-messages' => $options,
130 'label-message' => 'restriction-level',
131 'name' => 'level',
132 'id' => 'level',
133 ];
134 }
135
136 protected function getGroupName() {
137 return 'maintenance';
138 }
139}
140
145class_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:209
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.