Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialUnlockdb
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 10
182
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doesWrites
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 requiresWrite
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 checkExecutePermissions
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getFormFields
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 alterForm
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 onSubmit
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 onSuccess
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getDisplayFormat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Implements Special:Unlockdb
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24namespace MediaWiki\Specials;
25
26use ErrorPageError;
27use MediaWiki\HTMLForm\HTMLForm;
28use MediaWiki\MainConfigNames;
29use MediaWiki\SpecialPage\FormSpecialPage;
30use MediaWiki\Status\Status;
31use MediaWiki\User\User;
32use Wikimedia\AtEase\AtEase;
33
34/**
35 * Implements Special:Unlockdb
36 *
37 * @ingroup SpecialPage
38 */
39class SpecialUnlockdb extends FormSpecialPage {
40
41    public function __construct() {
42        parent::__construct( 'Unlockdb', 'siteadmin' );
43    }
44
45    public function doesWrites() {
46        return false;
47    }
48
49    public function requiresWrite() {
50        return false;
51    }
52
53    public function checkExecutePermissions( User $user ) {
54        parent::checkExecutePermissions( $user );
55        # If the lock file isn't writable, we can do sweet bugger all
56        if ( !file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) {
57            throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
58        }
59    }
60
61    protected function getFormFields() {
62        return [
63            'Confirm' => [
64                'type' => 'toggle',
65                'label-message' => 'unlockconfirm',
66            ],
67        ];
68    }
69
70    protected function alterForm( HTMLForm $form ) {
71        $form->setWrapperLegend( false )
72            ->setHeaderHtml( $this->msg( 'unlockdbtext' )->parseAsBlock() )
73            ->setSubmitTextMsg( 'unlockbtn' );
74    }
75
76    public function onSubmit( array $data ) {
77        if ( !$data['Confirm'] ) {
78            return Status::newFatal( 'locknoconfirm' );
79        }
80
81        $readOnlyFile = $this->getConfig()->get( MainConfigNames::ReadOnlyFile );
82        AtEase::suppressWarnings();
83        $res = unlink( $readOnlyFile );
84        AtEase::restoreWarnings();
85
86        if ( $res ) {
87            return Status::newGood();
88        } else {
89            return Status::newFatal( 'filedeleteerror', $readOnlyFile );
90        }
91    }
92
93    public function onSuccess() {
94        $out = $this->getOutput();
95        $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
96        $out->addWikiMsg( 'unlockdbsuccesstext' );
97    }
98
99    protected function getDisplayFormat() {
100        return 'ooui';
101    }
102
103    protected function getGroupName() {
104        return 'wiki';
105    }
106}
107
108/**
109 * Retain the old class name for backwards compatibility.
110 * @deprecated since 1.41
111 */
112class_alias( SpecialUnlockdb::class, 'SpecialUnlockdb' );