Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / specials / SpecialUnlockdb.php
blob8cd86ce645394407f3f2d75769737d7b7ee71f3b
1 <?php
2 /**
3 * Implements Special:Unlockdb
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Implements Special:Unlockdb
27 * @ingroup SpecialPage
29 class SpecialUnlockdb extends FormSpecialPage {
31 public function __construct() {
32 parent::__construct( 'Unlockdb', 'siteadmin' );
35 public function doesWrites() {
36 return false;
39 public function requiresWrite() {
40 return false;
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' );
51 protected function getFormFields() {
52 return [
53 'Confirm' => [
54 'type' => 'toggle',
55 'label-message' => 'unlockconfirm',
60 protected function alterForm( HTMLForm $form ) {
61 $form->setWrapperLegend( false )
62 ->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() )
63 ->setSubmitTextMsg( 'unlockbtn' );
66 public function onSubmit( array $data ) {
67 if ( !$data['Confirm'] ) {
68 return Status::newFatal( 'locknoconfirm' );
71 $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
72 MediaWiki\suppressWarnings();
73 $res = unlink( $readOnlyFile );
74 MediaWiki\restoreWarnings();
76 if ( $res ) {
77 return Status::newGood();
78 } else {
79 return Status::newFatal( 'filedeleteerror', $readOnlyFile );
83 public function onSuccess() {
84 $out = $this->getOutput();
85 $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
86 $out->addWikiMsg( 'unlockdbsuccesstext' );
89 protected function getDisplayFormat() {
90 return 'ooui';
93 protected function getGroupName() {
94 return 'wiki';