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 $protType = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
128 $description_items[] = $protType;
130 if ( $row->pr_cascade
) {
131 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
135 $lang = $this->getLanguage();
137 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
138 if ( $expiry != $infinity ) {
139 $user = $this->getUser();
140 $description_items[] = $this->msg(
141 'protect-expiring-local',
142 $lang->userTimeAndDate( $expiry, $user ),
143 $lang->userDate( $expiry, $user ),
144 $lang->userTime( $expiry, $user )
148 if ( !is_null( $size = $row->page_len
) ) {
149 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
152 # Show a link to the change protection form for allowed users otherwise
153 # a link to the protection log
154 if ( $this->getUser()->isAllowed( 'protect' ) ) {
155 $changeProtection = Linker
::linkKnown(
157 $this->msg( 'protect_change' )->escaped(),
159 array( 'action' => 'unprotect' )
162 $ltitle = SpecialPage
::getTitleFor( 'Log' );
163 $changeProtection = Linker
::linkKnown(
165 $this->msg( 'protectlogpage' )->escaped(),
169 'page' => $title->getPrefixedText()
174 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )
177 wfProfileOut( __METHOD__
);
179 return Html
::rawElement(
182 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) .
188 * @param $namespace Integer
189 * @param string $type restriction type
190 * @param string $level restriction level
191 * @param string $sizetype "min" or "max"
192 * @param $size Integer
193 * @param $indefOnly Boolean: only indefinie protection
194 * @param $cascadeOnly Boolean: only cascading protection
195 * @return String: input form
197 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
198 $size, $indefOnly, $cascadeOnly
202 $title = $this->getTitle();
204 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
205 Xml
::openElement( 'fieldset' ) .
206 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
207 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
208 $this->getNamespaceMenu( $namespace ) . " \n" .
209 $this->getTypeMenu( $type ) . " \n" .
210 $this->getLevelMenu( $level ) . " \n" .
211 "<br /><span style='white-space: nowrap'>" .
212 $this->getExpiryCheck( $indefOnly ) . " \n" .
213 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
214 "</span><br /><span style='white-space: nowrap'>" .
215 $this->getSizeLimit( $sizetype, $size ) . " \n" .
217 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
218 Xml
::closeElement( 'fieldset' ) .
219 Xml
::closeElement( 'form' );
223 * Prepare the namespace filter drop-down; standard namespace
224 * selector, sans the MediaWiki namespace
226 * @param $namespace Mixed: pre-select namespace
229 protected function getNamespaceMenu( $namespace = null ) {
230 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
231 Html
::namespaceSelector(
233 'selected' => $namespace,
235 'label' => $this->msg( 'namespace' )->text()
237 'name' => 'namespace',
239 'class' => 'namespaceselector',
246 * @param bool $indefOnly
247 * @return string Formatted HTML
249 protected function getExpiryCheck( $indefOnly ) {
250 return Xml
::checkLabel(
251 $this->msg( 'protectedpages-indef' )->text(),
259 * @param bool $cascadeOnly
260 * @return string Formatted HTML
262 protected function getCascadeCheck( $cascadeOnly ) {
263 return Xml
::checkLabel(
264 $this->msg( 'protectedpages-cascade' )->text(),
272 * @param string $sizetype "min" or "max"
274 * @return string Formatted HTML
276 protected function getSizeLimit( $sizetype, $size ) {
277 $max = $sizetype === 'max';
279 return Xml
::radioLabel(
280 $this->msg( 'minimum-size' )->text(),
288 $this->msg( 'maximum-size' )->text(),
295 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
297 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
301 * Creates the input label of the restriction type
302 * @param $pr_type string Protection type
303 * @return string Formatted HTML
305 protected function getTypeMenu( $pr_type ) {
306 $m = array(); // Temporary array
309 // First pass to load the log names
310 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
311 $text = $this->msg( "restriction-$type" )->text();
315 // Third pass generates sorted XHTML content
316 foreach ( $m as $text => $type ) {
317 $selected = ( $type == $pr_type );
318 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
321 return "<span style='white-space: nowrap'>" .
322 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
324 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
325 implode( "\n", $options ) ) . "</span>";
329 * Creates the input label of the restriction level
330 * @param $pr_level string Protection level
331 * @return string Formatted HTML
333 protected function getLevelMenu( $pr_level ) {
334 global $wgRestrictionLevels;
337 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
340 // First pass to load the log names
341 foreach ( $wgRestrictionLevels as $type ) {
342 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
343 if ( $type != '' && $type != '*' ) {
344 $text = $this->msg( "restriction-level-$type" )->text();
349 // Third pass generates sorted XHTML content
350 foreach ( $m as $text => $type ) {
351 $selected = ( $type == $pr_level );
352 $options[] = Xml
::option( $text, $type, $selected );
355 return "<span style='white-space: nowrap'>" .
356 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
358 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
359 implode( "\n", $options ) ) . "</span>";
362 protected function getGroupName() {
363 return 'maintenance';
371 class ProtectedPagesPager
extends AlphabeticPager
{
372 public $mForm, $mConds;
373 private $type, $level, $namespace, $sizetype, $size, $indefonly;
375 function __construct( $form, $conds = array(), $type, $level, $namespace,
376 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false
378 $this->mForm
= $form;
379 $this->mConds
= $conds;
380 $this->type
= ( $type ) ?
$type : 'edit';
381 $this->level
= $level;
382 $this->namespace = $namespace;
383 $this->sizetype
= $sizetype;
384 $this->size
= intval( $size );
385 $this->indefonly
= (bool)$indefonly;
386 $this->cascadeonly
= (bool)$cascadeonly;
387 parent
::__construct( $form->getContext() );
390 function getStartBody() {
391 # Do a link batch query
393 foreach ( $this->mResult
as $row ) {
394 $lb->add( $row->page_namespace
, $row->page_title
);
401 function formatRow( $row ) {
402 return $this->mForm
->formatRow( $row );
405 function getQueryInfo() {
406 $conds = $this->mConds
;
407 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
408 'OR pr_expiry IS NULL)';
409 $conds[] = 'page_id=pr_page';
410 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
412 if ( $this->sizetype
== 'min' ) {
413 $conds[] = 'page_len>=' . $this->size
;
414 } elseif ( $this->sizetype
== 'max' ) {
415 $conds[] = 'page_len<=' . $this->size
;
418 if ( $this->indefonly
) {
419 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
420 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
422 if ( $this->cascadeonly
) {
423 $conds[] = 'pr_cascade = 1';
426 if ( $this->level
) {
427 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
429 if ( !is_null( $this->namespace ) ) {
430 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
434 'tables' => array( 'page_restrictions', 'page' ),
435 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len',
436 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ),
441 function getIndexField() {