MediaWiki
REL1_19
|
00001 <?php 00029 class SpecialLockdb extends FormSpecialPage { 00030 var $reason = ''; 00031 00032 public function __construct() { 00033 parent::__construct( 'Lockdb', 'siteadmin' ); 00034 } 00035 00036 public function requiresWrite() { 00037 return false; 00038 } 00039 00040 public function checkExecutePermissions( User $user ) { 00041 global $wgReadOnlyFile; 00042 00043 parent::checkExecutePermissions( $user ); 00044 # If the lock file isn't writable, we can do sweet bugger all 00045 if ( !is_writable( dirname( $wgReadOnlyFile ) ) ) { 00046 throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' ); 00047 } 00048 } 00049 00050 protected function getFormFields() { 00051 return array( 00052 'Reason' => array( 00053 'type' => 'textarea', 00054 'rows' => 4, 00055 'vertical-label' => true, 00056 'label-message' => 'enterlockreason', 00057 ), 00058 'Confirm' => array( 00059 'type' => 'toggle', 00060 'label-message' => 'lockconfirm', 00061 ), 00062 ); 00063 } 00064 00065 protected function alterForm( HTMLForm $form ) { 00066 $form->setWrapperLegend( false ); 00067 $form->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() ); 00068 $form->setSubmitTextMsg( 'lockbtn' ); 00069 } 00070 00071 public function onSubmit( array $data ) { 00072 global $wgContLang, $wgReadOnlyFile; 00073 00074 if ( !$data['Confirm'] ) { 00075 return Status::newFatal( 'locknoconfirm' ); 00076 } 00077 00078 wfSuppressWarnings(); 00079 $fp = fopen( $wgReadOnlyFile, 'w' ); 00080 wfRestoreWarnings(); 00081 00082 if ( false === $fp ) { 00083 # This used to show a file not found error, but the likeliest reason for fopen() 00084 # to fail at this point is insufficient permission to write to the file...good old 00085 # is_writable() is plain wrong in some cases, it seems... 00086 return Status::newFatal( 'lockfilenotwritable' ); 00087 } 00088 fwrite( $fp, $data['Reason'] ); 00089 $timestamp = wfTimestampNow(); 00090 fwrite( $fp, "\n<p>" . wfMsgExt( 00091 'lockedbyandtime', 00092 array( 'content', 'parsemag' ), 00093 $this->getUser()->getName(), 00094 $wgContLang->date( $timestamp ), 00095 $wgContLang->time( $timestamp ) 00096 ) . "</p>\n" ); 00097 fclose( $fp ); 00098 00099 return Status::newGood(); 00100 } 00101 00102 public function onSuccess() { 00103 $out = $this->getOutput(); 00104 $out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) ); 00105 $out->addWikiMsg( 'lockdbsuccesstext' ); 00106 } 00107 }