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
21 * @ingroup SpecialPage
25 * A special page that lists protected pages
27 * @ingroup SpecialPage
29 class SpecialProtectedpages
extends SpecialPage
{
30 protected $IdLevel = 'level';
31 protected $IdType = 'type';
33 public function __construct() {
34 parent
::__construct( 'Protectedpages' );
37 public function execute( $par ) {
39 $this->outputHeader();
40 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
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;
55 $noRedirect = $request->getBool( 'noredirect' ) ?
1 : 0;
57 $pager = new ProtectedPagesPager(
70 $this->getOutput()->addHTML( $this->showOptions(
81 if ( $pager->getNumRows() ) {
82 $this->getOutput()->addHTML(
83 $pager->getNavigationBar() .
85 $pager->getNavigationBar()
88 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
93 * @param int $namespace
94 * @param string $type Restriction type
95 * @param string $level Restriction level
96 * @param string $sizetype "min" or "max"
98 * @param bool $indefOnly Only indefinite protection
99 * @param bool $cascadeOnly Only cascading protection
100 * @param bool $noRedirect Don't show redirects
101 * @return string Input form
103 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
104 $size, $indefOnly, $cascadeOnly, $noRedirect
108 $title = $this->getPageTitle();
110 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
111 Xml
::openElement( 'fieldset' ) .
112 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
113 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
114 $this->getNamespaceMenu( $namespace ) . " \n" .
115 $this->getTypeMenu( $type ) . " \n" .
116 $this->getLevelMenu( $level ) . " \n" .
117 "<br /><span style='white-space: nowrap'>" .
118 $this->getExpiryCheck( $indefOnly ) . " \n" .
119 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
120 $this->getRedirectCheck( $noRedirect ) . " \n" .
121 "</span><br /><span style='white-space: nowrap'>" .
122 $this->getSizeLimit( $sizetype, $size ) . " \n" .
124 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
125 Xml
::closeElement( 'fieldset' ) .
126 Xml
::closeElement( 'form' );
130 * Prepare the namespace filter drop-down; standard namespace
131 * selector, sans the MediaWiki namespace
133 * @param string|null $namespace Pre-select namespace
136 protected function getNamespaceMenu( $namespace = null ) {
137 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
138 Html
::namespaceSelector(
140 'selected' => $namespace,
142 'label' => $this->msg( 'namespace' )->text()
144 'name' => 'namespace',
146 'class' => 'namespaceselector',
153 * @param bool $indefOnly
154 * @return string Formatted HTML
156 protected function getExpiryCheck( $indefOnly ) {
157 return Xml
::checkLabel(
158 $this->msg( 'protectedpages-indef' )->text(),
166 * @param bool $cascadeOnly
167 * @return string Formatted HTML
169 protected function getCascadeCheck( $cascadeOnly ) {
170 return Xml
::checkLabel(
171 $this->msg( 'protectedpages-cascade' )->text(),
179 * @param bool $noRedirect
180 * @return string Formatted HTML
182 protected function getRedirectCheck( $noRedirect ) {
183 return Xml
::checkLabel(
184 $this->msg( 'protectedpages-noredirect' )->text(),
192 * @param string $sizetype "min" or "max"
194 * @return string Formatted HTML
196 protected function getSizeLimit( $sizetype, $size ) {
197 $max = $sizetype === 'max';
199 return Xml
::radioLabel(
200 $this->msg( 'minimum-size' )->text(),
208 $this->msg( 'maximum-size' )->text(),
215 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
217 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
221 * Creates the input label of the restriction type
222 * @param string $pr_type Protection type
223 * @return string Formatted HTML
225 protected function getTypeMenu( $pr_type ) {
226 $m = array(); // Temporary array
229 // First pass to load the log names
230 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
231 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
232 $text = $this->msg( "restriction-$type" )->text();
236 // Third pass generates sorted XHTML content
237 foreach ( $m as $text => $type ) {
238 $selected = ( $type == $pr_type );
239 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
242 return "<span style='white-space: nowrap'>" .
243 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
245 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
246 implode( "\n", $options ) ) . "</span>";
250 * Creates the input label of the restriction level
251 * @param string $pr_level Protection level
252 * @return string Formatted HTML
254 protected function getLevelMenu( $pr_level ) {
255 global $wgRestrictionLevels;
258 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
261 // First pass to load the log names
262 foreach ( $wgRestrictionLevels as $type ) {
263 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
264 if ( $type != '' && $type != '*' ) {
265 $text = $this->msg( "restriction-level-$type" )->text();
270 // Third pass generates sorted XHTML content
271 foreach ( $m as $text => $type ) {
272 $selected = ( $type == $pr_level );
273 $options[] = Xml
::option( $text, $type, $selected );
276 return "<span style='white-space: nowrap'>" .
277 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
279 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
280 implode( "\n", $options ) ) . "</span>";
283 protected function getGroupName() {
284 return 'maintenance';
292 class ProtectedPagesPager
extends TablePager
{
293 public $mForm, $mConds;
294 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
296 function __construct( $form, $conds = array(), $type, $level, $namespace,
297 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
299 $this->mForm
= $form;
300 $this->mConds
= $conds;
301 $this->type
= ( $type ) ?
$type : 'edit';
302 $this->level
= $level;
303 $this->namespace = $namespace;
304 $this->sizetype
= $sizetype;
305 $this->size
= intval( $size );
306 $this->indefonly
= (bool)$indefonly;
307 $this->cascadeonly
= (bool)$cascadeonly;
308 $this->noredirect
= (bool)$noredirect;
309 parent
::__construct( $form->getContext() );
312 function preprocessResults( $result ) {
313 # Do a link batch query
317 foreach ( $result as $row ) {
318 $lb->add( $row->page_namespace
, $row->page_title
);
319 // field is nullable, maybe null on old protections
320 if ( $row->log_user
!== null ) {
321 $userids[] = $row->log_user
;
325 // fill LinkBatch with user page and user talk
326 if ( count( $userids ) ) {
327 $userCache = UserCache
::singleton();
328 $userCache->doQuery( $userids, array(), __METHOD__
);
329 foreach ( $userids as $userid ) {
330 $name = $userCache->getProp( $userid, 'name' );
331 if ( $name !== false ) {
332 $lb->add( NS_USER
, $name );
333 $lb->add( NS_USER_TALK
, $name );
341 function getFieldNames() {
342 static $headers = null;
344 if ( $headers == array() ) {
346 'log_timestamp' => 'protectedpages-timestamp',
347 'pr_page' => 'protectedpages-page',
348 'pr_expiry' => 'protectedpages-expiry',
349 'log_user' => 'protectedpages-performer',
350 'pr_params' => 'protectedpages-params',
351 'log_comment' => 'protectedpages-reason',
353 foreach ( $headers as $key => $val ) {
354 $headers[$key] = $this->msg( $val )->text();
362 * @param string $field
363 * @param string $value
365 * @throws MWException
367 function formatValue( $field, $value ) {
368 /** @var $row object */
369 $row = $this->mCurrentRow
;
374 case 'log_timestamp':
375 // when timestamp is null, this is a old protection row
376 if ( $value === null ) {
377 $formatted = Html
::rawElement(
379 array( 'class' => 'mw-protectedpages-unknown' ),
380 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
383 $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
388 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
390 $formatted = Html
::element(
392 array( 'class' => 'mw-invalidtitle' ),
393 Linker
::getInvalidTitleDescription(
395 $row->page_namespace
,
400 $formatted = Linker
::link( $title );
402 if ( !is_null( $row->page_len
) ) {
403 $formatted .= $this->getLanguage()->getDirMark() .
404 ' ' . Html
::rawElement(
406 array( 'class' => 'mw-protectedpages-length' ),
407 Linker
::formatRevisionSize( $row->page_len
)
413 $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true );
414 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
415 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
416 $changeProtection = Linker
::linkKnown(
418 $this->msg( 'protect_change' )->escaped(),
420 array( 'action' => 'unprotect' )
422 $formatted .= ' ' . Html
::rawElement(
424 array( 'class' => 'mw-protectedpages-actions' ),
425 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
431 // when timestamp is null, this is a old protection row
432 if ( $row->log_timestamp
=== null ) {
433 $formatted = Html
::rawElement(
435 array( 'class' => 'mw-protectedpages-unknown' ),
436 $this->msg( 'protectedpages-unknown-performer' )->escaped()
439 $username = UserCache
::singleton()->getProp( $value, 'name' );
440 if ( LogEventsList
::userCanBitfield(
442 LogPage
::DELETED_USER
,
445 if ( $username === false ) {
446 $formatted = htmlspecialchars( $value );
448 $formatted = Linker
::userLink( $value, $username )
449 . Linker
::userToolLinks( $value, $username );
452 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
454 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
455 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
462 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
463 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
464 if ( $row->pr_cascade
) {
465 $params[] = $this->msg( 'protect-summary-cascade' )->text();
467 $formatted = $this->getLanguage()->commaList( $params );
471 // when timestamp is null, this is an old protection row
472 if ( $row->log_timestamp
=== null ) {
473 $formatted = Html
::rawElement(
475 array( 'class' => 'mw-protectedpages-unknown' ),
476 $this->msg( 'protectedpages-unknown-reason' )->escaped()
479 if ( LogEventsList
::userCanBitfield(
481 LogPage
::DELETED_COMMENT
,
484 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
486 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
488 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
489 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
495 throw new MWException( "Unknown field '$field'" );
501 function getQueryInfo() {
502 $conds = $this->mConds
;
503 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
504 'OR pr_expiry IS NULL';
505 $conds[] = 'page_id=pr_page';
506 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
508 if ( $this->sizetype
== 'min' ) {
509 $conds[] = 'page_len>=' . $this->size
;
510 } elseif ( $this->sizetype
== 'max' ) {
511 $conds[] = 'page_len<=' . $this->size
;
514 if ( $this->indefonly
) {
515 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
516 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
518 if ( $this->cascadeonly
) {
519 $conds[] = 'pr_cascade = 1';
521 if ( $this->noredirect
) {
522 $conds[] = 'page_is_redirect = 0';
525 if ( $this->level
) {
526 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
528 if ( !is_null( $this->namespace ) ) {
529 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
533 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ),
549 'join_conds' => array(
550 'log_search' => array(
552 'ls_field' => 'pr_id', 'ls_value = pr_id'
564 public function getTableClass() {
565 return 'TablePager mw-protectedpages';
568 function getIndexField() {
572 function getDefaultSort() {
576 function isFieldSortable( $field ) {
577 // no index for sorting exists