00001 <?php
00011 class ProtectedTitlesForm {
00012
00013 protected $IdLevel = 'level';
00014 protected $IdType = 'type';
00015
00016 function showList( $msg = '' ) {
00017 global $wgOut, $wgRequest;
00018
00019 if ( "" != $msg ) {
00020 $wgOut->setSubtitle( $msg );
00021 }
00022
00023
00024 if ( !mt_rand( 0, 10 ) ) {
00025 Title::purgeExpiredRestrictions();
00026 }
00027
00028 $type = $wgRequest->getVal( $this->IdType );
00029 $level = $wgRequest->getVal( $this->IdLevel );
00030 $sizetype = $wgRequest->getVal( 'sizetype' );
00031 $size = $wgRequest->getIntOrNull( 'size' );
00032 $NS = $wgRequest->getIntOrNull( 'namespace' );
00033
00034 $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
00035
00036 $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
00037
00038 if ( $pager->getNumRows() ) {
00039 $s = $pager->getNavigationBar();
00040 $s .= "<ul>" .
00041 $pager->getBody() .
00042 "</ul>";
00043 $s .= $pager->getNavigationBar();
00044 } else {
00045 $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
00046 }
00047 $wgOut->addHTML( $s );
00048 }
00049
00053 function formatRow( $row ) {
00054 global $wgUser, $wgLang, $wgContLang;
00055
00056 wfProfileIn( __METHOD__ );
00057
00058 static $skin=null;
00059
00060 if( is_null( $skin ) )
00061 $skin = $wgUser->getSkin();
00062
00063 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
00064 $link = $skin->makeLinkObj( $title );
00065
00066 $description_items = array ();
00067
00068 $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
00069
00070 $description_items[] = $protType;
00071
00072 $expiry_description = ''; $stxt = '';
00073
00074 if ( $row->pt_expiry != 'infinity' && strlen($row->pt_expiry) ) {
00075 $expiry = Block::decodeExpiry( $row->pt_expiry );
00076
00077 $expiry_description = wfMsg( 'protect-expiring', $wgLang->timeanddate( $expiry ) , $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
00078
00079 $description_items[] = $expiry_description;
00080 }
00081
00082 wfProfileOut( __METHOD__ );
00083
00084 return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
00085 }
00086
00094 function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
00095 global $wgScript;
00096 $action = htmlspecialchars( $wgScript );
00097 $title = SpecialPage::getTitleFor( 'ProtectedTitles' );
00098 $special = htmlspecialchars( $title->getPrefixedDBkey() );
00099 return "<form action=\"$action\" method=\"get\">\n" .
00100 '<fieldset>' .
00101 Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
00102 Xml::hidden( 'title', $special ) . " \n" .
00103 $this->getNamespaceMenu( $namespace ) . " \n" .
00104 $this->getLevelMenu( $level ) . " \n" .
00105 " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
00106 "</fieldset></form>";
00107 }
00108
00116 function getNamespaceMenu( $namespace = null ) {
00117 return Xml::label( wfMsg( 'namespace' ), 'namespace' )
00118 . ' '
00119 . Xml::namespaceSelector( $namespace, '' );
00120 }
00121
00126 function getLevelMenu( $pr_level ) {
00127 global $wgRestrictionLevels;
00128
00129 $m = array( wfMsg('restriction-level-all') => 0 );
00130 $options = array();
00131
00132
00133 foreach( $wgRestrictionLevels as $type ) {
00134 if ( $type !='' && $type !='*') {
00135 $text = wfMsg("restriction-level-$type");
00136 $m[$text] = $type;
00137 }
00138 }
00139
00140 if( count($m) <= 2 ) {
00141 return '';
00142 }
00143
00144 foreach( $m as $text => $type ) {
00145 $selected = ($type == $pr_level );
00146 $options[] = Xml::option( $text, $type, $selected );
00147 }
00148
00149 return
00150 Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . ' ' .
00151 Xml::tags( 'select',
00152 array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
00153 implode( "\n", $options ) );
00154 }
00155 }
00156
00161 class ProtectedtitlesPager extends AlphabeticPager {
00162 public $mForm, $mConds;
00163
00164 function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
00165 $this->mForm = $form;
00166 $this->mConds = $conds;
00167 $this->level = $level;
00168 $this->namespace = $namespace;
00169 $this->size = intval($size);
00170 parent::__construct();
00171 }
00172
00173 function getStartBody() {
00174 wfProfileIn( __METHOD__ );
00175 # Do a link batch query
00176 $this->mResult->seek( 0 );
00177 $lb = new LinkBatch;
00178
00179 while ( $row = $this->mResult->fetchObject() ) {
00180 $lb->add( $row->pt_namespace, $row->pt_title );
00181 }
00182
00183 $lb->execute();
00184 wfProfileOut( __METHOD__ );
00185 return '';
00186 }
00187
00188 function formatRow( $row ) {
00189 return $this->mForm->formatRow( $row );
00190 }
00191
00192 function getQueryInfo() {
00193 $conds = $this->mConds;
00194 $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
00195 if( $this->level )
00196 $conds['pt_create_perm'] = $this->level;
00197 if( !is_null($this->namespace) )
00198 $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
00199 return array(
00200 'tables' => 'protected_titles',
00201 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
00202 'conds' => $conds
00203 );
00204 }
00205
00206 function getIndexField() {
00207 return 'pt_timestamp';
00208 }
00209 }
00210
00214 function wfSpecialProtectedtitles() {
00215
00216 $ppForm = new ProtectedTitlesForm();
00217
00218 $ppForm->showList();
00219 }