MediaWiki  REL1_20
SpecialProtectedtitles.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialProtectedtitles extends SpecialPage {
00030 
00031         protected $IdLevel = 'level';
00032         protected $IdType  = 'type';
00033 
00034         public function __construct() {
00035                 parent::__construct( 'Protectedtitles' );
00036         }
00037 
00038         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 
00054                 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
00055 
00056                 $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
00057 
00058                 if ( $pager->getNumRows() ) {
00059                         $this->getOutput()->addHTML(
00060                                 $pager->getNavigationBar() .
00061                                 '<ul>' . $pager->getBody() . '</ul>' .
00062                                 $pager->getNavigationBar()
00063                         );
00064                 } else {
00065                         $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
00066                 }
00067         }
00068 
00074         function formatRow( $row ) {
00075                 wfProfileIn( __METHOD__ );
00076 
00077                 static $infinity = null;
00078 
00079                 if( is_null( $infinity ) ){
00080                         $infinity = wfGetDB( DB_SLAVE )->getInfinity();
00081                 }
00082 
00083                 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
00084                 $link = Linker::link( $title );
00085 
00086                 $description_items = array ();
00087 
00088                 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
00089 
00090                 $description_items[] = $protType;
00091 
00092                 $lang = $this->getLanguage();
00093                 $expiry = strlen( $row->pt_expiry ) ? $lang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
00094                 if( $expiry != $infinity ) {
00095                         $user = $this->getUser();
00096                         $description_items[] = $this->msg(
00097                                 'protect-expiring-local',
00098                                 $lang->userTimeAndDate( $expiry, $user ),
00099                                 $lang->userDate( $expiry, $user ),
00100                                 $lang->userTime( $expiry, $user )
00101                         )->escaped();
00102                 }
00103 
00104                 wfProfileOut( __METHOD__ );
00105 
00106                 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
00107         }
00108 
00116         function showOptions( $namespace, $type='edit', $level ) {
00117                 global $wgScript;
00118                 $action = htmlspecialchars( $wgScript );
00119                 $title = $this->getTitle();
00120                 $special = htmlspecialchars( $title->getPrefixedDBkey() );
00121                 return "<form action=\"$action\" method=\"get\">\n" .
00122                         '<fieldset>' .
00123                         Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
00124                         Html::hidden( 'title', $special ) . "&#160;\n" .
00125                         $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00126                         $this->getLevelMenu( $level ) . "&#160;\n" .
00127                         "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
00128                         "</fieldset></form>";
00129         }
00130 
00138         function getNamespaceMenu( $namespace = null ) {
00139                 return Html::namespaceSelector(
00140                         array(
00141                                 'selected' => $namespace,
00142                                 'all' => '',
00143                                 'label' => $this->msg( 'namespace' )->text()
00144                         ), array(
00145                                 'name'  => 'namespace',
00146                                 'id'    => 'namespace',
00147                                 'class' => 'namespaceselector',
00148                         )
00149                 );
00150         }
00151 
00156         function getLevelMenu( $pr_level ) {
00157                 global $wgRestrictionLevels;
00158 
00159                 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
00160                 $options = array();
00161 
00162                 // First pass to load the log names
00163                 foreach( $wgRestrictionLevels as $type ) {
00164                         if ( $type !='' && $type !='*') {
00165                                 $text = $this->msg( "restriction-level-$type" )->text();
00166                                 $m[$text] = $type;
00167                         }
00168                 }
00169                 // Is there only one level (aside from "all")?
00170                 if( count($m) <= 2 ) {
00171                         return '';
00172                 }
00173                 // Third pass generates sorted XHTML content
00174                 foreach( $m as $text => $type ) {
00175                         $selected = ($type == $pr_level );
00176                         $options[] = Xml::option( $text, $type, $selected );
00177                 }
00178 
00179                 return
00180                         Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
00181                         Xml::tags( 'select',
00182                                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00183                                 implode( "\n", $options ) );
00184         }
00185 }
00186 
00191 class ProtectedTitlesPager extends AlphabeticPager {
00192         public $mForm, $mConds;
00193 
00194         function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
00195                 $this->mForm = $form;
00196                 $this->mConds = $conds;
00197                 $this->level = $level;
00198                 $this->namespace = $namespace;
00199                 $this->size = intval($size);
00200                 parent::__construct( $form->getContext() );
00201         }
00202 
00203         function getStartBody() {
00204                 wfProfileIn( __METHOD__ );
00205                 # Do a link batch query
00206                 $this->mResult->seek( 0 );
00207                 $lb = new LinkBatch;
00208 
00209                 foreach ( $this->mResult as $row ) {
00210                         $lb->add( $row->pt_namespace, $row->pt_title );
00211                 }
00212 
00213                 $lb->execute();
00214                 wfProfileOut( __METHOD__ );
00215                 return '';
00216         }
00217 
00221         function getTitle() {
00222                 return $this->mForm->getTitle();
00223         }
00224 
00225         function formatRow( $row ) {
00226                 return $this->mForm->formatRow( $row );
00227         }
00228 
00232         function getQueryInfo() {
00233                 $conds = $this->mConds;
00234                 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00235                 if( $this->level )
00236                         $conds['pt_create_perm'] = $this->level;
00237                 if( !is_null($this->namespace) )
00238                         $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00239                 return array(
00240                         'tables' => 'protected_titles',
00241                         'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
00242                         'conds' => $conds
00243                 );
00244         }
00245 
00246         function getIndexField() {
00247                 return 'pt_timestamp';
00248         }
00249 }
00250