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;
56 $pager = new ProtectedPagesPager(
68 $this->getOutput()->addHTML( $this->showOptions(
78 if ( $pager->getNumRows() ) {
79 $this->getOutput()->addHTML(
80 $pager->getNavigationBar() .
81 '<ul>' . $pager->getBody() . '</ul>' .
82 $pager->getNavigationBar()
85 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
90 * Callback function to output a restriction
91 * @param Title $row Protected title
92 * @return string Formatted "<li>" element
94 public function formatRow( $row ) {
95 wfProfileIn( __METHOD__
);
97 static $infinity = null;
99 if ( is_null( $infinity ) ) {
100 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
103 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
105 wfProfileOut( __METHOD__
);
107 return Html
::rawElement(
112 array( 'class' => 'mw-invalidtitle' ),
113 Linker
::getInvalidTitleDescription(
115 $row->page_namespace
,
122 $link = Linker
::link( $title );
124 $description_items = array();
126 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
127 $protType = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
129 $description_items[] = $protType;
131 if ( $row->pr_cascade
) {
132 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
136 $lang = $this->getLanguage();
138 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
139 if ( $expiry != $infinity ) {
140 $user = $this->getUser();
141 $description_items[] = $this->msg(
142 'protect-expiring-local',
143 $lang->userTimeAndDate( $expiry, $user ),
144 $lang->userDate( $expiry, $user ),
145 $lang->userTime( $expiry, $user )
149 if ( !is_null( $size = $row->page_len
) ) {
150 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
153 // Show a link to the change protection form for allowed users otherwise
154 // a link to the protection log
155 if ( $this->getUser()->isAllowed( 'protect' ) ) {
156 $changeProtection = Linker
::linkKnown(
158 $this->msg( 'protect_change' )->escaped(),
160 array( 'action' => 'unprotect' )
163 $ltitle = SpecialPage
::getTitleFor( 'Log' );
164 $changeProtection = Linker
::linkKnown(
166 $this->msg( 'protectlogpage' )->escaped(),
170 'page' => $title->getPrefixedText()
175 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )
178 wfProfileOut( __METHOD__
);
180 return Html
::rawElement(
183 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) .
189 * @param $namespace Integer
190 * @param string $type restriction type
191 * @param string $level restriction level
192 * @param string $sizetype "min" or "max"
193 * @param $size Integer
194 * @param $indefOnly Boolean: only indefinie protection
195 * @param $cascadeOnly Boolean: only cascading protection
196 * @return String: input form
198 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
199 $size, $indefOnly, $cascadeOnly
203 $title = $this->getTitle();
205 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
206 Xml
::openElement( 'fieldset' ) .
207 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
208 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
209 $this->getNamespaceMenu( $namespace ) . " \n" .
210 $this->getTypeMenu( $type ) . " \n" .
211 $this->getLevelMenu( $level ) . " \n" .
212 "<br /><span style='white-space: nowrap'>" .
213 $this->getExpiryCheck( $indefOnly ) . " \n" .
214 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
215 "</span><br /><span style='white-space: nowrap'>" .
216 $this->getSizeLimit( $sizetype, $size ) . " \n" .
218 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
219 Xml
::closeElement( 'fieldset' ) .
220 Xml
::closeElement( 'form' );
224 * Prepare the namespace filter drop-down; standard namespace
225 * selector, sans the MediaWiki namespace
227 * @param $namespace Mixed: pre-select namespace
230 protected function getNamespaceMenu( $namespace = null ) {
231 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
232 Html
::namespaceSelector(
234 'selected' => $namespace,
236 'label' => $this->msg( 'namespace' )->text()
238 'name' => 'namespace',
240 'class' => 'namespaceselector',
247 * @param bool $indefOnly
248 * @return string Formatted HTML
250 protected function getExpiryCheck( $indefOnly ) {
251 return Xml
::checkLabel(
252 $this->msg( 'protectedpages-indef' )->text(),
260 * @param bool $cascadeOnly
261 * @return string Formatted HTML
263 protected function getCascadeCheck( $cascadeOnly ) {
264 return Xml
::checkLabel(
265 $this->msg( 'protectedpages-cascade' )->text(),
273 * @param string $sizetype "min" or "max"
275 * @return string Formatted HTML
277 protected function getSizeLimit( $sizetype, $size ) {
278 $max = $sizetype === 'max';
280 return Xml
::radioLabel(
281 $this->msg( 'minimum-size' )->text(),
289 $this->msg( 'maximum-size' )->text(),
296 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
298 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
302 * Creates the input label of the restriction type
303 * @param $pr_type string Protection type
304 * @return string Formatted HTML
306 protected function getTypeMenu( $pr_type ) {
307 $m = array(); // Temporary array
310 // First pass to load the log names
311 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
312 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload
313 $text = $this->msg( "restriction-$type" )->text();
317 // Third pass generates sorted XHTML content
318 foreach ( $m as $text => $type ) {
319 $selected = ( $type == $pr_type );
320 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
323 return "<span style='white-space: nowrap'>" .
324 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
326 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
327 implode( "\n", $options ) ) . "</span>";
331 * Creates the input label of the restriction level
332 * @param $pr_level string Protection level
333 * @return string Formatted HTML
335 protected function getLevelMenu( $pr_level ) {
336 global $wgRestrictionLevels;
339 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
342 // First pass to load the log names
343 foreach ( $wgRestrictionLevels as $type ) {
344 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
345 if ( $type != '' && $type != '*' ) {
346 $text = $this->msg( "restriction-level-$type" )->text();
351 // Third pass generates sorted XHTML content
352 foreach ( $m as $text => $type ) {
353 $selected = ( $type == $pr_level );
354 $options[] = Xml
::option( $text, $type, $selected );
357 return "<span style='white-space: nowrap'>" .
358 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
360 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
361 implode( "\n", $options ) ) . "</span>";
364 protected function getGroupName() {
365 return 'maintenance';
373 class ProtectedPagesPager
extends AlphabeticPager
{
374 public $mForm, $mConds;
375 private $type, $level, $namespace, $sizetype, $size, $indefonly;
377 function __construct( $form, $conds = array(), $type, $level, $namespace,
378 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false
380 $this->mForm
= $form;
381 $this->mConds
= $conds;
382 $this->type
= ( $type ) ?
$type : 'edit';
383 $this->level
= $level;
384 $this->namespace = $namespace;
385 $this->sizetype
= $sizetype;
386 $this->size
= intval( $size );
387 $this->indefonly
= (bool)$indefonly;
388 $this->cascadeonly
= (bool)$cascadeonly;
389 parent
::__construct( $form->getContext() );
392 function getStartBody() {
393 # Do a link batch query
395 foreach ( $this->mResult
as $row ) {
396 $lb->add( $row->page_namespace
, $row->page_title
);
403 function formatRow( $row ) {
404 return $this->mForm
->formatRow( $row );
407 function getQueryInfo() {
408 $conds = $this->mConds
;
409 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
410 'OR pr_expiry IS NULL)';
411 $conds[] = 'page_id=pr_page';
412 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
414 if ( $this->sizetype
== 'min' ) {
415 $conds[] = 'page_len>=' . $this->size
;
416 } elseif ( $this->sizetype
== 'max' ) {
417 $conds[] = 'page_len<=' . $this->size
;
420 if ( $this->indefonly
) {
421 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
422 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
424 if ( $this->cascadeonly
) {
425 $conds[] = 'pr_cascade = 1';
428 if ( $this->level
) {
429 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
431 if ( !is_null( $this->namespace ) ) {
432 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
436 'tables' => array( 'page_restrictions', 'page' ),
437 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len',
438 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ),
443 function getIndexField() {