MediaWiki  REL1_19
SpecialProtectedpages.php
Go to the documentation of this file.
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                         $s = $pager->getNavigationBar();
00062                         $s .= "<ul>" .
00063                                 $pager->getBody() .
00064                                 "</ul>";
00065                         $s .= $pager->getNavigationBar();
00066                 } else {
00067                         $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
00068                 }
00069                 $this->getOutput()->addHTML( $s );
00070         }
00071 
00077         public function formatRow( $row ) {
00078                 wfProfileIn( __METHOD__ );
00079 
00080                 static $infinity = null;
00081 
00082                 if( is_null( $infinity ) ){
00083                         $infinity = wfGetDB( DB_SLAVE )->getInfinity();
00084                 }
00085 
00086                 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
00087                 $link = Linker::link( $title );
00088 
00089                 $description_items = array ();
00090 
00091                 $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
00092 
00093                 $description_items[] = $protType;
00094 
00095                 if( $row->pr_cascade ) {
00096                         $description_items[] = wfMsg( 'protect-summary-cascade' );
00097                 }
00098 
00099                 $stxt = '';
00100                 $lang = $this->getLanguage();
00101 
00102                 $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW );
00103                 if( $expiry != $infinity ) {
00104 
00105                         $expiry_description = wfMsg(
00106                                 'protect-expiring-local',
00107                                 $lang->timeanddate( $expiry, true ),
00108                                 $lang->date( $expiry, true ),
00109                                 $lang->time( $expiry, true )
00110                         );
00111 
00112                         $description_items[] = htmlspecialchars($expiry_description);
00113                 }
00114 
00115                 if(!is_null($size = $row->page_len)) {
00116                         $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size );
00117                 }
00118 
00119                 # Show a link to the change protection form for allowed users otherwise a link to the protection log
00120                 if( $this->getUser()->isAllowed( 'protect' ) ) {
00121                         $changeProtection = ' (' . Linker::linkKnown(
00122                                 $title,
00123                                 wfMsgHtml( 'protect_change' ),
00124                                 array(),
00125                                 array( 'action' => 'unprotect' )
00126                         ) . ')';
00127                 } else {
00128                         $ltitle = SpecialPage::getTitleFor( 'Log' );
00129                         $changeProtection = ' (' . Linker::linkKnown(
00130                                 $ltitle,
00131                                 wfMsgHtml( 'protectlogpage' ),
00132                                 array(),
00133                                 array(
00134                                         'type' => 'protect',
00135                                         'page' => $title->getPrefixedText()
00136                                 )
00137                         ) . ')';
00138                 }
00139 
00140                 wfProfileOut( __METHOD__ );
00141 
00142                 return Html::rawElement(
00143                         'li',
00144                         array(),
00145                         $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
00146         }
00147 
00158         protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
00159                 global $wgScript;
00160                 $title = $this->getTitle();
00161                 return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
00162                         Xml::openElement( 'fieldset' ) .
00163                         Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
00164                         Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
00165                         $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00166                         $this->getTypeMenu( $type ) . "&#160;\n" .
00167                         $this->getLevelMenu( $level ) . "&#160;\n" .
00168                         "<br /><span style='white-space: nowrap'>" .
00169                         $this->getExpiryCheck( $indefOnly ) . "&#160;\n" .
00170                         $this->getCascadeCheck( $cascadeOnly ) . "&#160;\n" .
00171                         "</span><br /><span style='white-space: nowrap'>" .
00172                         $this->getSizeLimit( $sizetype, $size ) . "&#160;\n" .
00173                         "</span>" .
00174                         "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00175                         Xml::closeElement( 'fieldset' ) .
00176                         Xml::closeElement( 'form' );
00177         }
00178 
00186         protected function getNamespaceMenu( $namespace = null ) {
00187                 return "<span style='white-space: nowrap'>" .
00188                         Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;'
00189                         . Xml::namespaceSelector( $namespace, '' ) . "</span>";
00190         }
00191 
00195         protected function getExpiryCheck( $indefOnly ) {
00196                 return
00197                         Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
00198         }
00199 
00203         protected function getCascadeCheck( $cascadeOnly ) {
00204                 return
00205                         Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
00206         }
00207 
00211         protected function getSizeLimit( $sizetype, $size ) {
00212                 $max = $sizetype === 'max';
00213 
00214                 return
00215                         Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
00216                         '&#160;' .
00217                         Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
00218                         '&#160;' .
00219                         Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
00220                         '&#160;' .
00221                         Xml::label( wfMsg('pagesize'), 'wpsize' );
00222         }
00223 
00229         protected function getTypeMenu( $pr_type ) {
00230                 $m = array(); // Temporary array
00231                 $options = array();
00232 
00233                 // First pass to load the log names
00234                 foreach( Title::getFilteredRestrictionTypes( true ) as $type ) {
00235                         $text = wfMsg("restriction-$type");
00236                         $m[$text] = $type;
00237                 }
00238 
00239                 // Third pass generates sorted XHTML content
00240                 foreach( $m as $text => $type ) {
00241                         $selected = ($type == $pr_type );
00242                         $options[] = Xml::option( $text, $type, $selected ) . "\n";
00243                 }
00244 
00245                 return "<span style='white-space: nowrap'>" .
00246                         Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&#160;' .
00247                         Xml::tags( 'select',
00248                                 array( 'id' => $this->IdType, 'name' => $this->IdType ),
00249                                 implode( "\n", $options ) ) . "</span>";
00250         }
00251 
00257         protected function getLevelMenu( $pr_level ) {
00258                 global $wgRestrictionLevels;
00259 
00260                 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
00261                 $options = array();
00262 
00263                 // First pass to load the log names
00264                 foreach( $wgRestrictionLevels as $type ) {
00265                         // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
00266                         if( $type !='' && $type !='*') {
00267                                 $text = wfMsg("restriction-level-$type");
00268                                 $m[$text] = $type;
00269                         }
00270                 }
00271 
00272                 // Third pass generates sorted XHTML content
00273                 foreach( $m as $text => $type ) {
00274                         $selected = ($type == $pr_level );
00275                         $options[] = Xml::option( $text, $type, $selected );
00276                 }
00277 
00278                 return "<span style='white-space: nowrap'>" .
00279                         Xml::label( wfMsg( 'restriction-level' ) , $this->IdLevel ) . ' ' .
00280                         Xml::tags( 'select',
00281                                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00282                                 implode( "\n", $options ) ) . "</span>";
00283         }
00284 }
00285 
00290 class ProtectedPagesPager extends AlphabeticPager {
00291         public $mForm, $mConds;
00292         private $type, $level, $namespace, $sizetype, $size, $indefonly;
00293 
00294         function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
00295                 $indefonly = false, $cascadeonly = false )
00296         {
00297                 $this->mForm = $form;
00298                 $this->mConds = $conds;
00299                 $this->type = ( $type ) ? $type : 'edit';
00300                 $this->level = $level;
00301                 $this->namespace = $namespace;
00302                 $this->sizetype = $sizetype;
00303                 $this->size = intval($size);
00304                 $this->indefonly = (bool)$indefonly;
00305                 $this->cascadeonly = (bool)$cascadeonly;
00306                 parent::__construct( $form->getContext() );
00307         }
00308 
00309         function getStartBody() {
00310                 # Do a link batch query
00311                 $lb = new LinkBatch;
00312                 foreach ( $this->mResult as $row ) {
00313                         $lb->add( $row->page_namespace, $row->page_title );
00314                 }
00315                 $lb->execute();
00316                 return '';
00317         }
00318 
00319         function formatRow( $row ) {
00320                 return $this->mForm->formatRow( $row );
00321         }
00322 
00323         function getQueryInfo() {
00324                 $conds = $this->mConds;
00325                 $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
00326                                 'OR pr_expiry IS NULL)';
00327                 $conds[] = 'page_id=pr_page';
00328                 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
00329 
00330                 if( $this->sizetype=='min' ) {
00331                         $conds[] = 'page_len>=' . $this->size;
00332                 } elseif( $this->sizetype=='max' ) {
00333                         $conds[] = 'page_len<=' . $this->size;
00334                 }
00335 
00336                 if( $this->indefonly ) {
00337                         $db = wfGetDB( DB_SLAVE );
00338                         $conds[] = "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL";
00339                 }
00340                 if( $this->cascadeonly ) {
00341                         $conds[] = "pr_cascade = '1'";
00342                 }
00343 
00344                 if( $this->level )
00345                         $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
00346                 if( !is_null($this->namespace) )
00347                         $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
00348                 return array(
00349                         'tables' => array( 'page_restrictions', 'page' ),
00350                         'fields' => 'pr_id,page_namespace,page_title,page_len,pr_type,pr_level,pr_expiry,pr_cascade',
00351                         'conds' => $conds
00352                 );
00353         }
00354 
00355         function getIndexField() {
00356                 return 'pr_id';
00357         }
00358 }