MediaWiki
REL1_22
|
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( 00057 $this, 00058 array(), 00059 $type, 00060 $level, 00061 $ns, 00062 $sizetype, 00063 $size, 00064 $indefOnly, 00065 $cascadeOnly 00066 ); 00067 00068 $this->getOutput()->addHTML( $this->showOptions( 00069 $ns, 00070 $type, 00071 $level, 00072 $sizetype, 00073 $size, 00074 $indefOnly, 00075 $cascadeOnly 00076 ) ); 00077 00078 if ( $pager->getNumRows() ) { 00079 $this->getOutput()->addHTML( 00080 $pager->getNavigationBar() . 00081 '<ul>' . $pager->getBody() . '</ul>' . 00082 $pager->getNavigationBar() 00083 ); 00084 } else { 00085 $this->getOutput()->addWikiMsg( 'protectedpagesempty' ); 00086 } 00087 } 00088 00094 public function formatRow( $row ) { 00095 wfProfileIn( __METHOD__ ); 00096 00097 static $infinity = null; 00098 00099 if ( is_null( $infinity ) ) { 00100 $infinity = wfGetDB( DB_SLAVE )->getInfinity(); 00101 } 00102 00103 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); 00104 if ( !$title ) { 00105 wfProfileOut( __METHOD__ ); 00106 00107 return Html::rawElement( 00108 'li', 00109 array(), 00110 Html::element( 00111 'span', 00112 array( 'class' => 'mw-invalidtitle' ), 00113 Linker::getInvalidTitleDescription( 00114 $this->getContext(), 00115 $row->page_namespace, 00116 $row->page_title 00117 ) 00118 ) 00119 ) . "\n"; 00120 } 00121 00122 $link = Linker::link( $title ); 00123 00124 $description_items = array(); 00125 00126 // Messages: restriction-level-sysop, restriction-level-autoconfirmed 00127 $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped(); 00128 00129 $description_items[] = $protType; 00130 00131 if ( $row->pr_cascade ) { 00132 $description_items[] = $this->msg( 'protect-summary-cascade' )->text(); 00133 } 00134 00135 $stxt = ''; 00136 $lang = $this->getLanguage(); 00137 00138 $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW ); 00139 if ( $expiry != $infinity ) { 00140 $user = $this->getUser(); 00141 $description_items[] = $this->msg( 00142 'protect-expiring-local', 00143 $lang->userTimeAndDate( $expiry, $user ), 00144 $lang->userDate( $expiry, $user ), 00145 $lang->userTime( $expiry, $user ) 00146 )->escaped(); 00147 } 00148 00149 if ( !is_null( $size = $row->page_len ) ) { 00150 $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size ); 00151 } 00152 00153 // Show a link to the change protection form for allowed users otherwise 00154 // a link to the protection log 00155 if ( $this->getUser()->isAllowed( 'protect' ) ) { 00156 $changeProtection = Linker::linkKnown( 00157 $title, 00158 $this->msg( 'protect_change' )->escaped(), 00159 array(), 00160 array( 'action' => 'unprotect' ) 00161 ); 00162 } else { 00163 $ltitle = SpecialPage::getTitleFor( 'Log' ); 00164 $changeProtection = Linker::linkKnown( 00165 $ltitle, 00166 $this->msg( 'protectlogpage' )->escaped(), 00167 array(), 00168 array( 00169 'type' => 'protect', 00170 'page' => $title->getPrefixedText() 00171 ) 00172 ); 00173 } 00174 00175 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection ) 00176 ->escaped(); 00177 00178 wfProfileOut( __METHOD__ ); 00179 00180 return Html::rawElement( 00181 'li', 00182 array(), 00183 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . 00184 $changeProtection 00185 ) . "\n"; 00186 } 00187 00198 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype, 00199 $size, $indefOnly, $cascadeOnly 00200 ) { 00201 global $wgScript; 00202 00203 $title = $this->getTitle(); 00204 00205 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . 00206 Xml::openElement( 'fieldset' ) . 00207 Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) . 00208 Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" . 00209 $this->getNamespaceMenu( $namespace ) . " \n" . 00210 $this->getTypeMenu( $type ) . " \n" . 00211 $this->getLevelMenu( $level ) . " \n" . 00212 "<br /><span style='white-space: nowrap'>" . 00213 $this->getExpiryCheck( $indefOnly ) . " \n" . 00214 $this->getCascadeCheck( $cascadeOnly ) . " \n" . 00215 "</span><br /><span style='white-space: nowrap'>" . 00216 $this->getSizeLimit( $sizetype, $size ) . " \n" . 00217 "</span>" . 00218 " " . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" . 00219 Xml::closeElement( 'fieldset' ) . 00220 Xml::closeElement( 'form' ); 00221 } 00222 00230 protected function getNamespaceMenu( $namespace = null ) { 00231 return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ), 00232 Html::namespaceSelector( 00233 array( 00234 'selected' => $namespace, 00235 'all' => '', 00236 'label' => $this->msg( 'namespace' )->text() 00237 ), array( 00238 'name' => 'namespace', 00239 'id' => 'namespace', 00240 'class' => 'namespaceselector', 00241 ) 00242 ) 00243 ); 00244 } 00245 00250 protected function getExpiryCheck( $indefOnly ) { 00251 return Xml::checkLabel( 00252 $this->msg( 'protectedpages-indef' )->text(), 00253 'indefonly', 00254 'indefonly', 00255 $indefOnly 00256 ) . "\n"; 00257 } 00258 00263 protected function getCascadeCheck( $cascadeOnly ) { 00264 return Xml::checkLabel( 00265 $this->msg( 'protectedpages-cascade' )->text(), 00266 'cascadeonly', 00267 'cascadeonly', 00268 $cascadeOnly 00269 ) . "\n"; 00270 } 00271 00277 protected function getSizeLimit( $sizetype, $size ) { 00278 $max = $sizetype === 'max'; 00279 00280 return Xml::radioLabel( 00281 $this->msg( 'minimum-size' )->text(), 00282 'sizetype', 00283 'min', 00284 'wpmin', 00285 !$max 00286 ) . 00287 ' ' . 00288 Xml::radioLabel( 00289 $this->msg( 'maximum-size' )->text(), 00290 'sizetype', 00291 'max', 00292 'wpmax', 00293 $max 00294 ) . 00295 ' ' . 00296 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) . 00297 ' ' . 00298 Xml::label( $this->msg( 'pagesize' )->text(), 'wpsize' ); 00299 } 00300 00306 protected function getTypeMenu( $pr_type ) { 00307 $m = array(); // Temporary array 00308 $options = array(); 00309 00310 // First pass to load the log names 00311 foreach ( Title::getFilteredRestrictionTypes( true ) as $type ) { 00312 // Messages: restriction-edit, restriction-move, restriction-create, restriction-upload 00313 $text = $this->msg( "restriction-$type" )->text(); 00314 $m[$text] = $type; 00315 } 00316 00317 // Third pass generates sorted XHTML content 00318 foreach ( $m as $text => $type ) { 00319 $selected = ( $type == $pr_type ); 00320 $options[] = Xml::option( $text, $type, $selected ) . "\n"; 00321 } 00322 00323 return "<span style='white-space: nowrap'>" . 00324 Xml::label( $this->msg( 'restriction-type' )->text(), $this->IdType ) . ' ' . 00325 Xml::tags( 'select', 00326 array( 'id' => $this->IdType, 'name' => $this->IdType ), 00327 implode( "\n", $options ) ) . "</span>"; 00328 } 00329 00335 protected function getLevelMenu( $pr_level ) { 00336 global $wgRestrictionLevels; 00337 00338 // Temporary array 00339 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); 00340 $options = array(); 00341 00342 // First pass to load the log names 00343 foreach ( $wgRestrictionLevels as $type ) { 00344 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed' 00345 if ( $type != '' && $type != '*' ) { 00346 $text = $this->msg( "restriction-level-$type" )->text(); 00347 $m[$text] = $type; 00348 } 00349 } 00350 00351 // Third pass generates sorted XHTML content 00352 foreach ( $m as $text => $type ) { 00353 $selected = ( $type == $pr_level ); 00354 $options[] = Xml::option( $text, $type, $selected ); 00355 } 00356 00357 return "<span style='white-space: nowrap'>" . 00358 Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . ' ' . 00359 Xml::tags( 'select', 00360 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ), 00361 implode( "\n", $options ) ) . "</span>"; 00362 } 00363 00364 protected function getGroupName() { 00365 return 'maintenance'; 00366 } 00367 } 00368 00373 class ProtectedPagesPager extends AlphabeticPager { 00374 public $mForm, $mConds; 00375 private $type, $level, $namespace, $sizetype, $size, $indefonly; 00376 00377 function __construct( $form, $conds = array(), $type, $level, $namespace, 00378 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false 00379 ) { 00380 $this->mForm = $form; 00381 $this->mConds = $conds; 00382 $this->type = ( $type ) ? $type : 'edit'; 00383 $this->level = $level; 00384 $this->namespace = $namespace; 00385 $this->sizetype = $sizetype; 00386 $this->size = intval( $size ); 00387 $this->indefonly = (bool)$indefonly; 00388 $this->cascadeonly = (bool)$cascadeonly; 00389 parent::__construct( $form->getContext() ); 00390 } 00391 00392 function getStartBody() { 00393 # Do a link batch query 00394 $lb = new LinkBatch; 00395 foreach ( $this->mResult as $row ) { 00396 $lb->add( $row->page_namespace, $row->page_title ); 00397 } 00398 $lb->execute(); 00399 00400 return ''; 00401 } 00402 00403 function formatRow( $row ) { 00404 return $this->mForm->formatRow( $row ); 00405 } 00406 00407 function getQueryInfo() { 00408 $conds = $this->mConds; 00409 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) . 00410 'OR pr_expiry IS NULL)'; 00411 $conds[] = 'page_id=pr_page'; 00412 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type ); 00413 00414 if ( $this->sizetype == 'min' ) { 00415 $conds[] = 'page_len>=' . $this->size; 00416 } elseif ( $this->sizetype == 'max' ) { 00417 $conds[] = 'page_len<=' . $this->size; 00418 } 00419 00420 if ( $this->indefonly ) { 00421 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() ); 00422 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL"; 00423 } 00424 if ( $this->cascadeonly ) { 00425 $conds[] = 'pr_cascade = 1'; 00426 } 00427 00428 if ( $this->level ) { 00429 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level ); 00430 } 00431 if ( !is_null( $this->namespace ) ) { 00432 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace ); 00433 } 00434 00435 return array( 00436 'tables' => array( 'page_restrictions', 'page' ), 00437 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len', 00438 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ), 00439 'conds' => $conds 00440 ); 00441 } 00442 00443 function getIndexField() { 00444 return 'pr_id'; 00445 } 00446 }