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();
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() .
84 '<ul>' . $pager->getBody() . '</ul>' .
85 $pager->getNavigationBar()
88 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
93 * Callback function to output a restriction
94 * @param Title $row Protected title
95 * @return string Formatted "<li>" element
97 public function formatRow( $row ) {
98 wfProfileIn( __METHOD__
);
100 static $infinity = null;
102 if ( is_null( $infinity ) ) {
103 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
106 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
108 wfProfileOut( __METHOD__
);
110 return Html
::rawElement(
115 array( 'class' => 'mw-invalidtitle' ),
116 Linker
::getInvalidTitleDescription(
118 $row->page_namespace
,
125 $link = Linker
::link( $title );
127 $description_items = array();
129 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
130 $protType = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
132 $description_items[] = $protType;
134 if ( $row->pr_cascade
) {
135 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
139 $lang = $this->getLanguage();
141 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
142 if ( $expiry != $infinity ) {
143 $user = $this->getUser();
144 $description_items[] = $this->msg(
145 'protect-expiring-local',
146 $lang->userTimeAndDate( $expiry, $user ),
147 $lang->userDate( $expiry, $user ),
148 $lang->userTime( $expiry, $user )
152 if ( !is_null( $size = $row->page_len
) ) {
153 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
156 // Show a link to the change protection form for allowed users otherwise
157 // a link to the protection log
158 if ( $this->getUser()->isAllowed( 'protect' ) ) {
159 $changeProtection = Linker
::linkKnown(
161 $this->msg( 'protect_change' )->escaped(),
163 array( 'action' => 'unprotect' )
166 $ltitle = SpecialPage
::getTitleFor( 'Log' );
167 $changeProtection = Linker
::linkKnown(
169 $this->msg( 'protectlogpage' )->escaped(),
173 'page' => $title->getPrefixedText()
178 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )
181 wfProfileOut( __METHOD__
);
183 return Html
::rawElement(
186 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) .
192 * @param int $namespace
193 * @param string $type Restriction type
194 * @param string $level Restriction level
195 * @param string $sizetype "min" or "max"
197 * @param bool $indefOnly Only indefinite protection
198 * @param bool $cascadeOnly Only cascading protection
199 * @param bool $noRedirect Don't show redirects
200 * @return String: input form
202 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
203 $size, $indefOnly, $cascadeOnly, $noRedirect
207 $title = $this->getPageTitle();
209 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
210 Xml
::openElement( 'fieldset' ) .
211 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
212 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
213 $this->getNamespaceMenu( $namespace ) . " \n" .
214 $this->getTypeMenu( $type ) . " \n" .
215 $this->getLevelMenu( $level ) . " \n" .
216 "<br /><span style='white-space: nowrap'>" .
217 $this->getExpiryCheck( $indefOnly ) . " \n" .
218 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
219 $this->getRedirectCheck( $noRedirect ) . " \n" .
220 "</span><br /><span style='white-space: nowrap'>" .
221 $this->getSizeLimit( $sizetype, $size ) . " \n" .
223 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
224 Xml
::closeElement( 'fieldset' ) .
225 Xml
::closeElement( 'form' );
229 * Prepare the namespace filter drop-down; standard namespace
230 * selector, sans the MediaWiki namespace
232 * @param $namespace Mixed: pre-select namespace
235 protected function getNamespaceMenu( $namespace = null ) {
236 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
237 Html
::namespaceSelector(
239 'selected' => $namespace,
241 'label' => $this->msg( 'namespace' )->text()
243 'name' => 'namespace',
245 'class' => 'namespaceselector',
252 * @param bool $indefOnly
253 * @return string Formatted HTML
255 protected function getExpiryCheck( $indefOnly ) {
256 return Xml
::checkLabel(
257 $this->msg( 'protectedpages-indef' )->text(),
265 * @param bool $cascadeOnly
266 * @return string Formatted HTML
268 protected function getCascadeCheck( $cascadeOnly ) {
269 return Xml
::checkLabel(
270 $this->msg( 'protectedpages-cascade' )->text(),
278 * @param bool $noRedirect
279 * @return string Formatted HTML
281 protected function getRedirectCheck( $noRedirect ) {
282 return Xml
::checkLabel(
283 $this->msg( 'protectedpages-noredirect' )->text(),
291 * @param string $sizetype "min" or "max"
293 * @return string Formatted HTML
295 protected function getSizeLimit( $sizetype, $size ) {
296 $max = $sizetype === 'max';
298 return Xml
::radioLabel(
299 $this->msg( 'minimum-size' )->text(),
307 $this->msg( 'maximum-size' )->text(),
314 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
316 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
320 * Creates the input label of the restriction type
321 * @param $pr_type string Protection type
322 * @return string Formatted HTML
324 protected function getTypeMenu( $pr_type ) {
325 $m = array(); // Temporary array
328 // First pass to load the log names
329 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
330 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
331 $text = $this->msg( "restriction-$type" )->text();
335 // Third pass generates sorted XHTML content
336 foreach ( $m as $text => $type ) {
337 $selected = ( $type == $pr_type );
338 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
341 return "<span style='white-space: nowrap'>" .
342 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
344 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
345 implode( "\n", $options ) ) . "</span>";
349 * Creates the input label of the restriction level
350 * @param $pr_level string Protection level
351 * @return string Formatted HTML
353 protected function getLevelMenu( $pr_level ) {
354 global $wgRestrictionLevels;
357 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
360 // First pass to load the log names
361 foreach ( $wgRestrictionLevels as $type ) {
362 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
363 if ( $type != '' && $type != '*' ) {
364 $text = $this->msg( "restriction-level-$type" )->text();
369 // Third pass generates sorted XHTML content
370 foreach ( $m as $text => $type ) {
371 $selected = ( $type == $pr_level );
372 $options[] = Xml
::option( $text, $type, $selected );
375 return "<span style='white-space: nowrap'>" .
376 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
378 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
379 implode( "\n", $options ) ) . "</span>";
382 protected function getGroupName() {
383 return 'maintenance';
391 class ProtectedPagesPager
extends AlphabeticPager
{
392 public $mForm, $mConds;
393 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
395 function __construct( $form, $conds = array(), $type, $level, $namespace,
396 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false
398 $this->mForm
= $form;
399 $this->mConds
= $conds;
400 $this->type
= ( $type ) ?
$type : 'edit';
401 $this->level
= $level;
402 $this->namespace = $namespace;
403 $this->sizetype
= $sizetype;
404 $this->size
= intval( $size );
405 $this->indefonly
= (bool)$indefonly;
406 $this->cascadeonly
= (bool)$cascadeonly;
407 $this->noredirect
= (bool)$noredirect;
408 parent
::__construct( $form->getContext() );
411 function getStartBody() {
412 # Do a link batch query
414 foreach ( $this->mResult
as $row ) {
415 $lb->add( $row->page_namespace
, $row->page_title
);
422 function formatRow( $row ) {
423 return $this->mForm
->formatRow( $row );
426 function getQueryInfo() {
427 $conds = $this->mConds
;
428 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
429 'OR pr_expiry IS NULL';
430 $conds[] = 'page_id=pr_page';
431 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
433 if ( $this->sizetype
== 'min' ) {
434 $conds[] = 'page_len>=' . $this->size
;
435 } elseif ( $this->sizetype
== 'max' ) {
436 $conds[] = 'page_len<=' . $this->size
;
439 if ( $this->indefonly
) {
440 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
441 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
443 if ( $this->cascadeonly
) {
444 $conds[] = 'pr_cascade = 1';
446 if ( $this->noredirect
) {
447 $conds[] = 'page_is_redirect = 0';
450 if ( $this->level
) {
451 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
453 if ( !is_null( $this->namespace ) ) {
454 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
458 'tables' => array( 'page_restrictions', 'page' ),
459 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len',
460 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ),
465 function getIndexField() {