MediaWiki  REL1_24
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         $action = htmlspecialchars( wfScript() );
00137         $title = $this->getPageTitle();
00138         $special = htmlspecialchars( $title->getPrefixedDBkey() );
00139 
00140         return "<form action=\"$action\" method=\"get\">\n" .
00141             '<fieldset>' .
00142             Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
00143             Html::hidden( 'title', $special ) . "&#160;\n" .
00144             $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
00145             $this->getLevelMenu( $level ) . "&#160;\n" .
00146             "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
00147             "</fieldset></form>";
00148     }
00149 
00157     function getNamespaceMenu( $namespace = null ) {
00158         return Html::namespaceSelector(
00159             array(
00160                 'selected' => $namespace,
00161                 'all' => '',
00162                 'label' => $this->msg( 'namespace' )->text()
00163             ), array(
00164                 'name' => 'namespace',
00165                 'id' => 'namespace',
00166                 'class' => 'namespaceselector',
00167             )
00168         );
00169     }
00170 
00176     function getLevelMenu( $pr_level ) {
00177         // Temporary array
00178         $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
00179         $options = array();
00180 
00181         // First pass to load the log names
00182         foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
00183             if ( $type != '' && $type != '*' ) {
00184                 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
00185                 $text = $this->msg( "restriction-level-$type" )->text();
00186                 $m[$text] = $type;
00187             }
00188         }
00189 
00190         // Is there only one level (aside from "all")?
00191         if ( count( $m ) <= 2 ) {
00192             return '';
00193         }
00194         // Third pass generates sorted XHTML content
00195         foreach ( $m as $text => $type ) {
00196             $selected = ( $type == $pr_level );
00197             $options[] = Xml::option( $text, $type, $selected );
00198         }
00199 
00200         return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
00201             Xml::tags( 'select',
00202                 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00203                 implode( "\n", $options ) );
00204     }
00205 
00206     protected function getGroupName() {
00207         return 'maintenance';
00208     }
00209 }
00210 
00215 class ProtectedTitlesPager extends AlphabeticPager {
00216     public $mForm, $mConds;
00217 
00218     function __construct( $form, $conds = array(), $type, $level, $namespace,
00219         $sizetype = '', $size = 0
00220     ) {
00221         $this->mForm = $form;
00222         $this->mConds = $conds;
00223         $this->level = $level;
00224         $this->namespace = $namespace;
00225         $this->size = intval( $size );
00226         parent::__construct( $form->getContext() );
00227     }
00228 
00229     function getStartBody() {
00230         wfProfileIn( __METHOD__ );
00231         # Do a link batch query
00232         $this->mResult->seek( 0 );
00233         $lb = new LinkBatch;
00234 
00235         foreach ( $this->mResult as $row ) {
00236             $lb->add( $row->pt_namespace, $row->pt_title );
00237         }
00238 
00239         $lb->execute();
00240         wfProfileOut( __METHOD__ );
00241 
00242         return '';
00243     }
00244 
00248     function getTitle() {
00249         return $this->mForm->getTitle();
00250     }
00251 
00252     function formatRow( $row ) {
00253         return $this->mForm->formatRow( $row );
00254     }
00255 
00259     function getQueryInfo() {
00260         $conds = $this->mConds;
00261         $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00262         if ( $this->level ) {
00263             $conds['pt_create_perm'] = $this->level;
00264         }
00265 
00266         if ( !is_null( $this->namespace ) ) {
00267             $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00268         }
00269 
00270         return array(
00271             'tables' => 'protected_titles',
00272             'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
00273                 'pt_expiry', 'pt_timestamp' ),
00274             'conds' => $conds
00275         );
00276     }
00277 
00278     function getIndexField() {
00279         return 'pt_timestamp';
00280     }
00281 }