Debian Codegraph @

includes/specials/SpecialUnlockdb.php

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