MediaWiki
REL1_21
|
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 if( !$title ) { 00087 return Html::rawElement( 'li', array(), 00088 Html::element( 'span', array( 'class' => 'mw-invalidtitle' ), 00089 Linker::getInvalidTitleDescription( $this->getContext(), $row->page_namespace, $row->page_title ) ) ) . "\n"; 00090 } 00091 00092 $link = Linker::link( $title ); 00093 00094 $description_items = array (); 00095 00096 $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped(); 00097 00098 $description_items[] = $protType; 00099 00100 if( $row->pr_cascade ) { 00101 $description_items[] = $this->msg( 'protect-summary-cascade' )->text(); 00102 } 00103 00104 $stxt = ''; 00105 $lang = $this->getLanguage(); 00106 00107 $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW ); 00108 if( $expiry != $infinity ) { 00109 $user = $this->getUser(); 00110 $description_items[] = $this->msg( 00111 'protect-expiring-local', 00112 $lang->userTimeAndDate( $expiry, $user ), 00113 $lang->userDate( $expiry, $user ), 00114 $lang->userTime( $expiry, $user ) 00115 )->escaped(); 00116 } 00117 00118 if( !is_null( $size = $row->page_len ) ) { 00119 $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size ); 00120 } 00121 00122 # Show a link to the change protection form for allowed users otherwise a link to the protection log 00123 if( $this->getUser()->isAllowed( 'protect' ) ) { 00124 $changeProtection = Linker::linkKnown( 00125 $title, 00126 $this->msg( 'protect_change' )->escaped(), 00127 array(), 00128 array( 'action' => 'unprotect' ) 00129 ); 00130 } else { 00131 $ltitle = SpecialPage::getTitleFor( 'Log' ); 00132 $changeProtection = Linker::linkKnown( 00133 $ltitle, 00134 $this->msg( 'protectlogpage' )->escaped(), 00135 array(), 00136 array( 00137 'type' => 'protect', 00138 'page' => $title->getPrefixedText() 00139 ) 00140 ); 00141 } 00142 00143 $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped(); 00144 00145 wfProfileOut( __METHOD__ ); 00146 00147 return Html::rawElement( 00148 'li', 00149 array(), 00150 $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n"; 00151 } 00152 00163 protected function showOptions( $namespace, $type = 'edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) { 00164 global $wgScript; 00165 $title = $this->getTitle(); 00166 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . 00167 Xml::openElement( 'fieldset' ) . 00168 Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) . 00169 Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" . 00170 $this->getNamespaceMenu( $namespace ) . " \n" . 00171 $this->getTypeMenu( $type ) . " \n" . 00172 $this->getLevelMenu( $level ) . " \n" . 00173 "<br /><span style='white-space: nowrap'>" . 00174 $this->getExpiryCheck( $indefOnly ) . " \n" . 00175 $this->getCascadeCheck( $cascadeOnly ) . " \n" . 00176 "</span><br /><span style='white-space: nowrap'>" . 00177 $this->getSizeLimit( $sizetype, $size ) . " \n" . 00178 "</span>" . 00179 " " . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" . 00180 Xml::closeElement( 'fieldset' ) . 00181 Xml::closeElement( 'form' ); 00182 } 00183 00191 protected function getNamespaceMenu( $namespace = null ) { 00192 return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ), 00193 Html::namespaceSelector( 00194 array( 00195 'selected' => $namespace, 00196 'all' => '', 00197 'label' => $this->msg( 'namespace' )->text() 00198 ), array( 00199 'name' => 'namespace', 00200 'id' => 'namespace', 00201 'class' => 'namespaceselector', 00202 ) 00203 ) 00204 ); 00205 } 00206 00210 protected function getExpiryCheck( $indefOnly ) { 00211 return 00212 Xml::checkLabel( $this->msg( 'protectedpages-indef' )->text(), 'indefonly', 'indefonly', $indefOnly ) . "\n"; 00213 } 00214 00218 protected function getCascadeCheck( $cascadeOnly ) { 00219 return 00220 Xml::checkLabel( $this->msg( 'protectedpages-cascade' )->text(), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n"; 00221 } 00222 00226 protected function getSizeLimit( $sizetype, $size ) { 00227 $max = $sizetype === 'max'; 00228 00229 return 00230 Xml::radioLabel( $this->msg( 'minimum-size' )->text(), 'sizetype', 'min', 'wpmin', !$max ) . 00231 ' ' . 00232 Xml::radioLabel( $this->msg( 'maximum-size' )->text(), 'sizetype', 'max', 'wpmax', $max ) . 00233 ' ' . 00234 Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) . 00235 ' ' . 00236 Xml::label( $this->msg( 'pagesize' )->text(), 'wpsize' ); 00237 } 00238 00244 protected function getTypeMenu( $pr_type ) { 00245 $m = array(); // Temporary array 00246 $options = array(); 00247 00248 // First pass to load the log names 00249 foreach( Title::getFilteredRestrictionTypes( true ) as $type ) { 00250 $text = $this->msg( "restriction-$type" )->text(); 00251 $m[$text] = $type; 00252 } 00253 00254 // Third pass generates sorted XHTML content 00255 foreach( $m as $text => $type ) { 00256 $selected = ($type == $pr_type ); 00257 $options[] = Xml::option( $text, $type, $selected ) . "\n"; 00258 } 00259 00260 return "<span style='white-space: nowrap'>" . 00261 Xml::label( $this->msg( 'restriction-type' )->text(), $this->IdType ) . ' ' . 00262 Xml::tags( 'select', 00263 array( 'id' => $this->IdType, 'name' => $this->IdType ), 00264 implode( "\n", $options ) ) . "</span>"; 00265 } 00266 00272 protected function getLevelMenu( $pr_level ) { 00273 global $wgRestrictionLevels; 00274 00275 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array 00276 $options = array(); 00277 00278 // First pass to load the log names 00279 foreach( $wgRestrictionLevels as $type ) { 00280 // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed' 00281 if( $type != '' && $type != '*' ) { 00282 $text = $this->msg( "restriction-level-$type" )->text(); 00283 $m[$text] = $type; 00284 } 00285 } 00286 00287 // Third pass generates sorted XHTML content 00288 foreach( $m as $text => $type ) { 00289 $selected = ($type == $pr_level ); 00290 $options[] = Xml::option( $text, $type, $selected ); 00291 } 00292 00293 return "<span style='white-space: nowrap'>" . 00294 Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . ' ' . 00295 Xml::tags( 'select', 00296 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ), 00297 implode( "\n", $options ) ) . "</span>"; 00298 } 00299 00300 protected function getGroupName() { 00301 return 'maintenance'; 00302 } 00303 } 00304 00309 class ProtectedPagesPager extends AlphabeticPager { 00310 public $mForm, $mConds; 00311 private $type, $level, $namespace, $sizetype, $size, $indefonly; 00312 00313 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype = '', $size = 0, 00314 $indefonly = false, $cascadeonly = false ) 00315 { 00316 $this->mForm = $form; 00317 $this->mConds = $conds; 00318 $this->type = ( $type ) ? $type : 'edit'; 00319 $this->level = $level; 00320 $this->namespace = $namespace; 00321 $this->sizetype = $sizetype; 00322 $this->size = intval( $size ); 00323 $this->indefonly = (bool)$indefonly; 00324 $this->cascadeonly = (bool)$cascadeonly; 00325 parent::__construct( $form->getContext() ); 00326 } 00327 00328 function getStartBody() { 00329 # Do a link batch query 00330 $lb = new LinkBatch; 00331 foreach ( $this->mResult as $row ) { 00332 $lb->add( $row->page_namespace, $row->page_title ); 00333 } 00334 $lb->execute(); 00335 return ''; 00336 } 00337 00338 function formatRow( $row ) { 00339 return $this->mForm->formatRow( $row ); 00340 } 00341 00342 function getQueryInfo() { 00343 $conds = $this->mConds; 00344 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) . 00345 'OR pr_expiry IS NULL)'; 00346 $conds[] = 'page_id=pr_page'; 00347 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type ); 00348 00349 if( $this->sizetype == 'min' ) { 00350 $conds[] = 'page_len>=' . $this->size; 00351 } elseif( $this->sizetype == 'max' ) { 00352 $conds[] = 'page_len<=' . $this->size; 00353 } 00354 00355 if( $this->indefonly ) { 00356 $conds[] = "pr_expiry = {$this->mDb->addQuotes( $this->mDb->getInfinity() )} OR pr_expiry IS NULL"; 00357 } 00358 if( $this->cascadeonly ) { 00359 $conds[] = 'pr_cascade = 1'; 00360 } 00361 00362 if( $this->level ) 00363 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level ); 00364 if( !is_null( $this->namespace ) ) 00365 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace ); 00366 return array( 00367 'tables' => array( 'page_restrictions', 'page' ), 00368 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len', 00369 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ), 00370 'conds' => $conds 00371 ); 00372 } 00373 00374 function getIndexField() { 00375 return 'pr_id'; 00376 } 00377 }