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
{
31 protected $IdLevel = 'level';
32 protected $IdType = 'type';
34 public function __construct() {
35 parent
::__construct( 'Protectedpages' );
38 public function execute( $par ) {
40 $this->outputHeader();
41 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
43 // Purge expired entries on one in every 10 queries
44 if ( !mt_rand( 0, 10 ) ) {
45 Title
::purgeExpiredRestrictions();
48 $request = $this->getRequest();
49 $type = $request->getVal( $this->IdType
);
50 $level = $request->getVal( $this->IdLevel
);
51 $sizetype = $request->getVal( 'sizetype' );
52 $size = $request->getIntOrNull( 'size' );
53 $ns = $request->getIntOrNull( 'namespace' );
54 $indefOnly = $request->getBool( 'indefonly' ) ?
1 : 0;
55 $cascadeOnly = $request->getBool( 'cascadeonly' ) ?
1 : 0;
56 $noRedirect = $request->getBool( 'noredirect' ) ?
1 : 0;
58 $pager = new ProtectedPagesPager(
71 $this->getOutput()->addHTML( $this->showOptions(
82 if ( $pager->getNumRows() ) {
83 $this->getOutput()->addHTML(
84 $pager->getNavigationBar() .
86 $pager->getNavigationBar()
89 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
94 * @param int $namespace
95 * @param string $type Restriction type
96 * @param string $level Restriction level
97 * @param string $sizetype "min" or "max"
99 * @param bool $indefOnly Only indefinite protection
100 * @param bool $cascadeOnly Only cascading protection
101 * @param bool $noRedirect Don't show redirects
102 * @return string Input form
104 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
105 $size, $indefOnly, $cascadeOnly, $noRedirect
109 $title = $this->getPageTitle();
111 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
112 Xml
::openElement( 'fieldset' ) .
113 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
114 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
115 $this->getNamespaceMenu( $namespace ) . " \n" .
116 $this->getTypeMenu( $type ) . " \n" .
117 $this->getLevelMenu( $level ) . " \n" .
118 "<br /><span style='white-space: nowrap'>" .
119 $this->getExpiryCheck( $indefOnly ) . " \n" .
120 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
121 $this->getRedirectCheck( $noRedirect ) . " \n" .
122 "</span><br /><span style='white-space: nowrap'>" .
123 $this->getSizeLimit( $sizetype, $size ) . " \n" .
125 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
126 Xml
::closeElement( 'fieldset' ) .
127 Xml
::closeElement( 'form' );
131 * Prepare the namespace filter drop-down; standard namespace
132 * selector, sans the MediaWiki namespace
134 * @param string|null $namespace Pre-select namespace
137 protected function getNamespaceMenu( $namespace = null ) {
138 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
139 Html
::namespaceSelector(
141 'selected' => $namespace,
143 'label' => $this->msg( 'namespace' )->text()
145 'name' => 'namespace',
147 'class' => 'namespaceselector',
154 * @param bool $indefOnly
155 * @return string Formatted HTML
157 protected function getExpiryCheck( $indefOnly ) {
158 return Xml
::checkLabel(
159 $this->msg( 'protectedpages-indef' )->text(),
167 * @param bool $cascadeOnly
168 * @return string Formatted HTML
170 protected function getCascadeCheck( $cascadeOnly ) {
171 return Xml
::checkLabel(
172 $this->msg( 'protectedpages-cascade' )->text(),
180 * @param bool $noRedirect
181 * @return string Formatted HTML
183 protected function getRedirectCheck( $noRedirect ) {
184 return Xml
::checkLabel(
185 $this->msg( 'protectedpages-noredirect' )->text(),
193 * @param string $sizetype "min" or "max"
195 * @return string Formatted HTML
197 protected function getSizeLimit( $sizetype, $size ) {
198 $max = $sizetype === 'max';
200 return Xml
::radioLabel(
201 $this->msg( 'minimum-size' )->text(),
209 $this->msg( 'maximum-size' )->text(),
216 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
218 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
222 * Creates the input label of the restriction type
223 * @param string $pr_type Protection type
224 * @return string Formatted HTML
226 protected function getTypeMenu( $pr_type ) {
227 $m = array(); // Temporary array
230 // First pass to load the log names
231 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
232 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
233 $text = $this->msg( "restriction-$type" )->text();
237 // Third pass generates sorted XHTML content
238 foreach ( $m as $text => $type ) {
239 $selected = ( $type == $pr_type );
240 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
243 return "<span style='white-space: nowrap'>" .
244 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
246 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
247 implode( "\n", $options ) ) . "</span>";
251 * Creates the input label of the restriction level
252 * @param string $pr_level Protection level
253 * @return string Formatted HTML
255 protected function getLevelMenu( $pr_level ) {
256 global $wgRestrictionLevels;
259 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
262 // First pass to load the log names
263 foreach ( $wgRestrictionLevels as $type ) {
264 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
265 if ( $type != '' && $type != '*' ) {
266 $text = $this->msg( "restriction-level-$type" )->text();
271 // Third pass generates sorted XHTML content
272 foreach ( $m as $text => $type ) {
273 $selected = ( $type == $pr_level );
274 $options[] = Xml
::option( $text, $type, $selected );
277 return "<span style='white-space: nowrap'>" .
278 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
280 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
281 implode( "\n", $options ) ) . "</span>";
284 protected function getGroupName() {
285 return 'maintenance';
293 class ProtectedPagesPager
extends TablePager
{
294 public $mForm, $mConds;
295 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
297 function __construct( $form, $conds = array(), $type, $level, $namespace,
298 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
300 $this->mForm
= $form;
301 $this->mConds
= $conds;
302 $this->type
= ( $type ) ?
$type : 'edit';
303 $this->level
= $level;
304 $this->namespace = $namespace;
305 $this->sizetype
= $sizetype;
306 $this->size
= intval( $size );
307 $this->indefonly
= (bool)$indefonly;
308 $this->cascadeonly
= (bool)$cascadeonly;
309 $this->noredirect
= (bool)$noredirect;
310 parent
::__construct( $form->getContext() );
313 function preprocessResults( $result ) {
314 # Do a link batch query
318 foreach ( $result as $row ) {
319 $lb->add( $row->page_namespace
, $row->page_title
);
320 // field is nullable, maybe null on old protections
321 if ( $row->log_user
!== null ) {
322 $userids[] = $row->log_user
;
326 // fill LinkBatch with user page and user talk
327 if ( count( $userids ) ) {
328 $userCache = UserCache
::singleton();
329 $userCache->doQuery( $userids, array(), __METHOD__
);
330 foreach ( $userids as $userid ) {
331 $name = $userCache->getProp( $userid, 'name' );
332 if ( $name !== false ) {
333 $lb->add( NS_USER
, $name );
334 $lb->add( NS_USER_TALK
, $name );
342 function getFieldNames() {
343 static $headers = null;
345 if ( $headers == array() ) {
347 'log_timestamp' => 'protectedpages-timestamp',
348 'pr_page' => 'protectedpages-page',
349 'pr_expiry' => 'protectedpages-expiry',
350 'log_user' => 'protectedpages-performer',
351 'pr_params' => 'protectedpages-params',
352 'log_comment' => 'protectedpages-reason',
354 foreach ( $headers as $key => $val ) {
355 $headers[$key] = $this->msg( $val )->text();
363 * @param string $field
364 * @param string $value
366 * @throws MWException
368 function formatValue( $field, $value ) {
369 /** @var $row object */
370 $row = $this->mCurrentRow
;
375 case 'log_timestamp':
376 // when timestamp is null, this is a old protection row
377 if ( $value === null ) {
378 $formatted = Html
::rawElement(
380 array( 'class' => 'mw-protectedpages-unknown' ),
381 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
384 $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
389 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
391 $formatted = Html
::element(
393 array( 'class' => 'mw-invalidtitle' ),
394 Linker
::getInvalidTitleDescription(
396 $row->page_namespace
,
401 $formatted = Linker
::link( $title );
403 if ( !is_null( $row->page_len
) ) {
404 $formatted .= $this->getLanguage()->getDirMark() .
405 ' ' . Html
::rawElement(
407 array( 'class' => 'mw-protectedpages-length' ),
408 Linker
::formatRevisionSize( $row->page_len
)
414 $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true );
415 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
416 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
417 $changeProtection = Linker
::linkKnown(
419 $this->msg( 'protect_change' )->escaped(),
421 array( 'action' => 'unprotect' )
423 $formatted .= ' ' . Html
::rawElement(
425 array( 'class' => 'mw-protectedpages-actions' ),
426 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
432 // when timestamp is null, this is a old protection row
433 if ( $row->log_timestamp
=== null ) {
434 $formatted = Html
::rawElement(
436 array( 'class' => 'mw-protectedpages-unknown' ),
437 $this->msg( 'protectedpages-unknown-performer' )->escaped()
440 $username = UserCache
::singleton()->getProp( $value, 'name' );
441 if ( LogEventsList
::userCanBitfield( $row->log_deleted
, LogPage
::DELETED_USER
, $this->getUser() ) ) {
442 if ( $username === false ) {
443 $formatted = htmlspecialchars( $value );
445 $formatted = Linker
::userLink( $value, $username )
446 . Linker
::userToolLinks( $value, $username );
449 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
451 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
452 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
459 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
460 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
461 if ( $row->pr_cascade
) {
462 $params[] = $this->msg( 'protect-summary-cascade' )->text();
464 $formatted = $this->getLanguage()->commaList( $params );
468 // when timestamp is null, this is an old protection row
469 if ( $row->log_timestamp
=== null ) {
470 $formatted = Html
::rawElement(
472 array( 'class' => 'mw-protectedpages-unknown' ),
473 $this->msg( 'protectedpages-unknown-reason' )->escaped()
476 if ( LogEventsList
::userCanBitfield( $row->log_deleted
, LogPage
::DELETED_COMMENT
, $this->getUser() ) ) {
477 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
479 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
481 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
482 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
488 throw new MWException( "Unknown field '$field'" );
494 function getQueryInfo() {
495 $conds = $this->mConds
;
496 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
497 'OR pr_expiry IS NULL';
498 $conds[] = 'page_id=pr_page';
499 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
501 if ( $this->sizetype
== 'min' ) {
502 $conds[] = 'page_len>=' . $this->size
;
503 } elseif ( $this->sizetype
== 'max' ) {
504 $conds[] = 'page_len<=' . $this->size
;
507 if ( $this->indefonly
) {
508 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
509 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
511 if ( $this->cascadeonly
) {
512 $conds[] = 'pr_cascade = 1';
514 if ( $this->noredirect
) {
515 $conds[] = 'page_is_redirect = 0';
518 if ( $this->level
) {
519 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
521 if ( !is_null( $this->namespace ) ) {
522 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
526 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ),
542 'join_conds' => array(
543 'log_search' => array(
545 'ls_field' => 'pr_id', 'ls_value = pr_id'
557 public function getTableClass() {
558 return 'TablePager mw-protectedpages';
561 function getIndexField() {
565 function getDefaultSort() {
569 function isFieldSortable( $field ) {
570 // no index for sorting exists