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 $s = $pager->getNavigationBar();
65 $s .= $pager->getNavigationBar();
67 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
69 $this->getOutput()->addHTML( $s );
73 * Callback function to output a restriction
74 * @param $row object Protected title
75 * @return string Formatted <li> element
77 public function formatRow( $row ) {
78 wfProfileIn( __METHOD__
);
80 static $infinity = null;
82 if( is_null( $infinity ) ){
83 $infinity = wfGetDB( DB_SLAVE
)->getInfinity();
86 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
87 $link = Linker
::link( $title );
89 $description_items = array ();
91 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level
);
93 $description_items[] = $protType;
95 if( $row->pr_cascade
) {
96 $description_items[] = wfMsg( 'protect-summary-cascade' );
100 $lang = $this->getLang();
102 $expiry = $lang->formatExpiry( $row->pr_expiry
, TS_MW
);
103 if( $expiry != $infinity ) {
105 $expiry_description = wfMsg(
106 'protect-expiring-local',
107 $lang->timeanddate( $expiry, true ),
108 $lang->date( $expiry, true ),
109 $lang->time( $expiry, true )
112 $description_items[] = htmlspecialchars($expiry_description);
115 if(!is_null($size = $row->page_len
)) {
116 $stxt = $lang->getDirMark() . ' ' . Linker
::formatRevisionSize( $size );
119 # Show a link to the change protection form for allowed users otherwise a link to the protection log
120 if( $this->getUser()->isAllowed( 'protect' ) ) {
121 $changeProtection = ' (' . Linker
::linkKnown(
123 wfMsgHtml( 'protect_change' ),
125 array( 'action' => 'unprotect' )
128 $ltitle = SpecialPage
::getTitleFor( 'Log' );
129 $changeProtection = ' (' . Linker
::linkKnown(
131 wfMsgHtml( 'protectlogpage' ),
135 'page' => $title->getPrefixedText()
140 wfProfileOut( __METHOD__
);
142 return Html
::rawElement(
145 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
149 * @param $namespace Integer
150 * @param $type String: restriction type
151 * @param $level String: restriction level
152 * @param $sizetype String: "min" or "max"
153 * @param $size Integer
154 * @param $indefOnly Boolean: only indefinie protection
155 * @param $cascadeOnly Boolean: only cascading protection
156 * @return String: input form
158 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
160 $title = $this->getTitle();
161 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
162 Xml
::openElement( 'fieldset' ) .
163 Xml
::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
164 Html
::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
165 $this->getNamespaceMenu( $namespace ) . " \n" .
166 $this->getTypeMenu( $type ) . " \n" .
167 $this->getLevelMenu( $level ) . " \n" .
168 "<br /><span style='white-space: nowrap'>" .
169 $this->getExpiryCheck( $indefOnly ) . " \n" .
170 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
171 "</span><br /><span style='white-space: nowrap'>" .
172 $this->getSizeLimit( $sizetype, $size ) . " \n" .
174 " " . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
175 Xml
::closeElement( 'fieldset' ) .
176 Xml
::closeElement( 'form' );
180 * Prepare the namespace filter drop-down; standard namespace
181 * selector, sans the MediaWiki namespace
183 * @param $namespace Mixed: pre-select namespace
186 protected function getNamespaceMenu( $namespace = null ) {
187 return "<span style='white-space: nowrap'>" .
188 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
189 . Xml
::namespaceSelector( $namespace, '' ) . "</span>";
193 * @return string Formatted HTML
195 protected function getExpiryCheck( $indefOnly ) {
197 Xml
::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
201 * @return string Formatted HTML
203 protected function getCascadeCheck( $cascadeOnly ) {
205 Xml
::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
209 * @return string Formatted HTML
211 protected function getSizeLimit( $sizetype, $size ) {
212 $max = $sizetype === 'max';
215 Xml
::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
217 Xml
::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
219 Xml
::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
221 Xml
::label( wfMsg('pagesize'), 'wpsize' );
225 * Creates the input label of the restriction type
226 * @param $pr_type string Protection type
227 * @return string Formatted HTML
229 protected function getTypeMenu( $pr_type ) {
230 $m = array(); // Temporary array
233 // First pass to load the log names
234 foreach( Title
::getFilteredRestrictionTypes( true ) as $type ) {
235 $text = wfMsg("restriction-$type");
239 // Third pass generates sorted XHTML content
240 foreach( $m as $text => $type ) {
241 $selected = ($type == $pr_type );
242 $options[] = Xml
::option( $text, $type, $selected ) . "\n";
245 return "<span style='white-space: nowrap'>" .
246 Xml
::label( wfMsg('restriction-type') , $this->IdType
) . ' ' .
248 array( 'id' => $this->IdType
, 'name' => $this->IdType
),
249 implode( "\n", $options ) ) . "</span>";
253 * Creates the input label of the restriction level
254 * @param $pr_level string Protection level
255 * @return string Formatted HTML
257 protected function getLevelMenu( $pr_level ) {
258 global $wgRestrictionLevels;
260 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
263 // First pass to load the log names
264 foreach( $wgRestrictionLevels as $type ) {
265 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
266 if( $type !='' && $type !='*') {
267 $text = wfMsg("restriction-level-$type");
272 // Third pass generates sorted XHTML content
273 foreach( $m as $text => $type ) {
274 $selected = ($type == $pr_level );
275 $options[] = Xml
::option( $text, $type, $selected );
278 return "<span style='white-space: nowrap'>" .
279 Xml
::label( wfMsg( 'restriction-level' ) , $this->IdLevel
) . ' ' .
281 array( 'id' => $this->IdLevel
, 'name' => $this->IdLevel
),
282 implode( "\n", $options ) ) . "</span>";
290 class ProtectedPagesPager
extends AlphabeticPager
{
291 public $mForm, $mConds;
292 private $type, $level, $namespace, $sizetype, $size, $indefonly;
294 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
295 $indefonly = false, $cascadeonly = false )
297 $this->mForm
= $form;
298 $this->mConds
= $conds;
299 $this->type
= ( $type ) ?
$type : 'edit';
300 $this->level
= $level;
301 $this->namespace = $namespace;
302 $this->sizetype
= $sizetype;
303 $this->size
= intval($size);
304 $this->indefonly
= (bool)$indefonly;
305 $this->cascadeonly
= (bool)$cascadeonly;
306 parent
::__construct( $form->getContext() );
309 function getStartBody() {
310 # Do a link batch query
312 foreach ( $this->mResult
as $row ) {
313 $lb->add( $row->page_namespace
, $row->page_title
);
319 function formatRow( $row ) {
320 return $this->mForm
->formatRow( $row );
323 function getQueryInfo() {
324 $conds = $this->mConds
;
325 $conds[] = '(pr_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
326 'OR pr_expiry IS NULL)';
327 $conds[] = 'page_id=pr_page';
328 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
330 if( $this->sizetype
=='min' ) {
331 $conds[] = 'page_len>=' . $this->size
;
332 } elseif( $this->sizetype
=='max' ) {
333 $conds[] = 'page_len<=' . $this->size
;
336 if( $this->indefonly
) {
337 $db = wfGetDB( DB_SLAVE
);
338 $conds[] = "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL";
340 if( $this->cascadeonly
) {
341 $conds[] = "pr_cascade = '1'";
345 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
346 if( !is_null($this->namespace) )
347 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
349 'tables' => array( 'page_restrictions', 'page' ),
350 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
355 function getIndexField() {