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