MediaWiki  REL1_19
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                         $s = $pager->getNavigationBar();
00060                         $s .= "<ul>" .
00061                                 $pager->getBody() .
00062                                 "</ul>";
00063                         $s .= $pager->getNavigationBar();
00064                 } else {
00065                         $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
00066                 }
00067                 $this->getOutput()->addHTML( $s );
00068         }
00069 
00075         function formatRow( $row ) {
00076                 wfProfileIn( __METHOD__ );
00077 
00078                 static $infinity = null;
00079 
00080                 if( is_null( $infinity ) ){
00081                         $infinity = wfGetDB( DB_SLAVE )->getInfinity();
00082                 }
00083 
00084                 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
00085                 $link = Linker::link( $title );
00086 
00087                 $description_items = array ();
00088 
00089                 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
00090 
00091                 $description_items[] = $protType;
00092 
00093                 $lang = $this->getLanguage();
00094                 $expiry = strlen( $row->pt_expiry ) ? $lang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
00095                 if( $expiry != $infinity ) {
00096                         $expiry_description = wfMsg(
00097                                 'protect-expiring-local',
00098                                 $lang->timeanddate( $expiry, true ),
00099                                 $lang->date( $expiry, true ),
00100                                 $lang->time( $expiry, true )
00101                         );
00102 
00103                         $description_items[] = htmlspecialchars($expiry_description);
00104                 }
00105 
00106                 wfProfileOut( __METHOD__ );
00107 
00108                 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
00109         }
00110 
00117         function showOptions( $namespace, $type='edit', $level ) {
00118                 global $wgScript;
00119                 $action = htmlspecialchars( $wgScript );
00120                 $title = $this->getTitle();
00121                 $special = htmlspecialchars( $title->getPrefixedDBkey() );
00122                 return "<form action=\"$action\" method=\"get\">\n" .
00123                         '<fieldset>' .
00124                         Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
00125                         Html::hidden( 'title', $special ) . "&#160;\n" .
00126                         $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00127                         $this->getLevelMenu( $level ) . "&#160;\n" .
00128                         "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00129                         "</fieldset></form>";
00130         }
00131 
00139         function getNamespaceMenu( $namespace = null ) {
00140                 return Xml::label( wfMsg( 'namespace' ), 'namespace' )
00141                         . '&#160;'
00142                         . Xml::namespaceSelector( $namespace, '' );
00143         }
00144 
00149         function getLevelMenu( $pr_level ) {
00150                 global $wgRestrictionLevels;
00151 
00152                 $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
00153                 $options = array();
00154 
00155                 // First pass to load the log names
00156                 foreach( $wgRestrictionLevels as $type ) {
00157                         if ( $type !='' && $type !='*') {
00158                                 $text = wfMsg("restriction-level-$type");
00159                                 $m[$text] = $type;
00160                         }
00161                 }
00162                 // Is there only one level (aside from "all")?
00163                 if( count($m) <= 2 ) {
00164                         return '';
00165                 }
00166                 // Third pass generates sorted XHTML content
00167                 foreach( $m as $text => $type ) {
00168                         $selected = ($type == $pr_level );
00169                         $options[] = Xml::option( $text, $type, $selected );
00170                 }
00171 
00172                 return
00173                         Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&#160;' .
00174                         Xml::tags( 'select',
00175                                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00176                                 implode( "\n", $options ) );
00177         }
00178 }
00179 
00184 class ProtectedTitlesPager extends AlphabeticPager {
00185         public $mForm, $mConds;
00186 
00187         function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
00188                 $this->mForm = $form;
00189                 $this->mConds = $conds;
00190                 $this->level = $level;
00191                 $this->namespace = $namespace;
00192                 $this->size = intval($size);
00193                 parent::__construct( $form->getContext() );
00194         }
00195 
00196         function getStartBody() {
00197                 wfProfileIn( __METHOD__ );
00198                 # Do a link batch query
00199                 $this->mResult->seek( 0 );
00200                 $lb = new LinkBatch;
00201 
00202                 foreach ( $this->mResult as $row ) {
00203                         $lb->add( $row->pt_namespace, $row->pt_title );
00204                 }
00205 
00206                 $lb->execute();
00207                 wfProfileOut( __METHOD__ );
00208                 return '';
00209         }
00210 
00214         function getTitle() {
00215                 return SpecialPage::getTitleFor( 'Protectedtitles' );
00216         }
00217 
00218         function formatRow( $row ) {
00219                 return $this->mForm->formatRow( $row );
00220         }
00221 
00225         function getQueryInfo() {
00226                 $conds = $this->mConds;
00227                 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00228                 if( $this->level )
00229                         $conds['pt_create_perm'] = $this->level;
00230                 if( !is_null($this->namespace) )
00231                         $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00232                 return array(
00233                         'tables' => 'protected_titles',
00234                         'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
00235                         'conds' => $conds
00236                 );
00237         }
00238 
00239         function getIndexField() {
00240                 return 'pt_timestamp';
00241         }
00242 }
00243