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()->addParserOutputContent( $pager->getFullOutput() );
84 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
89 * @param int $namespace
90 * @param string $type Restriction type
91 * @param string $level Restriction level
92 * @param string $sizetype "min" or "max"
94 * @param bool $indefOnly Only indefinite protection
95 * @param bool $cascadeOnly Only cascading protection
96 * @param bool $noRedirect Don't show redirects
97 * @return string Input form
99 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
100 $size, $indefOnly, $cascadeOnly, $noRedirect
102 $title = $this->getPageTitle();
104 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
105 Xml
::openElement( 'fieldset' ) .
106 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
107 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
108 $this->getNamespaceMenu( $namespace ) . " \n" .
109 $this->getTypeMenu( $type ) . " \n" .
110 $this->getLevelMenu( $level ) . " \n" .
111 "<br /><span style='white-space: nowrap'>" .
112 $this->getExpiryCheck( $indefOnly ) . " \n" .
113 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
114 $this->getRedirectCheck( $noRedirect ) . " \n" .
115 "</span><br /><span style='white-space: nowrap'>" .
116 $this->getSizeLimit( $sizetype, $size ) . " \n" .
118 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
119 Xml
::closeElement( 'fieldset' ) .
120 Xml
::closeElement( 'form' );
124 * Prepare the namespace filter drop-down; standard namespace
125 * selector, sans the MediaWiki namespace
127 * @param string|null $namespace Pre-select namespace
130 protected function getNamespaceMenu( $namespace = null ) {
131 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
132 Html
::namespaceSelector(
134 'selected' => $namespace,
136 'label' => $this->msg( 'namespace' )->text()
138 'name' => 'namespace',
140 'class' => 'namespaceselector',
147 * @param bool $indefOnly
148 * @return string Formatted HTML
150 protected function getExpiryCheck( $indefOnly ) {
151 return Xml
::checkLabel(
152 $this->msg( 'protectedpages-indef' )->text(),
160 * @param bool $cascadeOnly
161 * @return string Formatted HTML
163 protected function getCascadeCheck( $cascadeOnly ) {
164 return Xml
::checkLabel(
165 $this->msg( 'protectedpages-cascade' )->text(),
173 * @param bool $noRedirect
174 * @return string Formatted HTML
176 protected function getRedirectCheck( $noRedirect ) {
177 return Xml
::checkLabel(
178 $this->msg( 'protectedpages-noredirect' )->text(),
186 * @param string $sizetype "min" or "max"
188 * @return string Formatted HTML
190 protected function getSizeLimit( $sizetype, $size ) {
191 $max = $sizetype === 'max';
193 return Xml
::radioLabel(
194 $this->msg( 'minimum-size' )->text(),
202 $this->msg( 'maximum-size' )->text(),
209 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
211 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
215 * Creates the input label of the restriction type
216 * @param string $pr_type Protection type
217 * @return string Formatted HTML
219 protected function getTypeMenu( $pr_type ) {
220 $m = array(); // Temporary array
223 // First pass to load the log names
224 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
225 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
226 $text = $this->msg( "restriction-$type" )->text();
230 // Third pass generates sorted XHTML content
231 foreach ( $m as $text => $type ) {
232 $selected = ( $type == $pr_type );
233 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
236 return "<span style='white-space: nowrap'>" .
237 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
239 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
240 implode( "\n", $options ) ) . "</span>";
244 * Creates the input label of the restriction level
245 * @param string $pr_level Protection level
246 * @return string Formatted HTML
248 protected function getLevelMenu( $pr_level ) {
250 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
253 // First pass to load the log names
254 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
255 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
256 if ( $type != '' && $type != '*' ) {
257 $text = $this->msg( "restriction-level-$type" )->text();
262 // Third pass generates sorted XHTML content
263 foreach ( $m as $text => $type ) {
264 $selected = ( $type == $pr_level );
265 $options[] = Xml
::option( $text, $type, $selected );
268 return "<span style='white-space: nowrap'>" .
269 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
271 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
272 implode( "\n", $options ) ) . "</span>";
275 protected function getGroupName() {
276 return 'maintenance';
284 class ProtectedPagesPager
extends TablePager
{
285 public $mForm, $mConds;
286 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
288 function __construct( $form, $conds = array(), $type, $level, $namespace,
289 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
291 $this->mForm
= $form;
292 $this->mConds
= $conds;
293 $this->type
= ( $type ) ?
$type : 'edit';
294 $this->level
= $level;
295 $this->namespace = $namespace;
296 $this->sizetype
= $sizetype;
297 $this->size
= intval( $size );
298 $this->indefonly
= (bool)$indefonly;
299 $this->cascadeonly
= (bool)$cascadeonly;
300 $this->noredirect
= (bool)$noredirect;
301 parent
::__construct( $form->getContext() );
304 function preprocessResults( $result ) {
305 # Do a link batch query
309 foreach ( $result as $row ) {
310 $lb->add( $row->page_namespace
, $row->page_title
);
311 // field is nullable, maybe null on old protections
312 if ( $row->log_user
!== null ) {
313 $userids[] = $row->log_user
;
317 // fill LinkBatch with user page and user talk
318 if ( count( $userids ) ) {
319 $userCache = UserCache
::singleton();
320 $userCache->doQuery( $userids, array(), __METHOD__
);
321 foreach ( $userids as $userid ) {
322 $name = $userCache->getProp( $userid, 'name' );
323 if ( $name !== false ) {
324 $lb->add( NS_USER
, $name );
325 $lb->add( NS_USER_TALK
, $name );
333 function getFieldNames() {
334 static $headers = null;
336 if ( $headers == array() ) {
338 'log_timestamp' => 'protectedpages-timestamp',
339 'pr_page' => 'protectedpages-page',
340 'pr_expiry' => 'protectedpages-expiry',
341 'log_user' => 'protectedpages-performer',
342 'pr_params' => 'protectedpages-params',
343 'log_comment' => 'protectedpages-reason',
345 foreach ( $headers as $key => $val ) {
346 $headers[$key] = $this->msg( $val )->text();
354 * @param string $field
355 * @param string $value
357 * @throws MWException
359 function formatValue( $field, $value ) {
360 /** @var $row object */
361 $row = $this->mCurrentRow
;
366 case 'log_timestamp':
367 // when timestamp is null, this is a old protection row
368 if ( $value === null ) {
369 $formatted = Html
::rawElement(
371 array( 'class' => 'mw-protectedpages-unknown' ),
372 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
375 $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
380 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
382 $formatted = Html
::element(
384 array( 'class' => 'mw-invalidtitle' ),
385 Linker
::getInvalidTitleDescription(
387 $row->page_namespace
,
392 $formatted = Linker
::link( $title );
394 if ( !is_null( $row->page_len
) ) {
395 $formatted .= $this->getLanguage()->getDirMark() .
396 ' ' . Html
::rawElement(
398 array( 'class' => 'mw-protectedpages-length' ),
399 Linker
::formatRevisionSize( $row->page_len
)
405 $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true );
406 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
407 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
408 $changeProtection = Linker
::linkKnown(
410 $this->msg( 'protect_change' )->escaped(),
412 array( 'action' => 'unprotect' )
414 $formatted .= ' ' . Html
::rawElement(
416 array( 'class' => 'mw-protectedpages-actions' ),
417 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
423 // when timestamp is null, this is a old protection row
424 if ( $row->log_timestamp
=== null ) {
425 $formatted = Html
::rawElement(
427 array( 'class' => 'mw-protectedpages-unknown' ),
428 $this->msg( 'protectedpages-unknown-performer' )->escaped()
431 $username = UserCache
::singleton()->getProp( $value, 'name' );
432 if ( LogEventsList
::userCanBitfield(
434 LogPage
::DELETED_USER
,
437 if ( $username === false ) {
438 $formatted = htmlspecialchars( $value );
440 $formatted = Linker
::userLink( $value, $username )
441 . Linker
::userToolLinks( $value, $username );
444 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
446 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
447 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
454 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
455 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
456 if ( $row->pr_cascade
) {
457 $params[] = $this->msg( 'protect-summary-cascade' )->text();
459 $formatted = $this->getLanguage()->commaList( $params );
463 // when timestamp is null, this is an old protection row
464 if ( $row->log_timestamp
=== null ) {
465 $formatted = Html
::rawElement(
467 array( 'class' => 'mw-protectedpages-unknown' ),
468 $this->msg( 'protectedpages-unknown-reason' )->escaped()
471 if ( LogEventsList
::userCanBitfield(
473 LogPage
::DELETED_COMMENT
,
476 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
478 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
480 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
481 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
487 throw new MWException( "Unknown field '$field'" );
493 function getQueryInfo() {
494 $conds = $this->mConds
;
495 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
496 'OR pr_expiry IS NULL';
497 $conds[] = 'page_id=pr_page';
498 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
500 if ( $this->sizetype
== 'min' ) {
501 $conds[] = 'page_len>=' . $this->size
;
502 } elseif ( $this->sizetype
== 'max' ) {
503 $conds[] = 'page_len<=' . $this->size
;
506 if ( $this->indefonly
) {
507 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
508 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
510 if ( $this->cascadeonly
) {
511 $conds[] = 'pr_cascade = 1';
513 if ( $this->noredirect
) {
514 $conds[] = 'page_is_redirect = 0';
517 if ( $this->level
) {
518 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
520 if ( !is_null( $this->namespace ) ) {
521 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
525 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ),
541 'join_conds' => array(
542 'log_search' => array(
544 'ls_field' => 'pr_id', 'ls_value = pr_id'
556 public function getTableClass() {
557 return parent
::getTableClass() . ' mw-protectedpages';
560 function getIndexField() {
564 function getDefaultSort() {
568 function isFieldSortable( $field ) {
569 // no index for sorting exists