MediaWiki REL1_30
SpecialProtectedtitles.php
Go to the documentation of this file.
1<?php
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
32
33 public function __construct() {
34 parent::__construct( 'Protectedtitles' );
35 }
36
37 function execute( $par ) {
38 $this->setHeaders();
39 $this->outputHeader();
40
41 $request = $this->getRequest();
42 $type = $request->getVal( $this->IdType );
43 $level = $request->getVal( $this->IdLevel );
44 $sizetype = $request->getVal( 'sizetype' );
45 $size = $request->getIntOrNull( 'size' );
46 $NS = $request->getIntOrNull( 'namespace' );
47
48 $pager = new ProtectedTitlesPager( $this, [], $type, $level, $NS, $sizetype, $size );
49
50 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
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
69 function formatRow( $row ) {
70 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
71 if ( !$title ) {
72 return Html::rawElement(
73 'li',
74 [],
75 Html::element(
76 'span',
77 [ 'class' => 'mw-invalidtitle' ],
79 $this->getContext(),
80 $row->pt_namespace,
81 $row->pt_title
82 )
83 )
84 ) . "\n";
85 }
86
87 $link = $this->getLinkRenderer()->makeLink( $title );
88 $description_items = [];
89 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
90 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
91 $description_items[] = $protType;
92 $lang = $this->getLanguage();
93 $expiry = strlen( $row->pt_expiry ) ?
94 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
95 'infinity';
96
97 if ( $expiry !== 'infinity' ) {
98 $user = $this->getUser();
99 $description_items[] = $this->msg(
100 'protect-expiring-local',
101 $lang->userTimeAndDate( $expiry, $user ),
102 $lang->userDate( $expiry, $user ),
103 $lang->userTime( $expiry, $user )
104 )->escaped();
105 }
106
107 // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
108 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
109 }
110
118 function showOptions( $namespace, $type = 'edit', $level ) {
119 $action = htmlspecialchars( wfScript() );
120 $title = $this->getPageTitle();
121 $special = htmlspecialchars( $title->getPrefixedDBkey() );
122
123 return "<form action=\"$action\" method=\"get\">\n" .
124 '<fieldset>' .
125 Xml::element( 'legend', [], $this->msg( 'protectedtitles' )->text() ) .
126 Html::hidden( 'title', $special ) . "&#160;\n" .
127 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
128 $this->getLevelMenu( $level ) . "&#160;\n" .
129 "&#160;" . Xml::submitButton( $this->msg( 'protectedtitles-submit' )->text() ) . "\n" .
130 "</fieldset></form>";
131 }
132
140 function getNamespaceMenu( $namespace = null ) {
141 return Html::namespaceSelector(
142 [
143 'selected' => $namespace,
144 'all' => '',
145 'label' => $this->msg( 'namespace' )->text()
146 ], [
147 'name' => 'namespace',
148 'id' => 'namespace',
149 'class' => 'namespaceselector',
150 ]
151 );
152 }
153
159 function getLevelMenu( $pr_level ) {
160 // Temporary array
161 $m = [ $this->msg( 'restriction-level-all' )->text() => 0 ];
162 $options = [];
163
164 // First pass to load the log names
165 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
166 if ( $type != '' && $type != '*' ) {
167 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
168 $text = $this->msg( "restriction-level-$type" )->text();
169 $m[$text] = $type;
170 }
171 }
172
173 // Is there only one level (aside from "all")?
174 if ( count( $m ) <= 2 ) {
175 return '';
176 }
177 // Third pass generates sorted XHTML content
178 foreach ( $m as $text => $type ) {
179 $selected = ( $type == $pr_level );
180 $options[] = Xml::option( $text, $type, $selected );
181 }
182
183 return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
184 Xml::tags( 'select',
185 [ 'id' => $this->IdLevel, 'name' => $this->IdLevel ],
186 implode( "\n", $options ) );
187 }
188
189 protected function getGroupName() {
190 return 'maintenance';
191 }
192}
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:209
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)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
A special page that list protected titles from creation.
getNamespaceMenu( $namespace=null)
Prepare the namespace filter drop-down; standard namespace selector, sans the MediaWiki namespace.
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='edit', $level)
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2775
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1971
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2989
if(!isset( $args[0])) $lang