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 $request = $this->getRequest();
43 $type = $request->getVal( $this->IdType
);
44 $level = $request->getVal( $this->IdLevel
);
45 $sizetype = $request->getVal( 'sizetype' );
46 $size = $request->getIntOrNull( 'size' );
47 $ns = $request->getIntOrNull( 'namespace' );
48 $indefOnly = $request->getBool( 'indefonly' ) ?
1 : 0;
49 $cascadeOnly = $request->getBool( 'cascadeonly' ) ?
1 : 0;
50 $noRedirect = $request->getBool( 'noredirect' ) ?
1 : 0;
52 $pager = new ProtectedPagesPager(
65 $this->getOutput()->addHTML( $this->showOptions(
76 if ( $pager->getNumRows() ) {
77 $this->getOutput()->addParserOutputContent( $pager->getFullOutput() );
79 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
84 * @param int $namespace
85 * @param string $type Restriction type
86 * @param string $level Restriction level
87 * @param string $sizetype "min" or "max"
89 * @param bool $indefOnly Only indefinite protection
90 * @param bool $cascadeOnly Only cascading protection
91 * @param bool $noRedirect Don't show redirects
92 * @return string Input form
94 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
95 $size, $indefOnly, $cascadeOnly, $noRedirect
97 $title = $this->getPageTitle();
99 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
100 Xml
::openElement( 'fieldset' ) .
101 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
102 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
103 $this->getNamespaceMenu( $namespace ) . " \n" .
104 $this->getTypeMenu( $type ) . " \n" .
105 $this->getLevelMenu( $level ) . " \n" .
106 "<br /><span style='white-space: nowrap'>" .
107 $this->getExpiryCheck( $indefOnly ) . " \n" .
108 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
109 $this->getRedirectCheck( $noRedirect ) . " \n" .
110 "</span><br /><span style='white-space: nowrap'>" .
111 $this->getSizeLimit( $sizetype, $size ) . " \n" .
113 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
114 Xml
::closeElement( 'fieldset' ) .
115 Xml
::closeElement( 'form' );
119 * Prepare the namespace filter drop-down; standard namespace
120 * selector, sans the MediaWiki namespace
122 * @param string|null $namespace Pre-select namespace
125 protected function getNamespaceMenu( $namespace = null ) {
126 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
127 Html
::namespaceSelector(
129 'selected' => $namespace,
131 'label' => $this->msg( 'namespace' )->text()
133 'name' => 'namespace',
135 'class' => 'namespaceselector',
142 * @param bool $indefOnly
143 * @return string Formatted HTML
145 protected function getExpiryCheck( $indefOnly ) {
146 return Xml
::checkLabel(
147 $this->msg( 'protectedpages-indef' )->text(),
155 * @param bool $cascadeOnly
156 * @return string Formatted HTML
158 protected function getCascadeCheck( $cascadeOnly ) {
159 return Xml
::checkLabel(
160 $this->msg( 'protectedpages-cascade' )->text(),
168 * @param bool $noRedirect
169 * @return string Formatted HTML
171 protected function getRedirectCheck( $noRedirect ) {
172 return Xml
::checkLabel(
173 $this->msg( 'protectedpages-noredirect' )->text(),
181 * @param string $sizetype "min" or "max"
183 * @return string Formatted HTML
185 protected function getSizeLimit( $sizetype, $size ) {
186 $max = $sizetype === 'max';
188 return Xml
::radioLabel(
189 $this->msg( 'minimum-size' )->text(),
197 $this->msg( 'maximum-size' )->text(),
204 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
206 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
210 * Creates the input label of the restriction type
211 * @param string $pr_type Protection type
212 * @return string Formatted HTML
214 protected function getTypeMenu( $pr_type ) {
215 $m = array(); // Temporary array
218 // First pass to load the log names
219 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
220 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
221 $text = $this->msg( "restriction-$type" )->text();
225 // Third pass generates sorted XHTML content
226 foreach ( $m as $text => $type ) {
227 $selected = ( $type == $pr_type );
228 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
231 return "<span style='white-space: nowrap'>" .
232 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
234 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
235 implode( "\n", $options ) ) . "</span>";
239 * Creates the input label of the restriction level
240 * @param string $pr_level Protection level
241 * @return string Formatted HTML
243 protected function getLevelMenu( $pr_level ) {
245 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
248 // First pass to load the log names
249 foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
250 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
251 if ( $type != '' && $type != '*' ) {
252 $text = $this->msg( "restriction-level-$type" )->text();
257 // Third pass generates sorted XHTML content
258 foreach ( $m as $text => $type ) {
259 $selected = ( $type == $pr_level );
260 $options[] = Xml
::option( $text, $type, $selected );
263 return "<span style='white-space: nowrap'>" .
264 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
266 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
267 implode( "\n", $options ) ) . "</span>";
270 protected function getGroupName() {
271 return 'maintenance';
279 class ProtectedPagesPager
extends TablePager
{
280 public $mForm, $mConds;
281 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
283 function __construct( $form, $conds = array(), $type, $level, $namespace,
284 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
286 $this->mForm
= $form;
287 $this->mConds
= $conds;
288 $this->type
= ( $type ) ?
$type : 'edit';
289 $this->level
= $level;
290 $this->namespace = $namespace;
291 $this->sizetype
= $sizetype;
292 $this->size
= intval( $size );
293 $this->indefonly
= (bool)$indefonly;
294 $this->cascadeonly
= (bool)$cascadeonly;
295 $this->noredirect
= (bool)$noredirect;
296 parent
::__construct( $form->getContext() );
299 function preprocessResults( $result ) {
300 # Do a link batch query
304 foreach ( $result as $row ) {
305 $lb->add( $row->page_namespace
, $row->page_title
);
306 // field is nullable, maybe null on old protections
307 if ( $row->log_user
!== null ) {
308 $userids[] = $row->log_user
;
312 // fill LinkBatch with user page and user talk
313 if ( count( $userids ) ) {
314 $userCache = UserCache
::singleton();
315 $userCache->doQuery( $userids, array(), __METHOD__
);
316 foreach ( $userids as $userid ) {
317 $name = $userCache->getProp( $userid, 'name' );
318 if ( $name !== false ) {
319 $lb->add( NS_USER
, $name );
320 $lb->add( NS_USER_TALK
, $name );
328 function getFieldNames() {
329 static $headers = null;
331 if ( $headers == array() ) {
333 'log_timestamp' => 'protectedpages-timestamp',
334 'pr_page' => 'protectedpages-page',
335 'pr_expiry' => 'protectedpages-expiry',
336 'log_user' => 'protectedpages-performer',
337 'pr_params' => 'protectedpages-params',
338 'log_comment' => 'protectedpages-reason',
340 foreach ( $headers as $key => $val ) {
341 $headers[$key] = $this->msg( $val )->text();
349 * @param string $field
350 * @param string $value
351 * @return string HTML
352 * @throws MWException
354 function formatValue( $field, $value ) {
355 /** @var $row object */
356 $row = $this->mCurrentRow
;
361 case 'log_timestamp':
362 // when timestamp is null, this is a old protection row
363 if ( $value === null ) {
364 $formatted = Html
::rawElement(
366 array( 'class' => 'mw-protectedpages-unknown' ),
367 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
370 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
371 $value, $this->getUser() ) );
376 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
378 $formatted = Html
::element(
380 array( 'class' => 'mw-invalidtitle' ),
381 Linker
::getInvalidTitleDescription(
383 $row->page_namespace
,
388 $formatted = Linker
::link( $title );
390 if ( !is_null( $row->page_len
) ) {
391 $formatted .= $this->getLanguage()->getDirMark() .
392 ' ' . Html
::rawElement(
394 array( 'class' => 'mw-protectedpages-length' ),
395 Linker
::formatRevisionSize( $row->page_len
)
401 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
402 $value, /* User preference timezone */true ) );
403 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
404 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
405 $changeProtection = Linker
::linkKnown(
407 $this->msg( 'protect_change' )->escaped(),
409 array( 'action' => 'unprotect' )
411 $formatted .= ' ' . Html
::rawElement(
413 array( 'class' => 'mw-protectedpages-actions' ),
414 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
420 // when timestamp is null, this is a old protection row
421 if ( $row->log_timestamp
=== null ) {
422 $formatted = Html
::rawElement(
424 array( 'class' => 'mw-protectedpages-unknown' ),
425 $this->msg( 'protectedpages-unknown-performer' )->escaped()
428 $username = UserCache
::singleton()->getProp( $value, 'name' );
429 if ( LogEventsList
::userCanBitfield(
431 LogPage
::DELETED_USER
,
434 if ( $username === false ) {
435 $formatted = htmlspecialchars( $value );
437 $formatted = Linker
::userLink( $value, $username )
438 . Linker
::userToolLinks( $value, $username );
441 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
443 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
444 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
451 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
452 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
453 if ( $row->pr_cascade
) {
454 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
456 $formatted = $this->getLanguage()->commaList( $params );
460 // when timestamp is null, this is an old protection row
461 if ( $row->log_timestamp
=== null ) {
462 $formatted = Html
::rawElement(
464 array( 'class' => 'mw-protectedpages-unknown' ),
465 $this->msg( 'protectedpages-unknown-reason' )->escaped()
468 if ( LogEventsList
::userCanBitfield(
470 LogPage
::DELETED_COMMENT
,
473 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
475 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
477 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
478 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
484 throw new MWException( "Unknown field '$field'" );
490 function getQueryInfo() {
491 $conds = $this->mConds
;
492 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
493 ' OR pr_expiry IS NULL';
494 $conds[] = 'page_id=pr_page';
495 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
497 if ( $this->sizetype
== 'min' ) {
498 $conds[] = 'page_len>=' . $this->size
;
499 } elseif ( $this->sizetype
== 'max' ) {
500 $conds[] = 'page_len<=' . $this->size
;
503 if ( $this->indefonly
) {
504 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
505 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
507 if ( $this->cascadeonly
) {
508 $conds[] = 'pr_cascade = 1';
510 if ( $this->noredirect
) {
511 $conds[] = 'page_is_redirect = 0';
514 if ( $this->level
) {
515 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
517 if ( !is_null( $this->namespace ) ) {
518 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
522 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ),
538 'join_conds' => array(
539 'log_search' => array(
541 'ls_field' => 'pr_id', 'ls_value = pr_id'
553 public function getTableClass() {
554 return parent
::getTableClass() . ' mw-protectedpages';
557 function getIndexField() {
561 function getDefaultSort() {
565 function isFieldSortable( $field ) {
566 // no index for sorting exists