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