MediaWiki  REL1_22
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         global $wgReadOnlyFile;
00041 
00042         parent::checkExecutePermissions( $user );
00043         # If the lock file isn't writable, we can do sweet bugger all
00044         if ( !file_exists( $wgReadOnlyFile ) ) {
00045             throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
00046         }
00047     }
00048 
00049     protected function getFormFields() {
00050         return array(
00051             'Confirm' => array(
00052                 'type' => 'toggle',
00053                 'label-message' => 'unlockconfirm',
00054             ),
00055         );
00056     }
00057 
00058     protected function alterForm( HTMLForm $form ) {
00059         $form->setWrapperLegend( false );
00060         $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() );
00061         $form->setSubmitTextMsg( 'unlockbtn' );
00062     }
00063 
00064     public function onSubmit( array $data ) {
00065         global $wgReadOnlyFile;
00066 
00067         if ( !$data['Confirm'] ) {
00068             return Status::newFatal( 'locknoconfirm' );
00069         }
00070 
00071         wfSuppressWarnings();
00072         $res = unlink( $wgReadOnlyFile );
00073         wfRestoreWarnings();
00074 
00075         if ( $res ) {
00076             return Status::newGood();
00077         } else {
00078             return Status::newFatal( 'filedeleteerror', $wgReadOnlyFile );
00079         }
00080     }
00081 
00082     public function onSuccess() {
00083         $out = $this->getOutput();
00084         $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
00085         $out->addWikiMsg( 'unlockdbsuccesstext' );
00086     }
00087 
00088     protected function getGroupName() {
00089         return 'wiki';
00090     }
00091 }