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
106 $title = $this->getPageTitle();
108 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
109 Xml
::openElement( 'fieldset' ) .
110 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
111 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
112 $this->getNamespaceMenu( $namespace ) . " \n" .
113 $this->getTypeMenu( $type ) . " \n" .
114 $this->getLevelMenu( $level ) . " \n" .
115 "<br /><span style='white-space: nowrap'>" .
116 $this->getExpiryCheck( $indefOnly ) . " \n" .
117 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
118 $this->getRedirectCheck( $noRedirect ) . " \n" .
119 "</span><br /><span style='white-space: nowrap'>" .
120 $this->getSizeLimit( $sizetype, $size ) . " \n" .
122 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
123 Xml
::closeElement( 'fieldset' ) .
124 Xml
::closeElement( 'form' );
128 * Prepare the namespace filter drop-down; standard namespace
129 * selector, sans the MediaWiki namespace
131 * @param string|null $namespace Pre-select namespace
134 protected function getNamespaceMenu( $namespace = null ) {
135 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
136 Html
::namespaceSelector(
138 'selected' => $namespace,
140 'label' => $this->msg( 'namespace' )->text()
142 'name' => 'namespace',
144 'class' => 'namespaceselector',
151 * @param bool $indefOnly
152 * @return string Formatted HTML
154 protected function getExpiryCheck( $indefOnly ) {
155 return Xml
::checkLabel(
156 $this->msg( 'protectedpages-indef' )->text(),
164 * @param bool $cascadeOnly
165 * @return string Formatted HTML
167 protected function getCascadeCheck( $cascadeOnly ) {
168 return Xml
::checkLabel(
169 $this->msg( 'protectedpages-cascade' )->text(),
177 * @param bool $noRedirect
178 * @return string Formatted HTML
180 protected function getRedirectCheck( $noRedirect ) {
181 return Xml
::checkLabel(
182 $this->msg( 'protectedpages-noredirect' )->text(),
190 * @param string $sizetype "min" or "max"
192 * @return string Formatted HTML
194 protected function getSizeLimit( $sizetype, $size ) {
195 $max = $sizetype === 'max';
197 return Xml
::radioLabel(
198 $this->msg( 'minimum-size' )->text(),
206 $this->msg( 'maximum-size' )->text(),
213 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
215 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
219 * Creates the input label of the restriction type
220 * @param string $pr_type Protection type
221 * @return string Formatted HTML
223 protected function getTypeMenu( $pr_type ) {
224 $m = array(); // Temporary array
227 // First pass to load the log names
228 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
229 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
230 $text = $this->msg( "restriction-$type" )->text();
234 // Third pass generates sorted XHTML content
235 foreach ( $m as $text => $type ) {
236 $selected = ( $type == $pr_type );
237 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
240 return "<span style='white-space: nowrap'>" .
241 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
243 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
244 implode( "\n", $options ) ) . "</span>";
248 * Creates the input label of the restriction level
249 * @param string $pr_level Protection level
250 * @return string Formatted HTML
252 protected function getLevelMenu( $pr_level ) {
254 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
257 // First pass to load the log names
258 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
259 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
260 if ( $type != '' && $type != '*' ) {
261 $text = $this->msg( "restriction-level-$type" )->text();
266 // Third pass generates sorted XHTML content
267 foreach ( $m as $text => $type ) {
268 $selected = ( $type == $pr_level );
269 $options[] = Xml
::option( $text, $type, $selected );
272 return "<span style='white-space: nowrap'>" .
273 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
275 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
276 implode( "\n", $options ) ) . "</span>";
279 protected function getGroupName() {
280 return 'maintenance';
288 class ProtectedPagesPager
extends TablePager
{
289 public $mForm, $mConds;
290 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
292 function __construct( $form, $conds = array(), $type, $level, $namespace,
293 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
295 $this->mForm
= $form;
296 $this->mConds
= $conds;
297 $this->type
= ( $type ) ?
$type : 'edit';
298 $this->level
= $level;
299 $this->namespace = $namespace;
300 $this->sizetype
= $sizetype;
301 $this->size
= intval( $size );
302 $this->indefonly
= (bool)$indefonly;
303 $this->cascadeonly
= (bool)$cascadeonly;
304 $this->noredirect
= (bool)$noredirect;
305 parent
::__construct( $form->getContext() );
308 function preprocessResults( $result ) {
309 # Do a link batch query
313 foreach ( $result as $row ) {
314 $lb->add( $row->page_namespace
, $row->page_title
);
315 // field is nullable, maybe null on old protections
316 if ( $row->log_user
!== null ) {
317 $userids[] = $row->log_user
;
321 // fill LinkBatch with user page and user talk
322 if ( count( $userids ) ) {
323 $userCache = UserCache
::singleton();
324 $userCache->doQuery( $userids, array(), __METHOD__
);
325 foreach ( $userids as $userid ) {
326 $name = $userCache->getProp( $userid, 'name' );
327 if ( $name !== false ) {
328 $lb->add( NS_USER
, $name );
329 $lb->add( NS_USER_TALK
, $name );
337 function getFieldNames() {
338 static $headers = null;
340 if ( $headers == array() ) {
342 'log_timestamp' => 'protectedpages-timestamp',
343 'pr_page' => 'protectedpages-page',
344 'pr_expiry' => 'protectedpages-expiry',
345 'log_user' => 'protectedpages-performer',
346 'pr_params' => 'protectedpages-params',
347 'log_comment' => 'protectedpages-reason',
349 foreach ( $headers as $key => $val ) {
350 $headers[$key] = $this->msg( $val )->text();
358 * @param string $field
359 * @param string $value
361 * @throws MWException
363 function formatValue( $field, $value ) {
364 /** @var $row object */
365 $row = $this->mCurrentRow
;
370 case 'log_timestamp':
371 // when timestamp is null, this is a old protection row
372 if ( $value === null ) {
373 $formatted = Html
::rawElement(
375 array( 'class' => 'mw-protectedpages-unknown' ),
376 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
379 $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() );
384 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
386 $formatted = Html
::element(
388 array( 'class' => 'mw-invalidtitle' ),
389 Linker
::getInvalidTitleDescription(
391 $row->page_namespace
,
396 $formatted = Linker
::link( $title );
398 if ( !is_null( $row->page_len
) ) {
399 $formatted .= $this->getLanguage()->getDirMark() .
400 ' ' . Html
::rawElement(
402 array( 'class' => 'mw-protectedpages-length' ),
403 Linker
::formatRevisionSize( $row->page_len
)
409 $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true );
410 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
411 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
412 $changeProtection = Linker
::linkKnown(
414 $this->msg( 'protect_change' )->escaped(),
416 array( 'action' => 'unprotect' )
418 $formatted .= ' ' . Html
::rawElement(
420 array( 'class' => 'mw-protectedpages-actions' ),
421 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
427 // when timestamp is null, this is a old protection row
428 if ( $row->log_timestamp
=== null ) {
429 $formatted = Html
::rawElement(
431 array( 'class' => 'mw-protectedpages-unknown' ),
432 $this->msg( 'protectedpages-unknown-performer' )->escaped()
435 $username = UserCache
::singleton()->getProp( $value, 'name' );
436 if ( LogEventsList
::userCanBitfield(
438 LogPage
::DELETED_USER
,
441 if ( $username === false ) {
442 $formatted = htmlspecialchars( $value );
444 $formatted = Linker
::userLink( $value, $username )
445 . Linker
::userToolLinks( $value, $username );
448 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
450 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
451 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
458 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
459 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
460 if ( $row->pr_cascade
) {
461 $params[] = $this->msg( 'protect-summary-cascade' )->text();
463 $formatted = $this->getLanguage()->commaList( $params );
467 // when timestamp is null, this is an old protection row
468 if ( $row->log_timestamp
=== null ) {
469 $formatted = Html
::rawElement(
471 array( 'class' => 'mw-protectedpages-unknown' ),
472 $this->msg( 'protectedpages-unknown-reason' )->escaped()
475 if ( LogEventsList
::userCanBitfield(
477 LogPage
::DELETED_COMMENT
,
480 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
482 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
484 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
485 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
491 throw new MWException( "Unknown field '$field'" );
497 function getQueryInfo() {
498 $conds = $this->mConds
;
499 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
500 'OR pr_expiry IS NULL';
501 $conds[] = 'page_id=pr_page';
502 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
504 if ( $this->sizetype
== 'min' ) {
505 $conds[] = 'page_len>=' . $this->size
;
506 } elseif ( $this->sizetype
== 'max' ) {
507 $conds[] = 'page_len<=' . $this->size
;
510 if ( $this->indefonly
) {
511 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
512 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
514 if ( $this->cascadeonly
) {
515 $conds[] = 'pr_cascade = 1';
517 if ( $this->noredirect
) {
518 $conds[] = 'page_is_redirect = 0';
521 if ( $this->level
) {
522 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
524 if ( !is_null( $this->namespace ) ) {
525 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
529 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ),
545 'join_conds' => array(
546 'log_search' => array(
548 'ls_field' => 'pr_id', 'ls_value = pr_id'
560 public function getTableClass() {
561 return parent
::getTableClass() . ' mw-protectedpages';
564 function getIndexField() {
568 function getDefaultSort() {
572 function isFieldSortable( $field ) {
573 // no index for sorting exists