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 $row object 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
);
86 $link = Linker
::link( $title );
88 $description_items = array ();
90 $protType = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
92 $description_items[] = $protType;
94 if( $row->pr_cascade
) {
95 $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
99 $lang = $this->getLanguage();
101 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
102 if( $expiry != $infinity ) {
103 $user = $this->getUser();
104 $description_items[] = $this->msg(
105 'protect-expiring-local',
106 $lang->userTimeAndDate( $expiry, $user ),
107 $lang->userDate( $expiry, $user ),
108 $lang->userTime( $expiry, $user )
112 if(!is_null($size = $row->page_len
)) {
113 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
116 # Show a link to the change protection form for allowed users otherwise a link to the protection log
117 if( $this->getUser()->isAllowed( 'protect' ) ) {
118 $changeProtection = Linker
::linkKnown(
120 $this->msg( 'protect_change' )->escaped(),
122 array( 'action' => 'unprotect' )
125 $ltitle = SpecialPage
::getTitleFor( 'Log' );
126 $changeProtection = Linker
::linkKnown(
128 $this->msg( 'protectlogpage' )->escaped(),
132 'page' => $title->getPrefixedText()
137 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped();
139 wfProfileOut( __METHOD__
);
141 return Html
::rawElement(
144 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
148 * @param $namespace Integer
149 * @param $type String: restriction type
150 * @param $level String: restriction level
151 * @param $sizetype String: "min" or "max"
152 * @param $size Integer
153 * @param $indefOnly Boolean: only indefinie protection
154 * @param $cascadeOnly Boolean: only cascading protection
155 * @return String: input form
157 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
159 $title = $this->getTitle();
160 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
161 Xml
::openElement( 'fieldset' ) .
162 Xml
::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
163 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
164 $this->getNamespaceMenu( $namespace ) . " \n" .
165 $this->getTypeMenu( $type ) . " \n" .
166 $this->getLevelMenu( $level ) . " \n" .
167 "<br /><span style='white-space: nowrap'>" .
168 $this->getExpiryCheck( $indefOnly ) . " \n" .
169 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
170 "</span><br /><span style='white-space: nowrap'>" .
171 $this->getSizeLimit( $sizetype, $size ) . " \n" .
173 " " . Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
174 Xml
::closeElement( 'fieldset' ) .
175 Xml
::closeElement( 'form' );
179 * Prepare the namespace filter drop-down; standard namespace
180 * selector, sans the MediaWiki namespace
182 * @param $namespace Mixed: pre-select namespace
185 protected function getNamespaceMenu( $namespace = null ) {
186 return Html
::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
187 Html
::namespaceSelector(
189 'selected' => $namespace,
191 'label' => $this->msg( 'namespace' )->text()
193 'name' => 'namespace',
195 'class' => 'namespaceselector',
202 * @return string Formatted HTML
204 protected function getExpiryCheck( $indefOnly ) {
206 Xml
::checkLabel( $this->msg( 'protectedpages-indef' )->text(), 'indefonly', 'indefonly', $indefOnly ) . "\n";
210 * @return string Formatted HTML
212 protected function getCascadeCheck( $cascadeOnly ) {
214 Xml
::checkLabel( $this->msg( 'protectedpages-cascade' )->text(), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
218 * @return string Formatted HTML
220 protected function getSizeLimit( $sizetype, $size ) {
221 $max = $sizetype === 'max';
224 Xml
::radioLabel( $this->msg( 'minimum-size' )->text(), 'sizetype', 'min', 'wpmin', !$max ) .
226 Xml
::radioLabel( $this->msg( 'maximum-size' )->text(), 'sizetype', 'max', 'wpmax', $max ) .
228 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
230 Xml
::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
234 * Creates the input label of the restriction type
235 * @param $pr_type string Protection type
236 * @return string Formatted HTML
238 protected function getTypeMenu( $pr_type ) {
239 $m = array(); // Temporary array
242 // First pass to load the log names
243 foreach( Title
::getFilteredRestrictionTypes( true ) as $type ) {
244 $text = $this->msg( "restriction-$type" )->text();
248 // Third pass generates sorted XHTML content
249 foreach( $m as $text => $type ) {
250 $selected = ($type == $pr_type );
251 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
254 return "<span style='white-space: nowrap'>" .
255 Xml
::label( $this->msg( 'restriction-type' )->text(), $this->IdType
) . ' ' .
257 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
258 implode( "\n", $options ) ) . "</span>";
262 * Creates the input label of the restriction level
263 * @param $pr_level string Protection level
264 * @return string Formatted HTML
266 protected function getLevelMenu( $pr_level ) {
267 global $wgRestrictionLevels;
269 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
272 // First pass to load the log names
273 foreach( $wgRestrictionLevels as $type ) {
274 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
275 if( $type !='' && $type !='*') {
276 $text = $this->msg( "restriction-level-$type" )->text();
281 // Third pass generates sorted XHTML content
282 foreach( $m as $text => $type ) {
283 $selected = ($type == $pr_level );
284 $options[] = Xml
::option( $text, $type, $selected );
287 return "<span style='white-space: nowrap'>" .
288 Xml
::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel
) . ' ' .
290 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
291 implode( "\n", $options ) ) . "</span>";
299 class ProtectedPagesPager
extends AlphabeticPager
{
300 public $mForm, $mConds;
301 private $type, $level, $namespace, $sizetype, $size, $indefonly;
303 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
304 $indefonly = false, $cascadeonly = false )
306 $this->mForm
= $form;
307 $this->mConds
= $conds;
308 $this->type
= ( $type ) ?
$type : 'edit';
309 $this->level
= $level;
310 $this->namespace = $namespace;
311 $this->sizetype
= $sizetype;
312 $this->size
= intval($size);
313 $this->indefonly
= (bool)$indefonly;
314 $this->cascadeonly
= (bool)$cascadeonly;
315 parent
::__construct( $form->getContext() );
318 function getStartBody() {
319 # Do a link batch query
321 foreach ( $this->mResult
as $row ) {
322 $lb->add( $row->page_namespace
, $row->page_title
);
328 function formatRow( $row ) {
329 return $this->mForm
->formatRow( $row );
332 function getQueryInfo() {
333 $conds = $this->mConds
;
334 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
335 'OR pr_expiry IS NULL)';
336 $conds[] = 'page_id=pr_page';
337 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
339 if( $this->sizetype
=='min' ) {
340 $conds[] = 'page_len>=' . $this->size
;
341 } elseif( $this->sizetype
=='max' ) {
342 $conds[] = 'page_len<=' . $this->size
;
345 if( $this->indefonly
) {
346 $db = wfGetDB( DB_SLAVE
);
347 $conds[] = "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL";
349 if( $this->cascadeonly
) {
350 $conds[] = "pr_cascade = '1'";
354 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
355 if( !is_null($this->namespace) )
356 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
358 'tables' => array( 'page_restrictions', 'page' ),
359 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
364 function getIndexField() {