MediaWiki
REL1_20
|
00001 <?php 00029 class SpecialProtectedpages extends SpecialPage { 00030 00031 protected $IdLevel = 'level'; 00032 protected $IdType = 'type'; 00033 00034 public function __construct() { 00035 parent::__construct( 'Protectedpages' ); 00036 } 00037 00038 public function execute( $par ) { 00039 $this->setHeaders(); 00040 $this->outputHeader(); 00041 00042 // Purge expired entries on one in every 10 queries 00043 if( !mt_rand( 0, 10 ) ) { 00044 Title::purgeExpiredRestrictions(); 00045 } 00046 00047 $request = $this->getRequest(); 00048 $type = $request->getVal( $this->IdType ); 00049 $level = $request->getVal( $this->IdLevel ); 00050 $sizetype = $request->getVal( 'sizetype' ); 00051 $size = $request->getIntOrNull( 'size' ); 00052 $NS = $request->getIntOrNull( 'namespace' ); 00053 $indefOnly = $request->getBool( 'indefonly' ) ? 1 : 0; 00054 $cascadeOnly = $request->getBool('cascadeonly') ? 1 : 0; 00055 00056 $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly ); 00057 00058 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) ); 00059 00060 if( $pager->getNumRows() ) { 00061 $this->getOutput()->addHTML( 00062 $pager->getNavigationBar() . 00063 '<ul>' . $pager->getBody() . '</ul>' . 00064 $pager->getNavigationBar() 00065 ); 00066 } else { 00067 $this->getOutput()->addWikiMsg( 'protectedpagesempty' ); 00068 } 00069 } 00070 00076 public function formatRow( $row ) { 00077 wfProfileIn( __METHOD__ ); 00078 00079 static $infinity = null; 00080 00081 if( is_null( $infinity ) ){ 00082 $infinity = wfGetDB( DB_SLAVE )->getInfinity(); 00083 } 00084 00085 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); 00086 $link = Linker::link( $title ); 00087 00088 $description_items = array (); 00089 00090 $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped(); 00091 00092 $description_items[] = $protType; 00093 00094 if( $row->pr_cascade ) { 00095 $description_items[] = $this->msg( 'protect-summary-cascade' )->text(); 00096 } 00097 00098 $stxt = ''; 00099 $lang = $this->getLanguage(); 00100 00101 $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW ); 00102 if( $expiry != $infinity ) { 00103 $user = $this->getUser(); 00104 $description_items[] = $this->msg( 00105 'protect-expiring-local', 00106 $lang->userTimeAndDate( $expiry, $user ), 00107 $lang->userDate( $expiry, $user ), 00108 $lang->userTime( $expiry, $user ) 00109 )->escaped(); 00110 } 00111 00112 if(!is_null($size = $row->page_len)) { 00113 $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size ); 00114 } 00115 00116 # Show a link to the change protection form for allowed users otherwise a link to the protection log 00117 if( $this->getUser()->isAllowed( 'protect' ) ) { 00118 $changeProtection = Linker::linkKnown( 00119 $title, 00120 $this->msg( 'protect_change' )->escaped(), 00121 array(), 00122 array( 'action' => 'unprotect' ) 00123 ); 00124 } else { 00125 $ltitle = SpecialPage::getTitleFor( 'Log' ); 00126 $changeProtection = Linker::linkKnown( 00127 $ltitle, 00128 $this->msg( 'protectlogpage' )->escaped(), 00129 array(), 00130 array( 00131 'type' => 'protect', 00132 'page' => $title->getPrefixedText() 00133 ) 00134 ); 00135 } 00136 00137 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped(); 00138 00139 wfProfileOut( __METHOD__ ); 00140 00141 return Html::rawElement( 00142 'li', 00143 array(), 00144 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n"; 00145 } 00146 00157 protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) { 00158 global $wgScript; 00159 $title = $this->getTitle(); 00160 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . 00161 Xml::openElement( 'fieldset' ) . 00162 Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) . 00163 Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" . 00164 $this->getNamespaceMenu( $namespace ) . " \n" . 00165 $this->getTypeMenu( $type ) . " \n" . 00166 $this->getLevelMenu( $level ) . " \n" . 00167 "<br /><span style='white-space: nowrap'>" . 00168 $this->getExpiryCheck( $indefOnly ) . " \n" . 00169 $this->getCascadeCheck( $cascadeOnly ) . " \n" . 00170 "</span><br /><span style='white-space: nowrap'>" . 00171 $this->getSizeLimit( $sizetype, $size ) . " \n" . 00172 "</span>" . 00173 " " . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" . 00174 Xml::closeElement( 'fieldset' ) . 00175 Xml::closeElement( 'form' ); 00176 } 00177 00185 protected function getNamespaceMenu( $namespace = null ) { 00186 return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ), 00187 Html::namespaceSelector( 00188 array( 00189 'selected' => $namespace, 00190 'all' => '', 00191 'label' => $this->msg( 'namespace' )->text() 00192 ), array( 00193 'name' => 'namespace', 00194 'id' => 'namespace', 00195 'class' => 'namespaceselector', 00196 ) 00197 ) 00198 ); 00199 } 00200 00204 protected function getExpiryCheck( $indefOnly ) { 00205 return 00206 Xml::checkLabel( $this->msg( 'protectedpages-indef' )->text(), 'indefonly', 'indefonly', $indefOnly ) . "\n"; 00207 } 00208 00212 protected function getCascadeCheck( $cascadeOnly ) { 00213 return 00214 Xml::checkLabel( $this->msg( 'protectedpages-cascade' )->text(), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n"; 00215 } 00216 00220 protected function getSizeLimit( $sizetype, $size ) { 00221 $max = $sizetype === 'max'; 00222 00223 return 00224 Xml::radioLabel( $this->msg( 'minimum-size' )->text(), 'sizetype', 'min', 'wpmin', !$max ) . 00225 ' ' . 00226 Xml::radioLabel( $this->msg( 'maximum-size' )->text(), 'sizetype', 'max', 'wpmax', $max ) . 00227 ' ' . 00228 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) . 00229 ' ' . 00230 Xml::label( $this->msg( 'pagesize' )->text(), 'wpsize' ); 00231 } 00232 00238 protected function getTypeMenu( $pr_type ) { 00239 $m = array(); // Temporary array 00240 $options = array(); 00241 00242 // First pass to load the log names 00243 foreach( Title::getFilteredRestrictionTypes( true ) as $type ) { 00244 $text = $this->msg( "restriction-$type" )->text(); 00245 $m[$text] = $type; 00246 } 00247 00248 // Third pass generates sorted XHTML content 00249 foreach( $m as $text => $type ) { 00250 $selected = ($type == $pr_type ); 00251 $options[] = Xml::option( $text, $type, $selected ) . "\n"; 00252 } 00253 00254 return "<span style='white-space: nowrap'>" . 00255 Xml::label( $this->msg( 'restriction-type' )->text(), $this->IdType ) . ' ' . 00256 Xml::tags( 'select', 00257 array( 'id' => $this->IdType, 'name' => $this->IdType ), 00258 implode( "\n", $options ) ) . "</span>"; 00259 } 00260 00266 protected function getLevelMenu( $pr_level ) { 00267 global $wgRestrictionLevels; 00268 00269 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array 00270 $options = array(); 00271 00272 // First pass to load the log names 00273 foreach( $wgRestrictionLevels as $type ) { 00274 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed' 00275 if( $type !='' && $type !='*') { 00276 $text = $this->msg( "restriction-level-$type" )->text(); 00277 $m[$text] = $type; 00278 } 00279 } 00280 00281 // Third pass generates sorted XHTML content 00282 foreach( $m as $text => $type ) { 00283 $selected = ($type == $pr_level ); 00284 $options[] = Xml::option( $text, $type, $selected ); 00285 } 00286 00287 return "<span style='white-space: nowrap'>" . 00288 Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . ' ' . 00289 Xml::tags( 'select', 00290 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ), 00291 implode( "\n", $options ) ) . "</span>"; 00292 } 00293 } 00294 00299 class ProtectedPagesPager extends AlphabeticPager { 00300 public $mForm, $mConds; 00301 private $type, $level, $namespace, $sizetype, $size, $indefonly; 00302 00303 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, 00304 $indefonly = false, $cascadeonly = false ) 00305 { 00306 $this->mForm = $form; 00307 $this->mConds = $conds; 00308 $this->type = ( $type ) ? $type : 'edit'; 00309 $this->level = $level; 00310 $this->namespace = $namespace; 00311 $this->sizetype = $sizetype; 00312 $this->size = intval($size); 00313 $this->indefonly = (bool)$indefonly; 00314 $this->cascadeonly = (bool)$cascadeonly; 00315 parent::__construct( $form->getContext() ); 00316 } 00317 00318 function getStartBody() { 00319 # Do a link batch query 00320 $lb = new LinkBatch; 00321 foreach ( $this->mResult as $row ) { 00322 $lb->add( $row->page_namespace, $row->page_title ); 00323 } 00324 $lb->execute(); 00325 return ''; 00326 } 00327 00328 function formatRow( $row ) { 00329 return $this->mForm->formatRow( $row ); 00330 } 00331 00332 function getQueryInfo() { 00333 $conds = $this->mConds; 00334 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) . 00335 'OR pr_expiry IS NULL)'; 00336 $conds[] = 'page_id=pr_page'; 00337 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type ); 00338 00339 if( $this->sizetype=='min' ) { 00340 $conds[] = 'page_len>=' . $this->size; 00341 } elseif( $this->sizetype=='max' ) { 00342 $conds[] = 'page_len<=' . $this->size; 00343 } 00344 00345 if( $this->indefonly ) { 00346 $db = wfGetDB( DB_SLAVE ); 00347 $conds[] = "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL"; 00348 } 00349 if( $this->cascadeonly ) { 00350 $conds[] = "pr_cascade = '1'"; 00351 } 00352 00353 if( $this->level ) 00354 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level ); 00355 if( !is_null($this->namespace) ) 00356 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace ); 00357 return array( 00358 'tables' => array( 'page_restrictions', 'page' ), 00359 'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade', 00360 'conds' => $conds 00361 ); 00362 } 00363 00364 function getIndexField() { 00365 return 'pr_id'; 00366 } 00367 }