Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| SpecialUnlockdb | |
0.00% |
0 / 27 |
|
0.00% |
0 / 10 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| requiresWrite | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| checkExecutePermissions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getFormFields | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| alterForm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| onSubmit | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| onSuccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getDisplayFormat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\Exception\ErrorPageError; |
| 10 | use MediaWiki\HTMLForm\HTMLForm; |
| 11 | use MediaWiki\MainConfigNames; |
| 12 | use MediaWiki\SpecialPage\FormSpecialPage; |
| 13 | use MediaWiki\Status\Status; |
| 14 | use MediaWiki\User\User; |
| 15 | |
| 16 | /** |
| 17 | * Implements Special:Unlockdb |
| 18 | * |
| 19 | * @see SpecialLockDb |
| 20 | * @ingroup SpecialPage |
| 21 | */ |
| 22 | class SpecialUnlockdb extends FormSpecialPage { |
| 23 | |
| 24 | public function __construct() { |
| 25 | parent::__construct( 'Unlockdb', 'siteadmin' ); |
| 26 | } |
| 27 | |
| 28 | /** @inheritDoc */ |
| 29 | public function doesWrites() { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | /** @inheritDoc */ |
| 34 | public function requiresWrite() { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | public function checkExecutePermissions( User $user ) { |
| 39 | parent::checkExecutePermissions( $user ); |
| 40 | # If the lock file isn't writable, we can do sweet bugger all |
| 41 | if ( !file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) { |
| 42 | throw new ErrorPageError( 'lockdb', 'databasenotlocked' ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** @inheritDoc */ |
| 47 | protected function getFormFields() { |
| 48 | return [ |
| 49 | 'Confirm' => [ |
| 50 | 'type' => 'toggle', |
| 51 | 'label-message' => 'unlockconfirm', |
| 52 | ], |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | protected function alterForm( HTMLForm $form ) { |
| 57 | $form->setWrapperLegend( false ) |
| 58 | ->setHeaderHtml( $this->msg( 'unlockdbtext' )->parseAsBlock() ) |
| 59 | ->setSubmitTextMsg( 'unlockbtn' ); |
| 60 | } |
| 61 | |
| 62 | /** @inheritDoc */ |
| 63 | public function onSubmit( array $data ) { |
| 64 | if ( !$data['Confirm'] ) { |
| 65 | return Status::newFatal( 'locknoconfirm' ); |
| 66 | } |
| 67 | |
| 68 | $readOnlyFile = $this->getConfig()->get( MainConfigNames::ReadOnlyFile ); |
| 69 | // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged |
| 70 | $res = @unlink( $readOnlyFile ); |
| 71 | |
| 72 | if ( $res ) { |
| 73 | return Status::newGood(); |
| 74 | } else { |
| 75 | return Status::newFatal( 'filedeleteerror', $readOnlyFile ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public function onSuccess() { |
| 80 | $out = $this->getOutput(); |
| 81 | $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) ); |
| 82 | $out->addWikiMsg( 'unlockdbsuccesstext' ); |
| 83 | } |
| 84 | |
| 85 | /** @inheritDoc */ |
| 86 | protected function getDisplayFormat() { |
| 87 | return 'ooui'; |
| 88 | } |
| 89 | |
| 90 | /** @inheritDoc */ |
| 91 | protected function getGroupName() { |
| 92 | return 'wiki'; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Retain the old class name for backwards compatibility. |
| 98 | * @deprecated since 1.41 |
| 99 | */ |
| 100 | class_alias( SpecialUnlockdb::class, 'SpecialUnlockdb' ); |