MediaWiki  REL1_21
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                 if( !$title ) {
00085                         return Html::rawElement( 'li', array(),
00086                                 Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
00087                                         Linker::getInvalidTitleDescription( $this->getContext(), $row->pt_namespace, $row->pt_title ) ) ) . "\n";
00088                 }
00089 
00090                 $link = Linker::link( $title );
00091 
00092                 $description_items = array ();
00093 
00094                 $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
00095 
00096                 $description_items[] = $protType;
00097 
00098                 $lang = $this->getLanguage();
00099                 $expiry = strlen( $row->pt_expiry ) ? $lang->formatExpiry( $row->pt_expiry, TS_MW ) : $infinity;
00100                 if( $expiry != $infinity ) {
00101                         $user = $this->getUser();
00102                         $description_items[] = $this->msg(
00103                                 'protect-expiring-local',
00104                                 $lang->userTimeAndDate( $expiry, $user ),
00105                                 $lang->userDate( $expiry, $user ),
00106                                 $lang->userTime( $expiry, $user )
00107                         )->escaped();
00108                 }
00109 
00110                 wfProfileOut( __METHOD__ );
00111 
00112                 return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
00113         }
00114 
00122         function showOptions( $namespace, $type = 'edit', $level ) {
00123                 global $wgScript;
00124                 $action = htmlspecialchars( $wgScript );
00125                 $title = $this->getTitle();
00126                 $special = htmlspecialchars( $title->getPrefixedDBkey() );
00127                 return "<form action=\"$action\" method=\"get\">\n" .
00128                         '<fieldset>' .
00129                         Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
00130                         Html::hidden( 'title', $special ) . "&#160;\n" .
00131                         $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00132                         $this->getLevelMenu( $level ) . "&#160;\n" .
00133                         "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
00134                         "</fieldset></form>";
00135         }
00136 
00144         function getNamespaceMenu( $namespace = null ) {
00145                 return Html::namespaceSelector(
00146                         array(
00147                                 'selected' => $namespace,
00148                                 'all' => '',
00149                                 'label' => $this->msg( 'namespace' )->text()
00150                         ), array(
00151                                 'name'  => 'namespace',
00152                                 'id'    => 'namespace',
00153                                 'class' => 'namespaceselector',
00154                         )
00155                 );
00156         }
00157 
00162         function getLevelMenu( $pr_level ) {
00163                 global $wgRestrictionLevels;
00164 
00165                 $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
00166                 $options = array();
00167 
00168                 // First pass to load the log names
00169                 foreach( $wgRestrictionLevels as $type ) {
00170                         if ( $type != '' && $type != '*' ) {
00171                                 $text = $this->msg( "restriction-level-$type" )->text();
00172                                 $m[$text] = $type;
00173                         }
00174                 }
00175                 // Is there only one level (aside from "all")?
00176                 if( count( $m ) <= 2 ) {
00177                         return '';
00178                 }
00179                 // Third pass generates sorted XHTML content
00180                 foreach( $m as $text => $type ) {
00181                         $selected = ($type == $pr_level );
00182                         $options[] = Xml::option( $text, $type, $selected );
00183                 }
00184 
00185                 return
00186                         Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
00187                         Xml::tags( 'select',
00188                                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00189                                 implode( "\n", $options ) );
00190         }
00191 
00192         protected function getGroupName() {
00193                 return 'maintenance';
00194         }
00195 }
00196 
00201 class ProtectedTitlesPager extends AlphabeticPager {
00202         public $mForm, $mConds;
00203 
00204         function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype = '', $size = 0 ) {
00205                 $this->mForm = $form;
00206                 $this->mConds = $conds;
00207                 $this->level = $level;
00208                 $this->namespace = $namespace;
00209                 $this->size = intval($size);
00210                 parent::__construct( $form->getContext() );
00211         }
00212 
00213         function getStartBody() {
00214                 wfProfileIn( __METHOD__ );
00215                 # Do a link batch query
00216                 $this->mResult->seek( 0 );
00217                 $lb = new LinkBatch;
00218 
00219                 foreach ( $this->mResult as $row ) {
00220                         $lb->add( $row->pt_namespace, $row->pt_title );
00221                 }
00222 
00223                 $lb->execute();
00224                 wfProfileOut( __METHOD__ );
00225                 return '';
00226         }
00227 
00231         function getTitle() {
00232                 return $this->mForm->getTitle();
00233         }
00234 
00235         function formatRow( $row ) {
00236                 return $this->mForm->formatRow( $row );
00237         }
00238 
00242         function getQueryInfo() {
00243                 $conds = $this->mConds;
00244                 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00245                 if( $this->level )
00246                         $conds['pt_create_perm'] = $this->level;
00247                 if( !is_null( $this->namespace ) )
00248                         $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00249                 return array(
00250                         'tables' => 'protected_titles',
00251                         'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
00252                                 'pt_expiry', 'pt_timestamp' ),
00253                         'conds' => $conds
00254                 );
00255         }
00256 
00257         function getIndexField() {
00258                 return 'pt_timestamp';
00259         }
00260 }