MediaWiki  REL1_22
SpecialLockdb.php
Go to the documentation of this file.
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>" . $this->msg( 'lockedbyandtime',
00091             $this->getUser()->getName(),
00092             $wgContLang->date( $timestamp, false, false ),
00093             $wgContLang->time( $timestamp, false, false )
00094         )->inContentLanguage()->text() . "</p>\n" );
00095         fclose( $fp );
00096 
00097         return Status::newGood();
00098     }
00099 
00100     public function onSuccess() {
00101         $out = $this->getOutput();
00102         $out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) );
00103         $out->addWikiMsg( 'lockdbsuccesstext' );
00104     }
00105 
00106     protected function getGroupName() {
00107         return 'wiki';
00108     }
00109 }