MediaWiki REL1_39
SpecialProtectedtitles.php
Go to the documentation of this file.
1<?php
27
34 protected $IdLevel = 'level';
35 protected $IdType = 'type';
36
38 private $linkBatchFactory;
39
41 private $loadBalancer;
42
47 public function __construct(
48 LinkBatchFactory $linkBatchFactory,
49 ILoadBalancer $loadBalancer
50 ) {
51 parent::__construct( 'Protectedtitles' );
52 $this->linkBatchFactory = $linkBatchFactory;
53 $this->loadBalancer = $loadBalancer;
54 }
55
56 public function execute( $par ) {
57 $this->setHeaders();
58 $this->outputHeader();
59 $this->addHelpLink( 'Help:Protected_pages' );
60
61 $request = $this->getRequest();
62 $type = $request->getVal( $this->IdType );
63 $level = $request->getVal( $this->IdLevel );
64 $sizetype = $request->getVal( 'sizetype' );
65 $size = $request->getIntOrNull( 'size' );
66 $NS = $request->getIntOrNull( 'namespace' );
67
68 $pager = new ProtectedTitlesPager(
69 $this,
70 $this->linkBatchFactory,
71 $this->loadBalancer,
72 [],
73 $type,
74 $level,
75 $NS,
76 $sizetype,
77 $size
78 );
79
80 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
81
82 if ( $pager->getNumRows() ) {
83 $this->getOutput()->addHTML(
84 $pager->getNavigationBar() .
85 '<ul>' . $pager->getBody() . '</ul>' .
86 $pager->getNavigationBar()
87 );
88 } else {
89 $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
90 }
91 }
92
99 public function formatRow( $row ) {
100 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
101 if ( !$title ) {
102 return Html::rawElement(
103 'li',
104 [],
105 Html::element(
106 'span',
107 [ 'class' => 'mw-invalidtitle' ],
109 $this->getContext(),
110 $row->pt_namespace,
111 $row->pt_title
112 )
113 )
114 ) . "\n";
115 }
116
117 $link = $this->getLinkRenderer()->makeLink( $title );
118 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
119 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
120 $lang = $this->getLanguage();
121 $expiry = strlen( $row->pt_expiry ) ?
122 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
123 'infinity';
124
125 if ( $expiry !== 'infinity' ) {
126 $user = $this->getUser();
127 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
128 'protect-expiring-local',
129 $lang->userTimeAndDate( $expiry, $user ),
130 $lang->userDate( $expiry, $user ),
131 $lang->userTime( $expiry, $user )
132 )->escaped();
133 }
134
135 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
136 }
137
145 private function showOptions( $namespace, $type, $level ) {
146 $formDescriptor = [
147 'namespace' => [
148 'class' => HTMLSelectNamespace::class,
149 'name' => 'namespace',
150 'id' => 'namespace',
151 'cssclass' => 'namespaceselector',
152 'all' => '',
153 'label' => $this->msg( 'namespace' )->text()
154 ],
155 'levelmenu' => $this->getLevelMenu( $level )
156 ];
157
158 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
159 ->setMethod( 'get' )
160 ->setWrapperLegendMsg( 'protectedtitles' )
161 ->setSubmitTextMsg( 'protectedtitles-submit' );
162
163 return $htmlForm->prepareForm()->getHTML( false );
164 }
165
171 private function getLevelMenu( $pr_level ) {
172 // Temporary array
173 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
174 $options = [];
175
176 // First pass to load the log names
177 foreach ( $this->getConfig()->get( MainConfigNames::RestrictionLevels ) as $type ) {
178 if ( $type != '' && $type != '*' ) {
179 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
180 $text = $this->msg( "restriction-level-$type" )->text();
181 $m[$text] = $type;
182 }
183 }
184
185 // Is there only one level (aside from "all")?
186 if ( count( $m ) <= 2 ) {
187 return '';
188 }
189 // Third pass generates sorted XHTML content
190 foreach ( $m as $text => $type ) {
191 $options[ $text ] = $type;
192 }
193
194 return [
195 'type' => 'select',
196 'options' => $options,
197 'label' => $this->msg( 'restriction-level' )->text(),
198 'name' => $this->IdLevel,
199 'id' => $this->IdLevel
200 ];
201 }
202
203 protected function getGroupName() {
204 return 'maintenance';
205 }
206}
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:189
A class containing constants representing the names of configuration variables.
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.
Create and track the database connections and transactions for a given database cluster.
if(!isset( $args[0])) $lang