| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use ErrorPageError; |
| 24 |
use MediaWiki\HTMLForm\HTMLForm; |
| 25 |
use MediaWiki\MainConfigNames; |
| 26 |
use MediaWiki\SpecialPage\FormSpecialPage; |
| 27 |
use MediaWiki\Status\Status; |
| 28 |
use MediaWiki\User\User; |
| 29 |
use Wikimedia\AtEase\AtEase; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class SpecialUnlockdb extends FormSpecialPage { |
| 38 |
|
| 39 |
public function __construct() { |
| 40 |
parent::__construct( 'Unlockdb', 'siteadmin' ); |
| 41 |
} |
| 42 |
|
| 43 |
public function doesWrites() { |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
public function requiresWrite() { |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
public function checkExecutePermissions( User $user ) { |
| 52 |
parent::checkExecutePermissions( $user ); |
| 53 |
|
| 54 |
if ( !file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) { |
| 55 |
throw new ErrorPageError( 'lockdb', 'databasenotlocked' ); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
protected function getFormFields() { |
| 60 |
return [ |
| 61 |
'Confirm' => [ |
| 62 |
'type' => 'toggle', |
| 63 |
'label-message' => 'unlockconfirm', |
| 64 |
], |
| 65 |
]; |
| 66 |
} |
| 67 |
|
| 68 |
protected function alterForm( HTMLForm $form ) { |
| 69 |
$form->setWrapperLegend( false ) |
| 70 |
->setHeaderHtml( $this->msg( 'unlockdbtext' )->parseAsBlock() ) |
| 71 |
->setSubmitTextMsg( 'unlockbtn' ); |
| 72 |
} |
| 73 |
|
| 74 |
public function onSubmit( array $data ) { |
| 75 |
if ( !$data['Confirm'] ) { |
| 76 |
return Status::newFatal( 'locknoconfirm' ); |
| 77 |
} |
| 78 |
|
| 79 |
$readOnlyFile = $this->getConfig()->get( MainConfigNames::ReadOnlyFile ); |
| 80 |
AtEase::suppressWarnings(); |
| 81 |
$res = unlink( $readOnlyFile ); |
| 82 |
AtEase::restoreWarnings(); |
| 83 |
|
| 84 |
if ( $res ) { |
| 85 |
return Status::newGood(); |
| 86 |
} else { |
| 87 |
return Status::newFatal( 'filedeleteerror', $readOnlyFile ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
public function onSuccess() { |
| 92 |
$out = $this->getOutput(); |
| 93 |
$out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) ); |
| 94 |
$out->addWikiMsg( 'unlockdbsuccesstext' ); |
| 95 |
} |
| 96 |
|
| 97 |
protected function getDisplayFormat() { |
| 98 |
return 'ooui'; |
| 99 |
} |
| 100 |
|
| 101 |
protected function getGroupName() { |
| 102 |
return 'wiki'; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
class_alias( SpecialUnlockdb::class, 'SpecialUnlockdb' ); |