MediaWiki  REL1_22
SpecialProtectedtitles.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialProtectedtitles extends SpecialPage {
00030     protected $IdLevel = 'level';
00031     protected $IdType = 'type';
00032 
00033     public function __construct() {
00034         parent::__construct( 'Protectedtitles' );
00035     }
00036 
00037     function execute( $par ) {
00038         $this->setHeaders();
00039         $this->outputHeader();
00040 
00041         // Purge expired entries on one in every 10 queries
00042         if ( !mt_rand( 0, 10 ) ) {
00043             Title::purgeExpiredRestrictions();
00044         }
00045 
00046         $request = $this->getRequest();
00047         $type = $request->getVal( $this->IdType );
00048         $level = $request->getVal( $this->IdLevel );
00049         $sizetype = $request->getVal( 'sizetype' );
00050         $size = $request->getIntOrNull( 'size' );
00051         $NS = $request->getIntOrNull( 'namespace' );
00052 
00053         $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
00054 
00055         $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
00056 
00057         if ( $pager->getNumRows() ) {
00058             $this->getOutput()->addHTML(
00059                 $pager->getNavigationBar() .
00060                     '<ul>' . $pager->getBody() . '</ul>' .
00061                     $pager->getNavigationBar()
00062             );
00063         } else {
00064             $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
00065         }
00066     }
00067 
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             wfProfileOut( __METHOD__ );
00086 
00087             return Html::rawElement(
00088                 'li',
00089                 array(),
00090                 Html::element(
00091                     'span',
00092                     array( 'class' => 'mw-invalidtitle' ),
00093                     Linker::getInvalidTitleDescription(
00094                         $this->getContext(),
00095                         $row->pt_namespace,
00096                         $row->pt_title
00097                     )
00098                 )
00099             ) . "\n";
00100         }
00101 
00102         $link = Linker::link( $title );
00103         $description_items = array();
00104         // Messages: restriction-level-sysop, restriction-level-autoconfirmed
00105         $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
00106         $description_items[] = $protType;
00107         $lang = $this->getLanguage();
00108         $expiry = strlen( $row->pt_expiry ) ?
00109             $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
00110             $infinity;
00111 
00112         if ( $expiry != $infinity ) {
00113             $user = $this->getUser();
00114             $description_items[] = $this->msg(
00115                 'protect-expiring-local',
00116                 $lang->userTimeAndDate( $expiry, $user ),
00117                 $lang->userDate( $expiry, $user ),
00118                 $lang->userTime( $expiry, $user )
00119             )->escaped();
00120         }
00121 
00122         wfProfileOut( __METHOD__ );
00123 
00124         // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
00125         return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
00126     }
00127 
00135     function showOptions( $namespace, $type = 'edit', $level ) {
00136         global $wgScript;
00137         $action = htmlspecialchars( $wgScript );
00138         $title = $this->getTitle();
00139         $special = htmlspecialchars( $title->getPrefixedDBkey() );
00140 
00141         return "<form action=\"$action\" method=\"get\">\n" .
00142             '<fieldset>' .
00143             Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
00144             Html::hidden( 'title', $special ) . "&#160;\n" .
00145             $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00146             $this->getLevelMenu( $level ) . "&#160;\n" .
00147             "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
00148             "</fieldset></form>";
00149     }
00150 
00158     function getNamespaceMenu( $namespace = null ) {
00159         return Html::namespaceSelector(
00160             array(
00161                 'selected' => $namespace,
00162                 'all' => '',
00163                 'label' => $this->msg( 'namespace' )->text()
00164             ), array(
00165                 'name' => 'namespace',
00166                 'id' => 'namespace',
00167                 'class' => 'namespaceselector',
00168             )
00169         );
00170     }
00171 
00177     function getLevelMenu( $pr_level ) {
00178         global $wgRestrictionLevels;
00179 
00180         // Temporary array
00181         $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
00182         $options = array();
00183 
00184         // First pass to load the log names
00185         foreach ( $wgRestrictionLevels as $type ) {
00186             if ( $type != '' && $type != '*' ) {
00187                 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
00188                 $text = $this->msg( "restriction-level-$type" )->text();
00189                 $m[$text] = $type;
00190             }
00191         }
00192 
00193         // Is there only one level (aside from "all")?
00194         if ( count( $m ) <= 2 ) {
00195             return '';
00196         }
00197         // Third pass generates sorted XHTML content
00198         foreach ( $m as $text => $type ) {
00199             $selected = ( $type == $pr_level );
00200             $options[] = Xml::option( $text, $type, $selected );
00201         }
00202 
00203         return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
00204             Xml::tags( 'select',
00205                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00206                 implode( "\n", $options ) );
00207     }
00208 
00209     protected function getGroupName() {
00210         return 'maintenance';
00211     }
00212 }
00213 
00218 class ProtectedTitlesPager extends AlphabeticPager {
00219     public $mForm, $mConds;
00220 
00221     function __construct( $form, $conds = array(), $type, $level, $namespace,
00222         $sizetype = '', $size = 0
00223     ) {
00224         $this->mForm = $form;
00225         $this->mConds = $conds;
00226         $this->level = $level;
00227         $this->namespace = $namespace;
00228         $this->size = intval( $size );
00229         parent::__construct( $form->getContext() );
00230     }
00231 
00232     function getStartBody() {
00233         wfProfileIn( __METHOD__ );
00234         # Do a link batch query
00235         $this->mResult->seek( 0 );
00236         $lb = new LinkBatch;
00237 
00238         foreach ( $this->mResult as $row ) {
00239             $lb->add( $row->pt_namespace, $row->pt_title );
00240         }
00241 
00242         $lb->execute();
00243         wfProfileOut( __METHOD__ );
00244 
00245         return '';
00246     }
00247 
00251     function getTitle() {
00252         return $this->mForm->getTitle();
00253     }
00254 
00255     function formatRow( $row ) {
00256         return $this->mForm->formatRow( $row );
00257     }
00258 
00262     function getQueryInfo() {
00263         $conds = $this->mConds;
00264         $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00265         if ( $this->level ) {
00266             $conds['pt_create_perm'] = $this->level;
00267         }
00268 
00269         if ( !is_null( $this->namespace ) ) {
00270             $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00271         }
00272 
00273         return array(
00274             'tables' => 'protected_titles',
00275             'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
00276                 'pt_expiry', 'pt_timestamp' ),
00277             'conds' => $conds
00278         );
00279     }
00280 
00281     function getIndexField() {
00282         return 'pt_timestamp';
00283     }
00284 }