MediaWiki master
SpecialUnlockdb.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
29use Wikimedia\AtEase\AtEase;
30
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
110class_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