Remove most named character references from output
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 * @todo document
9 * @ingroup SpecialPage
10 */
11 class ProtectedPagesForm {
12
13 protected $IdLevel = 'level';
14 protected $IdType = 'type';
15
16 public function showList( $msg = '' ) {
17 global $wgOut, $wgRequest;
18
19 if( $msg != "" ) {
20 $wgOut->setSubtitle( $msg );
21 }
22
23 // Purge expired entries on one in every 10 queries
24 if( !mt_rand( 0, 10 ) ) {
25 Title::purgeExpiredRestrictions();
26 }
27
28 $type = $wgRequest->getVal( $this->IdType );
29 $level = $wgRequest->getVal( $this->IdLevel );
30 $sizetype = $wgRequest->getVal( 'sizetype' );
31 $size = $wgRequest->getIntOrNull( 'size' );
32 $NS = $wgRequest->getIntOrNull( 'namespace' );
33 $indefOnly = $wgRequest->getBool( 'indefonly' ) ? 1 : 0;
34 $cascadeOnly = $wgRequest->getBool('cascadeonly') ? 1 : 0;
35
36 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
37
38 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
39
40 if( $pager->getNumRows() ) {
41 $s = $pager->getNavigationBar();
42 $s .= "<ul>" .
43 $pager->getBody() .
44 "</ul>";
45 $s .= $pager->getNavigationBar();
46 } else {
47 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
48 }
49 $wgOut->addHTML( $s );
50 }
51
52 /**
53 * Callback function to output a restriction
54 * @param $row object Protected title
55 * @return string Formatted <li> element
56 */
57 public function formatRow( $row ) {
58 global $wgUser, $wgLang, $wgContLang;
59
60 wfProfileIn( __METHOD__ );
61
62 static $skin=null;
63
64 if( is_null( $skin ) )
65 $skin = $wgUser->getSkin();
66
67 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
68 $link = $skin->link( $title );
69
70 $description_items = array ();
71
72 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
73
74 $description_items[] = $protType;
75
76 if( $row->pr_cascade ) {
77 $description_items[] = wfMsg( 'protect-summary-cascade' );
78 }
79
80 $expiry_description = '';
81 $stxt = '';
82
83 if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
84 $expiry = Block::decodeExpiry( $row->pr_expiry );
85
86 $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) ,
87 $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
88
89 $description_items[] = htmlspecialchars($expiry_description);
90 }
91
92 if(!is_null($size = $row->page_len)) {
93 $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
94 }
95
96 # Show a link to the change protection form for allowed users otherwise a link to the protection log
97 if( $wgUser->isAllowed( 'protect' ) ) {
98 $changeProtection = ' (' . $skin->linkKnown(
99 $title,
100 wfMsgHtml( 'protect_change' ),
101 array(),
102 array( 'action' => 'unprotect' )
103 ) . ')';
104 } else {
105 $ltitle = SpecialPage::getTitleFor( 'Log' );
106 $changeProtection = ' (' . $skin->linkKnown(
107 $ltitle,
108 wfMsgHtml( 'protectlogpage' ),
109 array(),
110 array(
111 'type' => 'protect',
112 'page' => $title->getPrefixedText()
113 )
114 ) . ')';
115 }
116
117 wfProfileOut( __METHOD__ );
118
119 return Html::rawElement(
120 'li',
121 array(),
122 wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
123 }
124
125 /**
126 * @param $namespace Integer
127 * @param $type String: restriction type
128 * @param $level String: restriction level
129 * @param $sizetype String: "min" or "max"
130 * @param $size Integer
131 * @param $indefOnly Boolean: only indefinie protection
132 * @param $cascadeOnly Boolean: only cascading protection
133 * @return String: input form
134 */
135 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
136 global $wgScript;
137 $title = SpecialPage::getTitleFor( 'Protectedpages' );
138 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
139 Xml::openElement( 'fieldset' ) .
140 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
141 Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
142 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
143 $this->getTypeMenu( $type ) . "&#160;\n" .
144 $this->getLevelMenu( $level ) . "&#160;\n" .
145 "<br /><span style='white-space: nowrap'>" .
146 $this->getExpiryCheck( $indefOnly ) . "&#160;\n" .
147 $this->getCascadeCheck( $cascadeOnly ) . "&#160;\n" .
148 "</span><br /><span style='white-space: nowrap'>" .
149 $this->getSizeLimit( $sizetype, $size ) . "&#160;\n" .
150 "</span>" .
151 "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
152 Xml::closeElement( 'fieldset' ) .
153 Xml::closeElement( 'form' );
154 }
155
156 /**
157 * Prepare the namespace filter drop-down; standard namespace
158 * selector, sans the MediaWiki namespace
159 *
160 * @param $namespace Mixed: pre-select namespace
161 * @return String
162 */
163 protected function getNamespaceMenu( $namespace = null ) {
164 return "<span style='white-space: nowrap'>" .
165 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;'
166 . Xml::namespaceSelector( $namespace, '' ) . "</span>";
167 }
168
169 /**
170 * @return string Formatted HTML
171 */
172 protected function getExpiryCheck( $indefOnly ) {
173 return
174 Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
175 }
176
177 /**
178 * @return string Formatted HTML
179 */
180 protected function getCascadeCheck( $cascadeOnly ) {
181 return
182 Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
183 }
184
185 /**
186 * @return string Formatted HTML
187 */
188 protected function getSizeLimit( $sizetype, $size ) {
189 $max = $sizetype === 'max';
190
191 return
192 Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
193 '&#160;' .
194 Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
195 '&#160;' .
196 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
197 '&#160;' .
198 Xml::label( wfMsg('pagesize'), 'wpsize' );
199 }
200
201 /**
202 * Creates the input label of the restriction type
203 * @param $pr_type string Protection type
204 * @return string Formatted HTML
205 */
206 protected function getTypeMenu( $pr_type ) {
207 global $wgRestrictionTypes;
208
209 $m = array(); // Temporary array
210 $options = array();
211
212 // First pass to load the log names
213 foreach( $wgRestrictionTypes as $type ) {
214 $text = wfMsg("restriction-$type");
215 $m[$text] = $type;
216 }
217
218 // Third pass generates sorted XHTML content
219 foreach( $m as $text => $type ) {
220 $selected = ($type == $pr_type );
221 $options[] = Xml::option( $text, $type, $selected ) . "\n";
222 }
223
224 return "<span style='white-space: nowrap'>" .
225 Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&#160;' .
226 Xml::tags( 'select',
227 array( 'id' => $this->IdType, 'name' => $this->IdType ),
228 implode( "\n", $options ) ) . "</span>";
229 }
230
231 /**
232 * Creates the input label of the restriction level
233 * @param $pr_level string Protection level
234 * @return string Formatted HTML
235 */
236 protected function getLevelMenu( $pr_level ) {
237 global $wgRestrictionLevels;
238
239 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
240 $options = array();
241
242 // First pass to load the log names
243 foreach( $wgRestrictionLevels as $type ) {
244 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
245 if( $type !='' && $type !='*') {
246 $text = wfMsg("restriction-level-$type");
247 $m[$text] = $type;
248 }
249 }
250
251 // Third pass generates sorted XHTML content
252 foreach( $m as $text => $type ) {
253 $selected = ($type == $pr_level );
254 $options[] = Xml::option( $text, $type, $selected );
255 }
256
257 return "<span style='white-space: nowrap'>" .
258 Xml::label( wfMsg( 'restriction-level' ) , $this->IdLevel ) . ' ' .
259 Xml::tags( 'select',
260 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
261 implode( "\n", $options ) ) . "</span>";
262 }
263 }
264
265 /**
266 * @todo document
267 * @ingroup Pager
268 */
269 class ProtectedPagesPager extends AlphabeticPager {
270 public $mForm, $mConds;
271 private $type, $level, $namespace, $sizetype, $size, $indefonly;
272
273 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
274 $indefonly = false, $cascadeonly = false )
275 {
276 $this->mForm = $form;
277 $this->mConds = $conds;
278 $this->type = ( $type ) ? $type : 'edit';
279 $this->level = $level;
280 $this->namespace = $namespace;
281 $this->sizetype = $sizetype;
282 $this->size = intval($size);
283 $this->indefonly = (bool)$indefonly;
284 $this->cascadeonly = (bool)$cascadeonly;
285 parent::__construct();
286 }
287
288 function getStartBody() {
289 # Do a link batch query
290 $lb = new LinkBatch;
291 while( $row = $this->mResult->fetchObject() ) {
292 $lb->add( $row->page_namespace, $row->page_title );
293 }
294 $lb->execute();
295 return '';
296 }
297
298 function formatRow( $row ) {
299 return $this->mForm->formatRow( $row );
300 }
301
302 function getQueryInfo() {
303 $conds = $this->mConds;
304 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
305 'OR pr_expiry IS NULL)';
306 $conds[] = 'page_id=pr_page';
307 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
308
309 if( $this->sizetype=='min' ) {
310 $conds[] = 'page_len>=' . $this->size;
311 } else if( $this->sizetype=='max' ) {
312 $conds[] = 'page_len<=' . $this->size;
313 }
314
315 if( $this->indefonly ) {
316 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
317 }
318 if( $this->cascadeonly ) {
319 $conds[] = "pr_cascade = '1'";
320 }
321
322 if( $this->level )
323 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
324 if( !is_null($this->namespace) )
325 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
326 return array(
327 'tables' => array( 'page_restrictions', 'page' ),
328 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
329 'conds' => $conds
330 );
331 }
332
333 function getIndexField() {
334 return 'pr_id';
335 }
336 }
337
338 /**
339 * Constructor
340 */
341 function wfSpecialProtectedpages() {
342 $ppForm = new ProtectedPagesForm();
343 $ppForm->showList();
344 }