00001 <?php
00011 class ProtectedPagesForm {
00012
00013 protected $IdLevel = 'level';
00014 protected $IdType = 'type';
00015
00016 public function showList( $msg = '' ) {
00017 global $wgOut, $wgRequest;
00018
00019 if( $msg != "" ) {
00020 $wgOut->setSubtitle( $msg );
00021 }
00022
00023
00024 if( !mt_rand( 0, 10 ) ) {
00025 Title::purgeExpiredRestrictions();
00026 }
00027
00028 $type = $wgRequest->getVal( $this->IdType );
00029 $level = $wgRequest->getVal( $this->IdLevel );
00030 $sizetype = $wgRequest->getVal( 'sizetype' );
00031 $size = $wgRequest->getIntOrNull( 'size' );
00032 $NS = $wgRequest->getIntOrNull( 'namespace' );
00033 $indefOnly = $wgRequest->getBool( 'indefonly' ) ? 1 : 0;
00034 $cascadeOnly = $wgRequest->getBool('cascadeonly') ? 1 : 0;
00035
00036 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
00037
00038 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
00039
00040 if( $pager->getNumRows() ) {
00041 $s = $pager->getNavigationBar();
00042 $s .= "<ul>" .
00043 $pager->getBody() .
00044 "</ul>";
00045 $s .= $pager->getNavigationBar();
00046 } else {
00047 $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
00048 }
00049 $wgOut->addHTML( $s );
00050 }
00051
00057 public function formatRow( $row ) {
00058 global $wgUser, $wgLang, $wgContLang;
00059
00060 wfProfileIn( __METHOD__ );
00061
00062 static $skin=null;
00063
00064 if( is_null( $skin ) )
00065 $skin = $wgUser->getSkin();
00066
00067 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
00068 $link = $skin->link( $title );
00069
00070 $description_items = array ();
00071
00072 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
00073
00074 $description_items[] = $protType;
00075
00076 if( $row->pr_cascade ) {
00077 $description_items[] = wfMsg( 'protect-summary-cascade' );
00078 }
00079
00080 $expiry_description = '';
00081 $stxt = '';
00082
00083 if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
00084 $expiry = Block::decodeExpiry( $row->pr_expiry );
00085
00086 $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) ,
00087 $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
00088
00089 $description_items[] = htmlspecialchars($expiry_description);
00090 }
00091
00092 if(!is_null($size = $row->page_len)) {
00093 $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
00094 }
00095
00096 # Show a link to the change protection form for allowed users otherwise a link to the protection log
00097 if( $wgUser->isAllowed( 'protect' ) ) {
00098 $changeProtection = ' (' . $skin->linkKnown(
00099 $title,
00100 wfMsgHtml( 'protect_change' ),
00101 array(),
00102 array( 'action' => 'unprotect' )
00103 ) . ')';
00104 } else {
00105 $ltitle = SpecialPage::getTitleFor( 'Log' );
00106 $changeProtection = ' (' . $skin->linkKnown(
00107 $ltitle,
00108 wfMsgHtml( 'protectlogpage' ),
00109 array(),
00110 array(
00111 'type' => 'protect',
00112 'page' => $title->getPrefixedText()
00113 )
00114 ) . ')';
00115 }
00116
00117 wfProfileOut( __METHOD__ );
00118
00119 return Html::rawElement(
00120 'li',
00121 array(),
00122 wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
00123 }
00124
00135 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
00136 global $wgScript;
00137 $title = SpecialPage::getTitleFor( 'Protectedpages' );
00138 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
00139 Xml::openElement( 'fieldset' ) .
00140 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
00141 Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
00142 $this->getNamespaceMenu( $namespace ) . " \n" .
00143 $this->getTypeMenu( $type ) . " \n" .
00144 $this->getLevelMenu( $level ) . " \n" .
00145 "<br /><span style='white-space: nowrap'>" .
00146 $this->getExpiryCheck( $indefOnly ) . " \n" .
00147 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
00148 "</span><br /><span style='white-space: nowrap'>" .
00149 $this->getSizeLimit( $sizetype, $size ) . " \n" .
00150 "</span>" .
00151 " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00152 Xml::closeElement( 'fieldset' ) .
00153 Xml::closeElement( 'form' );
00154 }
00155
00163 protected function getNamespaceMenu( $namespace = null ) {
00164 return "<span style='white-space: nowrap'>" .
00165 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
00166 . Xml::namespaceSelector( $namespace, '' ) . "</span>";
00167 }
00168
00172 protected function getExpiryCheck( $indefOnly ) {
00173 return
00174 Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
00175 }
00176
00180 protected function getCascadeCheck( $cascadeOnly ) {
00181 return
00182 Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
00183 }
00184
00188 protected function getSizeLimit( $sizetype, $size ) {
00189 $max = $sizetype === 'max';
00190
00191 return
00192 Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
00193 ' ' .
00194 Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
00195 ' ' .
00196 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
00197 ' ' .
00198 Xml::label( wfMsg('pagesize'), 'wpsize' );
00199 }
00200
00206 protected function getTypeMenu( $pr_type ) {
00207 global $wgRestrictionTypes;
00208
00209 $m = array();
00210 $options = array();
00211
00212
00213 foreach( $wgRestrictionTypes as $type ) {
00214 $text = wfMsg("restriction-$type");
00215 $m[$text] = $type;
00216 }
00217
00218
00219 foreach( $m as $text => $type ) {
00220 $selected = ($type == $pr_type );
00221 $options[] = Xml::option( $text, $type, $selected ) . "\n";
00222 }
00223
00224 return "<span style='white-space: nowrap'>" .
00225 Xml::label( wfMsg('restriction-type') , $this->IdType ) . ' ' .
00226 Xml::tags( 'select',
00227 array( 'id' => $this->IdType, 'name' => $this->IdType ),
00228 implode( "\n", $options ) ) . "</span>";
00229 }
00230
00236 protected function getLevelMenu( $pr_level ) {
00237 global $wgRestrictionLevels;
00238
00239 $m = array( wfMsg('restriction-level-all') => 0 );
00240 $options = array();
00241
00242
00243 foreach( $wgRestrictionLevels as $type ) {
00244
00245 if( $type !='' && $type !='*') {
00246 $text = wfMsg("restriction-level-$type");
00247 $m[$text] = $type;
00248 }
00249 }
00250
00251
00252 foreach( $m as $text => $type ) {
00253 $selected = ($type == $pr_level );
00254 $options[] = Xml::option( $text, $type, $selected );
00255 }
00256
00257 return "<span style='white-space: nowrap'>" .
00258 Xml::label( wfMsg( 'restriction-level' ) , $this->IdLevel ) . ' ' .
00259 Xml::tags( 'select',
00260 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00261 implode( "\n", $options ) ) . "</span>";
00262 }
00263 }
00264
00269 class ProtectedPagesPager extends AlphabeticPager {
00270 public $mForm, $mConds;
00271 private $type, $level, $namespace, $sizetype, $size, $indefonly;
00272
00273 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
00274 $indefonly = false, $cascadeonly = false )
00275 {
00276 $this->mForm = $form;
00277 $this->mConds = $conds;
00278 $this->type = ( $type ) ? $type : 'edit';
00279 $this->level = $level;
00280 $this->namespace = $namespace;
00281 $this->sizetype = $sizetype;
00282 $this->size = intval($size);
00283 $this->indefonly = (bool)$indefonly;
00284 $this->cascadeonly = (bool)$cascadeonly;
00285 parent::__construct();
00286 }
00287
00288 function getStartBody() {
00289 # Do a link batch query
00290 $lb = new LinkBatch;
00291 while( $row = $this->mResult->fetchObject() ) {
00292 $lb->add( $row->page_namespace, $row->page_title );
00293 }
00294 $lb->execute();
00295 return '';
00296 }
00297
00298 function formatRow( $row ) {
00299 return $this->mForm->formatRow( $row );
00300 }
00301
00302 function getQueryInfo() {
00303 $conds = $this->mConds;
00304 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
00305 'OR pr_expiry IS NULL)';
00306 $conds[] = 'page_id=pr_page';
00307 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
00308
00309 if( $this->sizetype=='min' ) {
00310 $conds[] = 'page_len>=' . $this->size;
00311 } else if( $this->sizetype=='max' ) {
00312 $conds[] = 'page_len<=' . $this->size;
00313 }
00314
00315 if( $this->indefonly ) {
00316 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
00317 }
00318 if( $this->cascadeonly ) {
00319 $conds[] = "pr_cascade = '1'";
00320 }
00321
00322 if( $this->level )
00323 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
00324 if( !is_null($this->namespace) )
00325 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
00326 return array(
00327 'tables' => array( 'page_restrictions', 'page' ),
00328 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
00329 'conds' => $conds
00330 );
00331 }
00332
00333 function getIndexField() {
00334 return 'pr_id';
00335 }
00336 }
00337
00341 function wfSpecialProtectedpages() {
00342 $ppForm = new ProtectedPagesForm();
00343 $ppForm->showList();
00344 }