MediaWiki master
SpecialProtectedTitles.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
16
23
24 public function __construct(
25 private readonly LinkBatchFactory $linkBatchFactory,
26 private readonly IConnectionProvider $dbProvider,
27 ) {
28 parent::__construct( 'Protectedtitles' );
29 }
30
32 public function execute( $par ) {
33 $this->setHeaders();
34 $this->outputHeader();
35 $this->addHelpLink( 'Help:Protected_pages' );
36
37 $request = $this->getRequest();
38 $level = $request->getVal( 'level' );
39 $NS = $request->getIntOrNull( 'namespace' );
40
41 $pager = new ProtectedTitlesPager(
42 $this->getContext(),
43 $this->getLinkRenderer(),
44 $this->linkBatchFactory,
45 $this->dbProvider,
46 $level,
47 $NS
48 );
49
50 $this->getOutput()->addHTML( $this->showOptions() );
51
52 if ( $pager->getNumRows() ) {
53 $this->getOutput()->addHTML(
54 $pager->getNavigationBar() .
55 '<ul>' . $pager->getBody() . '</ul>' .
56 $pager->getNavigationBar()
57 );
58 } else {
59 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
60 }
61 }
62
66 private function showOptions() {
67 $formDescriptor = [
68 'namespace' => [
69 'class' => HTMLSelectNamespace::class,
70 'name' => 'namespace',
71 'id' => 'namespace',
72 'cssclass' => 'namespaceselector',
73 'all' => '',
74 'label' => $this->msg( 'namespace' )->text()
75 ],
76 'levelmenu' => $this->getLevelMenu()
77 ];
78
79 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
80 ->setMethod( 'get' )
81 ->setWrapperLegendMsg( 'protectedtitles' )
82 ->setSubmitTextMsg( 'protectedtitles-submit' );
83
84 return $htmlForm->prepareForm()->getHTML( false );
85 }
86
90 private function getLevelMenu() {
91 $options = [ 'restriction-level-all' => 0 ];
92
93 // Load the log names as options
94 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
95 if ( $type != '' && $type != '*' ) {
96 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
97 $options["restriction-level-$type"] = $type;
98 }
99 }
100
101 // Is there only one level (aside from "all")?
102 if ( count( $options ) <= 2 ) {
103 return '';
104 }
105
106 return [
107 'type' => 'select',
108 'options-messages' => $options,
109 'label-message' => 'restriction-level',
110 'name' => 'level',
111 'id' => 'level',
112 ];
113 }
114
116 protected function getGroupName() {
117 return 'maintenance';
118 }
119}
120
125class_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:214
A class containing constants representing the names of configuration variables.
const RestrictionLevels
Name constant for the RestrictionLevels setting, for use with Config::get()
Factory for LinkBatch objects to batch query page metadata.
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...
__construct(private readonly LinkBatchFactory $linkBatchFactory, private readonly IConnectionProvider $dbProvider,)
execute( $par)
Default execute method Checks user permissions.This must be overridden by subclasses; it will be made...
Provide primary and replica IDatabase connections.