MediaWiki master
SpecialUnlockdb.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
32use Wikimedia\AtEase\AtEase;
33
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
112class_alias( SpecialUnlockdb::class, 'SpecialUnlockdb' );
An error page which can definitely be safely rendered using the OutputPage.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
setWrapperLegend( $legend)
Prompt the whole form to be wrapped in a "<fieldset>", with this text as its "<legend>" element.
A class containing constants representing the names of configuration variables.
const ReadOnlyFile
Name constant for the ReadOnlyFile setting, for use with Config::get()
Special page which uses an HTMLForm to handle processing.
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
Implements Special:Unlockdb.
getDisplayFormat()
Get display format for the form.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
requiresWrite()
Whether this action requires the wiki not to be locked, default to requiresPost()
doesWrites()
Indicates whether this special page may perform database writes.
onSubmit(array $data)
Process the form on submission.
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
getFormFields()
Get an HTMLForm descriptor array.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
internal since 1.36
Definition User.php:93
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...