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( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
58 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
60 if ( $pager->getNumRows() ) {
61 $this->getOutput()->addHTML(
62 $pager->getNavigationBar() .
63 '<ul>' . $pager->getBody() . '</ul>' .
64 $pager->getNavigationBar()
67 $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
72 * Callback function to output a restriction
73 * @param Title $row Protected title
74 * @return string Formatted "<li>" element
76 public function formatRow( $row ) {
77 wfProfileIn( __METHOD__
);
79 static $infinity = null;
81 if ( is_null( $infinity ) ) {
82 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
85 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
87 wfProfileOut( __METHOD__
);
88 return Html
::rawElement( 'li', array(),
89 Html
::element( 'span', array( 'class' => 'mw-invalidtitle' ),
90 Linker
::getInvalidTitleDescription( $this->getContext(), $row->page_namespace
, $row->page_title
) ) ) . "\n";
93 $link = Linker
::link( $title );
95 $description_items = array();
97 $protType = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
99 $description_items[] = $protType;
101 if ( $row->pr_cascade
) {
102 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
106 $lang = $this->getLanguage();
108 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
109 if ( $expiry != $infinity ) {
110 $user = $this->getUser();
111 $description_items[] = $this->msg(
112 'protect-expiring-local',
113 $lang->userTimeAndDate( $expiry, $user ),
114 $lang->userDate( $expiry, $user ),
115 $lang->userTime( $expiry, $user )
119 if ( !is_null( $size = $row->page_len
) ) {
120 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
123 # Show a link to the change protection form for allowed users otherwise a link to the protection log
124 if ( $this->getUser()->isAllowed( 'protect' ) ) {
125 $changeProtection = Linker
::linkKnown(
127 $this->msg( 'protect_change' )->escaped(),
129 array( 'action' => 'unprotect' )
132 $ltitle = SpecialPage
::getTitleFor( 'Log' );
133 $changeProtection = Linker
::linkKnown(
135 $this->msg( 'protectlogpage' )->escaped(),
139 'page' => $title->getPrefixedText()
144 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped();
146 wfProfileOut( __METHOD__
);
148 return Html
::rawElement(
151 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
155 * @param $namespace Integer
156 * @param string $type restriction type
157 * @param string $level restriction level
158 * @param string $sizetype "min" or "max"
159 * @param $size Integer
160 * @param $indefOnly Boolean: only indefinie protection
161 * @param $cascadeOnly Boolean: only cascading protection
162 * @return String: input form
164 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
166 $title = $this->getTitle();
167 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
168 Xml
::openElement( 'fieldset' ) .
169 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
170 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
171 $this->getNamespaceMenu( $namespace ) . " \n" .
172 $this->getTypeMenu( $type ) . " \n" .
173 $this->getLevelMenu( $level ) . " \n" .
174 "<br /><span style='white-space: nowrap'>" .
175 $this->getExpiryCheck( $indefOnly ) . " \n" .
176 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
177 "</span><br /><span style='white-space: nowrap'>" .
178 $this->getSizeLimit( $sizetype, $size ) . " \n" .
180 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
181 Xml
::closeElement( 'fieldset' ) .
182 Xml
::closeElement( 'form' );
186 * Prepare the namespace filter drop-down; standard namespace
187 * selector, sans the MediaWiki namespace
189 * @param $namespace Mixed: pre-select namespace
192 protected function getNamespaceMenu( $namespace = null ) {
193 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
194 Html
::namespaceSelector(
196 'selected' => $namespace,
198 'label' => $this->msg( 'namespace' )->text()
200 'name' => 'namespace',
202 'class' => 'namespaceselector',
209 * @param bool $indefOnly
210 * @return string Formatted HTML
212 protected function getExpiryCheck( $indefOnly ) {
213 return Xml
::checkLabel( $this->msg( 'protectedpages-indef' )->text(), 'indefonly', 'indefonly', $indefOnly ) . "\n";
217 * @param bool $cascadeOnly
218 * @return string Formatted HTML
220 protected function getCascadeCheck( $cascadeOnly ) {
221 return Xml
::checkLabel( $this->msg( 'protectedpages-cascade' )->text(), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
225 * @param string $sizetype "min" or "max"
227 * @return string Formatted HTML
229 protected function getSizeLimit( $sizetype, $size ) {
230 $max = $sizetype === 'max';
232 return Xml
::radioLabel( $this->msg( 'minimum-size' )->text(), 'sizetype', 'min', 'wpmin', !$max ) .
234 Xml
::radioLabel( $this->msg( 'maximum-size' )->text(), 'sizetype', 'max', 'wpmax', $max ) .
236 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
238 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
242 * Creates the input label of the restriction type
243 * @param $pr_type string Protection type
244 * @return string Formatted HTML
246 protected function getTypeMenu( $pr_type ) {
247 $m = array(); // Temporary array
250 // First pass to load the log names
251 foreach ( Title
::getFilteredRestrictionTypes( true ) as $type ) {
252 $text = $this->msg( "restriction-$type" )->text();
256 // Third pass generates sorted XHTML content
257 foreach ( $m as $text => $type ) {
258 $selected = ($type == $pr_type );
259 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
262 return "<span style='white-space: nowrap'>" .
263 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
265 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
266 implode( "\n", $options ) ) . "</span>";
270 * Creates the input label of the restriction level
271 * @param $pr_level string Protection level
272 * @return string Formatted HTML
274 protected function getLevelMenu( $pr_level ) {
275 global $wgRestrictionLevels;
277 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
280 // First pass to load the log names
281 foreach ( $wgRestrictionLevels as $type ) {
282 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
283 if ( $type != '' && $type != '*' ) {
284 $text = $this->msg( "restriction-level-$type" )->text();
289 // Third pass generates sorted XHTML content
290 foreach ( $m as $text => $type ) {
291 $selected = ( $type == $pr_level );
292 $options[] = Xml
::option( $text, $type, $selected );
295 return "<span style='white-space: nowrap'>" .
296 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
298 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
299 implode( "\n", $options ) ) . "</span>";
302 protected function getGroupName() {
303 return 'maintenance';
311 class ProtectedPagesPager
extends AlphabeticPager
{
312 public $mForm, $mConds;
313 private $type, $level, $namespace, $sizetype, $size, $indefonly;
315 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype = '', $size = 0,
316 $indefonly = false, $cascadeonly = false )
318 $this->mForm
= $form;
319 $this->mConds
= $conds;
320 $this->type
= ( $type ) ?
$type : 'edit';
321 $this->level
= $level;
322 $this->namespace = $namespace;
323 $this->sizetype
= $sizetype;
324 $this->size
= intval( $size );
325 $this->indefonly
= (bool)$indefonly;
326 $this->cascadeonly
= (bool)$cascadeonly;
327 parent
::__construct( $form->getContext() );
330 function getStartBody() {
331 # Do a link batch query
333 foreach ( $this->mResult
as $row ) {
334 $lb->add( $row->page_namespace
, $row->page_title
);
340 function formatRow( $row ) {
341 return $this->mForm
->formatRow( $row );
344 function getQueryInfo() {
345 $conds = $this->mConds
;
346 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
347 'OR pr_expiry IS NULL)';
348 $conds[] = 'page_id=pr_page';
349 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
351 if ( $this->sizetype
== 'min' ) {
352 $conds[] = 'page_len>=' . $this->size
;
353 } elseif ( $this->sizetype
== 'max' ) {
354 $conds[] = 'page_len<=' . $this->size
;
357 if ( $this->indefonly
) {
358 $conds[] = "pr_expiry = {$this->mDb->addQuotes( $this->mDb->getInfinity() )} OR pr_expiry IS NULL";
360 if ( $this->cascadeonly
) {
361 $conds[] = 'pr_cascade = 1';
364 if ( $this->level
) {
365 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
367 if ( !is_null( $this->namespace ) ) {
368 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
371 'tables' => array( 'page_restrictions', 'page' ),
372 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len',
373 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ),
378 function getIndexField() {