MediaWiki REL1_37
SpecialProtectedtitles.php
Go to the documentation of this file.
1<?php
26
33 protected $IdLevel = 'level';
34 protected $IdType = 'type';
35
38
41
46 public function __construct(
49 ) {
50 parent::__construct( 'Protectedtitles' );
51 $this->linkBatchFactory = $linkBatchFactory;
52 $this->loadBalancer = $loadBalancer;
53 }
54
55 public function execute( $par ) {
56 $this->setHeaders();
57 $this->outputHeader();
58 $this->addHelpLink( 'Help:Protected_pages' );
59
60 $request = $this->getRequest();
61 $type = $request->getVal( $this->IdType );
62 $level = $request->getVal( $this->IdLevel );
63 $sizetype = $request->getVal( 'sizetype' );
64 $size = $request->getIntOrNull( 'size' );
65 $NS = $request->getIntOrNull( 'namespace' );
66
67 $pager = new ProtectedTitlesPager(
68 $this,
69 [],
70 $type,
71 $level,
72 $NS,
73 $sizetype,
74 $size,
75 $this->linkBatchFactory,
76 $this->loadBalancer
77 );
78
79 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
80
81 if ( $pager->getNumRows() ) {
82 $this->getOutput()->addHTML(
83 $pager->getNavigationBar() .
84 '<ul>' . $pager->getBody() . '</ul>' .
85 $pager->getNavigationBar()
86 );
87 } else {
88 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
89 }
90 }
91
98 public function formatRow( $row ) {
99 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
100 if ( !$title ) {
101 return Html::rawElement(
102 'li',
103 [],
104 Html::element(
105 'span',
106 [ 'class' => 'mw-invalidtitle' ],
108 $this->getContext(),
109 $row->pt_namespace,
110 $row->pt_title
111 )
112 )
113 ) . "\n";
114 }
115
116 $link = $this->getLinkRenderer()->makeLink( $title );
117 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
118 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
119 $lang = $this->getLanguage();
120 $expiry = strlen( $row->pt_expiry ) ?
121 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
122 'infinity';
123
124 if ( $expiry !== 'infinity' ) {
125 $user = $this->getUser();
126 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
127 'protect-expiring-local',
128 $lang->userTimeAndDate( $expiry, $user ),
129 $lang->userDate( $expiry, $user ),
130 $lang->userTime( $expiry, $user )
131 )->escaped();
132 }
133
134 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
135 }
136
144 private function showOptions( $namespace, $type, $level ) {
145 $formDescriptor = [
146 'namespace' => [
147 'class' => HTMLSelectNamespace::class,
148 'name' => 'namespace',
149 'id' => 'namespace',
150 'cssclass' => 'namespaceselector',
151 'all' => '',
152 'label' => $this->msg( 'namespace' )->text()
153 ],
154 'levelmenu' => $this->getLevelMenu( $level )
155 ];
156
157 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
158 ->setMethod( 'get' )
159 ->setWrapperLegendMsg( 'protectedtitles' )
160 ->setSubmitTextMsg( 'protectedtitles-submit' );
161
162 return $htmlForm->prepareForm()->getHTML( false );
163 }
164
170 private function getLevelMenu( $pr_level ) {
171 // Temporary array
172 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
173 $options = [];
174
175 // First pass to load the log names
176 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
177 if ( $type != '' && $type != '*' ) {
178 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
179 $text = $this->msg( "restriction-level-$type" )->text();
180 $m[$text] = $type;
181 }
182 }
183
184 // Is there only one level (aside from "all")?
185 if ( count( $m ) <= 2 ) {
186 return '';
187 }
188 // Third pass generates sorted XHTML content
189 foreach ( $m as $text => $type ) {
190 $options[ $text ] = $type;
191 }
192
193 return [
194 'type' => 'select',
195 'options' => $options,
196 'label' => $this->msg( 'restriction-level' )->text(),
197 'name' => $this->IdLevel,
198 'id' => $this->IdLevel
199 ];
200 }
201
202 protected function getGroupName() {
203 return 'maintenance';
204 }
205}
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:185
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that list protected titles from creation.
__construct(LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
formatRow( $row)
Callback function to output a restriction.
execute( $par)
Default execute method Checks user permissions.
showOptions( $namespace, $type, $level)
Database cluster connection, tracking, load balancing, and transaction manager interface.
if(!isset( $args[0])) $lang