MediaWiki  REL1_24
SpecialUnlockdb.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialUnlockdb extends FormSpecialPage {
00030 
00031     public function __construct() {
00032         parent::__construct( 'Unlockdb', 'siteadmin' );
00033     }
00034 
00035     public function requiresWrite() {
00036         return false;
00037     }
00038 
00039     public function checkExecutePermissions( User $user ) {
00040         parent::checkExecutePermissions( $user );
00041         # If the lock file isn't writable, we can do sweet bugger all
00042         if ( !file_exists( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) {
00043             throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
00044         }
00045     }
00046 
00047     protected function getFormFields() {
00048         return array(
00049             'Confirm' => array(
00050                 'type' => 'toggle',
00051                 'label-message' => 'unlockconfirm',
00052             ),
00053         );
00054     }
00055 
00056     protected function alterForm( HTMLForm $form ) {
00057         $form->setWrapperLegend( false );
00058         $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() );
00059         $form->setSubmitTextMsg( 'unlockbtn' );
00060     }
00061 
00062     public function onSubmit( array $data ) {
00063         if ( !$data['Confirm'] ) {
00064             return Status::newFatal( 'locknoconfirm' );
00065         }
00066 
00067         $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
00068         wfSuppressWarnings();
00069         $res = unlink( $readOnlyFile );
00070         wfRestoreWarnings();
00071 
00072         if ( $res ) {
00073             return Status::newGood();
00074         } else {
00075             return Status::newFatal( 'filedeleteerror', $readOnlyFile );
00076         }
00077     }
00078 
00079     public function onSuccess() {
00080         $out = $this->getOutput();
00081         $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
00082         $out->addWikiMsg( 'unlockdbsuccesstext' );
00083     }
00084 
00085     protected function getGroupName() {
00086         return 'wiki';
00087     }
00088 }