]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialUnlockdb.php
MediaWiki 1.30.2 renames
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialUnlockdb.php
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
24 /**
25  * Implements Special:Unlockdb
26  *
27  * @ingroup SpecialPage
28  */
29 class SpecialUnlockdb extends FormSpecialPage {
30
31         public function __construct() {
32                 parent::__construct( 'Unlockdb', 'siteadmin' );
33         }
34
35         public function doesWrites() {
36                 return false;
37         }
38
39         public function requiresWrite() {
40                 return false;
41         }
42
43         public function checkExecutePermissions( User $user ) {
44                 parent::checkExecutePermissions( $user );
45                 # If the lock file isn't writable, we can do sweet bugger all
46                 if ( !file_exists( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) {
47                         throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
48                 }
49         }
50
51         protected function getFormFields() {
52                 return [
53                         'Confirm' => [
54                                 'type' => 'toggle',
55                                 'label-message' => 'unlockconfirm',
56                         ],
57                 ];
58         }
59
60         protected function alterForm( HTMLForm $form ) {
61                 $form->setWrapperLegend( false )
62                         ->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() )
63                         ->setSubmitTextMsg( 'unlockbtn' );
64         }
65
66         public function onSubmit( array $data ) {
67                 if ( !$data['Confirm'] ) {
68                         return Status::newFatal( 'locknoconfirm' );
69                 }
70
71                 $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
72                 MediaWiki\suppressWarnings();
73                 $res = unlink( $readOnlyFile );
74                 MediaWiki\restoreWarnings();
75
76                 if ( $res ) {
77                         return Status::newGood();
78                 } else {
79                         return Status::newFatal( 'filedeleteerror', $readOnlyFile );
80                 }
81         }
82
83         public function onSuccess() {
84                 $out = $this->getOutput();
85                 $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
86                 $out->addWikiMsg( 'unlockdbsuccesstext' );
87         }
88
89         protected function getDisplayFormat() {
90                 return 'ooui';
91         }
92
93         protected function getGroupName() {
94                 return 'wiki';
95         }
96 }