MediaWiki REL1_39
SpecialUnlockdb.php
Go to the documentation of this file.
1<?php
25use Wikimedia\AtEase\AtEase;
26
33
34 public function __construct() {
35 parent::__construct( 'Unlockdb', 'siteadmin' );
36 }
37
38 public function doesWrites() {
39 return false;
40 }
41
42 public function requiresWrite() {
43 return false;
44 }
45
46 public function checkExecutePermissions( User $user ) {
47 parent::checkExecutePermissions( $user );
48 # If the lock file isn't writable, we can do sweet bugger all
49 if ( !file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) {
50 throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
51 }
52 }
53
54 protected function getFormFields() {
55 return [
56 'Confirm' => [
57 'type' => 'toggle',
58 'label-message' => 'unlockconfirm',
59 ],
60 ];
61 }
62
63 protected function alterForm( HTMLForm $form ) {
64 $form->setWrapperLegend( false )
65 ->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() )
66 ->setSubmitTextMsg( 'unlockbtn' );
67 }
68
69 public function onSubmit( array $data ) {
70 if ( !$data['Confirm'] ) {
71 return Status::newFatal( 'locknoconfirm' );
72 }
73
74 $readOnlyFile = $this->getConfig()->get( MainConfigNames::ReadOnlyFile );
75 AtEase::suppressWarnings();
76 $res = unlink( $readOnlyFile );
77 AtEase::restoreWarnings();
78
79 if ( $res ) {
80 return Status::newGood();
81 } else {
82 return Status::newFatal( 'filedeleteerror', $readOnlyFile );
83 }
84 }
85
86 public function onSuccess() {
87 $out = $this->getOutput();
88 $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
89 $out->addWikiMsg( 'unlockdbsuccesstext' );
90 }
91
92 protected function getDisplayFormat() {
93 return 'ooui';
94 }
95
96 protected function getGroupName() {
97 return 'wiki';
98 }
99}
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:150
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.
getOutput()
Get the OutputPage being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
Implements Special:Unlockdb.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
doesWrites()
Indicates whether this special page may perform database writes.
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
requiresWrite()
Whether this action requires the wiki not to be locked.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
onSubmit(array $data)
Process the form on POST submission.
getFormFields()
Get an HTMLForm descriptor array.
getDisplayFormat()
Get display format for the form.
internal since 1.36
Definition User.php:70