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