Whitelist the <wbr> element.
[mediawiki.git] / includes / specials / SpecialProtectedpages.php
blob78931a0db54bc7ee16fc2e5ddcbbe9bf3c62c76b
1 <?php
2 /**
3 * Implements Special:Protectedpages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page that lists protected pages
27 * @ingroup SpecialPage
29 class SpecialProtectedpages extends SpecialPage {
31 protected $IdLevel = 'level';
32 protected $IdType = 'type';
34 public function __construct() {
35 parent::__construct( 'Protectedpages' );
38 public function execute( $par ) {
39 $this->setHeaders();
40 $this->outputHeader();
42 // Purge expired entries on one in every 10 queries
43 if ( !mt_rand( 0, 10 ) ) {
44 Title::purgeExpiredRestrictions();
47 $request = $this->getRequest();
48 $type = $request->getVal( $this->IdType );
49 $level = $request->getVal( $this->IdLevel );
50 $sizetype = $request->getVal( 'sizetype' );
51 $size = $request->getIntOrNull( 'size' );
52 $ns = $request->getIntOrNull( 'namespace' );
53 $indefOnly = $request->getBool( 'indefonly' ) ? 1 : 0;
54 $cascadeOnly = $request->getBool( 'cascadeonly' ) ? 1 : 0;
56 $pager = new ProtectedPagesPager(
57 $this,
58 array(),
59 $type,
60 $level,
61 $ns,
62 $sizetype,
63 $size,
64 $indefOnly,
65 $cascadeOnly
68 $this->getOutput()->addHTML( $this->showOptions(
69 $ns,
70 $type,
71 $level,
72 $sizetype,
73 $size,
74 $indefOnly,
75 $cascadeOnly
76 ) );
78 if ( $pager->getNumRows() ) {
79 $this->getOutput()->addHTML(
80 $pager->getNavigationBar() .
81 '<ul>' . $pager->getBody() . '</ul>' .
82 $pager->getNavigationBar()
84 } else {
85 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
89 /**
90 * Callback function to output a restriction
91 * @param Title $row Protected title
92 * @return string Formatted "<li>" element
94 public function formatRow( $row ) {
95 wfProfileIn( __METHOD__ );
97 static $infinity = null;
99 if ( is_null( $infinity ) ) {
100 $infinity = wfGetDB( DB_SLAVE )->getInfinity();
103 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
104 if ( !$title ) {
105 wfProfileOut( __METHOD__ );
107 return Html::rawElement(
108 'li',
109 array(),
110 Html::element(
111 'span',
112 array( 'class' => 'mw-invalidtitle' ),
113 Linker::getInvalidTitleDescription(
114 $this->getContext(),
115 $row->page_namespace,
116 $row->page_title
119 ) . "\n";
122 $link = Linker::link( $title );
124 $description_items = array();
126 $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped();
128 $description_items[] = $protType;
130 if ( $row->pr_cascade ) {
131 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
134 $stxt = '';
135 $lang = $this->getLanguage();
137 $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW );
138 if ( $expiry != $infinity ) {
139 $user = $this->getUser();
140 $description_items[] = $this->msg(
141 'protect-expiring-local',
142 $lang->userTimeAndDate( $expiry, $user ),
143 $lang->userDate( $expiry, $user ),
144 $lang->userTime( $expiry, $user )
145 )->escaped();
148 if ( !is_null( $size = $row->page_len ) ) {
149 $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size );
152 # Show a link to the change protection form for allowed users otherwise
153 # a link to the protection log
154 if ( $this->getUser()->isAllowed( 'protect' ) ) {
155 $changeProtection = Linker::linkKnown(
156 $title,
157 $this->msg( 'protect_change' )->escaped(),
158 array(),
159 array( 'action' => 'unprotect' )
161 } else {
162 $ltitle = SpecialPage::getTitleFor( 'Log' );
163 $changeProtection = Linker::linkKnown(
164 $ltitle,
165 $this->msg( 'protectlogpage' )->escaped(),
166 array(),
167 array(
168 'type' => 'protect',
169 'page' => $title->getPrefixedText()
174 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )
175 ->escaped();
177 wfProfileOut( __METHOD__ );
179 return Html::rawElement(
180 'li',
181 array(),
182 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) .
183 $changeProtection
184 ) . "\n";
188 * @param $namespace Integer
189 * @param string $type restriction type
190 * @param string $level restriction level
191 * @param string $sizetype "min" or "max"
192 * @param $size Integer
193 * @param $indefOnly Boolean: only indefinie protection
194 * @param $cascadeOnly Boolean: only cascading protection
195 * @return String: input form
197 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
198 $size, $indefOnly, $cascadeOnly
200 global $wgScript;
202 $title = $this->getTitle();
204 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
205 Xml::openElement( 'fieldset' ) .
206 Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
207 Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
208 $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
209 $this->getTypeMenu( $type ) . "&#160;\n" .
210 $this->getLevelMenu( $level ) . "&#160;\n" .
211 "<br /><span style='white-space: nowrap'>" .
212 $this->getExpiryCheck( $indefOnly ) . "&#160;\n" .
213 $this->getCascadeCheck( $cascadeOnly ) . "&#160;\n" .
214 "</span><br /><span style='white-space: nowrap'>" .
215 $this->getSizeLimit( $sizetype, $size ) . "&#160;\n" .
216 "</span>" .
217 "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
218 Xml::closeElement( 'fieldset' ) .
219 Xml::closeElement( 'form' );
223 * Prepare the namespace filter drop-down; standard namespace
224 * selector, sans the MediaWiki namespace
226 * @param $namespace Mixed: pre-select namespace
227 * @return String
229 protected function getNamespaceMenu( $namespace = null ) {
230 return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
231 Html::namespaceSelector(
232 array(
233 'selected' => $namespace,
234 'all' => '',
235 'label' => $this->msg( 'namespace' )->text()
236 ), array(
237 'name' => 'namespace',
238 'id' => 'namespace',
239 'class' => 'namespaceselector',
246 * @param bool $indefOnly
247 * @return string Formatted HTML
249 protected function getExpiryCheck( $indefOnly ) {
250 return Xml::checkLabel(
251 $this->msg( 'protectedpages-indef' )->text(),
252 'indefonly',
253 'indefonly',
254 $indefOnly
255 ) . "\n";
259 * @param bool $cascadeOnly
260 * @return string Formatted HTML
262 protected function getCascadeCheck( $cascadeOnly ) {
263 return Xml::checkLabel(
264 $this->msg( 'protectedpages-cascade' )->text(),
265 'cascadeonly',
266 'cascadeonly',
267 $cascadeOnly
268 ) . "\n";
272 * @param string $sizetype "min" or "max"
273 * @param mixed $size
274 * @return string Formatted HTML
276 protected function getSizeLimit( $sizetype, $size ) {
277 $max = $sizetype === 'max';
279 return Xml::radioLabel(
280 $this->msg( 'minimum-size' )->text(),
281 'sizetype',
282 'min',
283 'wpmin',
284 !$max
286 '&#160;' .
287 Xml::radioLabel(
288 $this->msg( 'maximum-size' )->text(),
289 'sizetype',
290 'max',
291 'wpmax',
292 $max
294 '&#160;' .
295 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
296 '&#160;' .
297 Xml::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
301 * Creates the input label of the restriction type
302 * @param $pr_type string Protection type
303 * @return string Formatted HTML
305 protected function getTypeMenu( $pr_type ) {
306 $m = array(); // Temporary array
307 $options = array();
309 // First pass to load the log names
310 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) {
311 $text = $this->msg( "restriction-$type" )->text();
312 $m[$text] = $type;
315 // Third pass generates sorted XHTML content
316 foreach ( $m as $text => $type ) {
317 $selected = ( $type == $pr_type );
318 $options[] = Xml::option( $text, $type, $selected ) . "\n";
321 return "<span style='white-space: nowrap'>" .
322 Xml::label( $this->msg( 'restriction-type' )->text(), $this->IdType ) . '&#160;' .
323 Xml::tags( 'select',
324 array( 'id' => $this->IdType, 'name' => $this->IdType ),
325 implode( "\n", $options ) ) . "</span>";
329 * Creates the input label of the restriction level
330 * @param $pr_level string Protection level
331 * @return string Formatted HTML
333 protected function getLevelMenu( $pr_level ) {
334 global $wgRestrictionLevels;
336 // Temporary array
337 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
338 $options = array();
340 // First pass to load the log names
341 foreach ( $wgRestrictionLevels as $type ) {
342 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
343 if ( $type != '' && $type != '*' ) {
344 $text = $this->msg( "restriction-level-$type" )->text();
345 $m[$text] = $type;
349 // Third pass generates sorted XHTML content
350 foreach ( $m as $text => $type ) {
351 $selected = ( $type == $pr_level );
352 $options[] = Xml::option( $text, $type, $selected );
355 return "<span style='white-space: nowrap'>" .
356 Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . ' ' .
357 Xml::tags( 'select',
358 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
359 implode( "\n", $options ) ) . "</span>";
362 protected function getGroupName() {
363 return 'maintenance';
368 * @todo document
369 * @ingroup Pager
371 class ProtectedPagesPager extends AlphabeticPager {
372 public $mForm, $mConds;
373 private $type, $level, $namespace, $sizetype, $size, $indefonly;
375 function __construct( $form, $conds = array(), $type, $level, $namespace,
376 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false
378 $this->mForm = $form;
379 $this->mConds = $conds;
380 $this->type = ( $type ) ? $type : 'edit';
381 $this->level = $level;
382 $this->namespace = $namespace;
383 $this->sizetype = $sizetype;
384 $this->size = intval( $size );
385 $this->indefonly = (bool)$indefonly;
386 $this->cascadeonly = (bool)$cascadeonly;
387 parent::__construct( $form->getContext() );
390 function getStartBody() {
391 # Do a link batch query
392 $lb = new LinkBatch;
393 foreach ( $this->mResult as $row ) {
394 $lb->add( $row->page_namespace, $row->page_title );
396 $lb->execute();
398 return '';
401 function formatRow( $row ) {
402 return $this->mForm->formatRow( $row );
405 function getQueryInfo() {
406 $conds = $this->mConds;
407 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
408 'OR pr_expiry IS NULL)';
409 $conds[] = 'page_id=pr_page';
410 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
412 if ( $this->sizetype == 'min' ) {
413 $conds[] = 'page_len>=' . $this->size;
414 } elseif ( $this->sizetype == 'max' ) {
415 $conds[] = 'page_len<=' . $this->size;
418 if ( $this->indefonly ) {
419 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
420 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
422 if ( $this->cascadeonly ) {
423 $conds[] = 'pr_cascade = 1';
426 if ( $this->level ) {
427 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
429 if ( !is_null( $this->namespace ) ) {
430 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
433 return array(
434 'tables' => array( 'page_restrictions', 'page' ),
435 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len',
436 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ),
437 'conds' => $conds
441 function getIndexField() {
442 return 'pr_id';