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