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->makeLinkObj( $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[] = $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->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ),
00099 'action=unprotect' ) . ')';
00100 } else {
00101 $ltitle = SpecialPage::getTitleFor( 'Log' );
00102 $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ),
00103 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
00104 }
00105
00106 wfProfileOut( __METHOD__ );
00107
00108 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
00109 }
00110
00121 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
00122 global $wgScript;
00123 $title = SpecialPage::getTitleFor( 'ProtectedPages' );
00124 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
00125 Xml::openElement( 'fieldset' ) .
00126 Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
00127 Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
00128 $this->getNamespaceMenu( $namespace ) . " \n" .
00129 $this->getTypeMenu( $type ) . " \n" .
00130 $this->getLevelMenu( $level ) . " \n" .
00131 "<br/><span style='white-space: nowrap'>" .
00132 $this->getExpiryCheck( $indefOnly ) . " \n" .
00133 $this->getCascadeCheck( $cascadeOnly ) . " \n" .
00134 "</span><br/><span style='white-space: nowrap'>" .
00135 $this->getSizeLimit( $sizetype, $size ) . " \n" .
00136 "</span>" .
00137 " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00138 Xml::closeElement( 'fieldset' ) .
00139 Xml::closeElement( 'form' );
00140 }
00141
00149 protected function getNamespaceMenu( $namespace = null ) {
00150 return "<span style='white-space: nowrap'>" .
00151 Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '
00152 . Xml::namespaceSelector( $namespace, '' ) . "</span>";
00153 }
00154
00158 protected function getExpiryCheck( $indefOnly ) {
00159 return
00160 Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
00161 }
00162
00166 protected function getCascadeCheck( $cascadeOnly ) {
00167 return
00168 Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
00169 }
00170
00174 protected function getSizeLimit( $sizetype, $size ) {
00175 $max = $sizetype === 'max';
00176
00177 return
00178 Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
00179 ' ' .
00180 Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
00181 ' ' .
00182 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
00183 ' ' .
00184 Xml::label( wfMsg('pagesize'), 'wpsize' );
00185 }
00186
00190 protected function getTypeMenu( $pr_type ) {
00191 global $wgRestrictionTypes;
00192
00193 $m = array();
00194 $options = array();
00195
00196
00197 foreach( $wgRestrictionTypes as $type ) {
00198 $text = wfMsg("restriction-$type");
00199 $m[$text] = $type;
00200 }
00201
00202
00203 foreach( $m as $text => $type ) {
00204 $selected = ($type == $pr_type );
00205 $options[] = Xml::option( $text, $type, $selected ) . "\n";
00206 }
00207
00208 return "<span style='white-space: nowrap'>" .
00209 Xml::label( wfMsg('restriction-type') , $this->IdType ) . ' ' .
00210 Xml::tags( 'select',
00211 array( 'id' => $this->IdType, 'name' => $this->IdType ),
00212 implode( "\n", $options ) ) . "</span>";
00213 }
00214
00218 protected function getLevelMenu( $pr_level ) {
00219 global $wgRestrictionLevels;
00220
00221 $m = array( wfMsg('restriction-level-all') => 0 );
00222 $options = array();
00223
00224
00225 foreach( $wgRestrictionLevels as $type ) {
00226 if( $type !='' && $type !='*') {
00227 $text = wfMsg("restriction-level-$type");
00228 $m[$text] = $type;
00229 }
00230 }
00231
00232
00233 foreach( $m as $text => $type ) {
00234 $selected = ($type == $pr_level );
00235 $options[] = Xml::option( $text, $type, $selected );
00236 }
00237
00238 return
00239 Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . ' ' .
00240 Xml::tags( 'select',
00241 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00242 implode( "\n", $options ) );
00243 }
00244 }
00245
00250 class ProtectedPagesPager extends AlphabeticPager {
00251 public $mForm, $mConds;
00252 private $type, $level, $namespace, $sizetype, $size, $indefonly;
00253
00254 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
00255 $indefonly = false, $cascadeonly = false )
00256 {
00257 $this->mForm = $form;
00258 $this->mConds = $conds;
00259 $this->type = ( $type ) ? $type : 'edit';
00260 $this->level = $level;
00261 $this->namespace = $namespace;
00262 $this->sizetype = $sizetype;
00263 $this->size = intval($size);
00264 $this->indefonly = (bool)$indefonly;
00265 $this->cascadeonly = (bool)$cascadeonly;
00266 parent::__construct();
00267 }
00268
00269 function getStartBody() {
00270 # Do a link batch query
00271 $lb = new LinkBatch;
00272 while( $row = $this->mResult->fetchObject() ) {
00273 $lb->add( $row->page_namespace, $row->page_title );
00274 }
00275 $lb->execute();
00276 return '';
00277 }
00278
00279 function formatRow( $row ) {
00280 return $this->mForm->formatRow( $row );
00281 }
00282
00283 function getQueryInfo() {
00284 $conds = $this->mConds;
00285 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
00286 'OR pr_expiry IS NULL)';
00287 $conds[] = 'page_id=pr_page';
00288 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
00289
00290 if( $this->sizetype=='min' ) {
00291 $conds[] = 'page_len>=' . $this->size;
00292 } else if( $this->sizetype=='max' ) {
00293 $conds[] = 'page_len<=' . $this->size;
00294 }
00295
00296 if( $this->indefonly ) {
00297 $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
00298 }
00299 if( $this->cascadeonly ) {
00300 $conds[] = "pr_cascade = '1'";
00301 }
00302
00303 if( $this->level )
00304 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
00305 if( !is_null($this->namespace) )
00306 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
00307 return array(
00308 'tables' => array( 'page_restrictions', 'page' ),
00309 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
00310 'conds' => $conds
00311 );
00312 }
00313
00314 function getIndexField() {
00315 return 'pr_id';
00316 }
00317 }
00318
00322 function wfSpecialProtectedpages() {
00323 $ppForm = new ProtectedPagesForm();
00324 $ppForm->showList();
00325 }