MediaWiki master
SpecialLockdb.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
29use Wikimedia\AtEase\AtEase;
30
39
40 public function __construct() {
41 parent::__construct( 'Lockdb', 'siteadmin' );
42 }
43
44 public function doesWrites() {
45 return false;
46 }
47
48 public function requiresWrite() {
49 return false;
50 }
51
52 public function checkExecutePermissions( User $user ) {
53 parent::checkExecutePermissions( $user );
54 # If the lock file isn't writable, we can do sweet bugger all
55 if ( !is_writable( dirname( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) ) {
56 throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' );
57 }
58 if ( file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) {
59 throw new ErrorPageError( 'lockdb', 'databaselocked' );
60 }
61 }
62
63 protected function getFormFields() {
64 return [
65 'Reason' => [
66 'type' => 'textarea',
67 'rows' => 4,
68 'label-message' => 'enterlockreason',
69 ],
70 'Confirm' => [
71 'type' => 'toggle',
72 'label-message' => 'lockconfirm',
73 ],
74 ];
75 }
76
77 protected function alterForm( HTMLForm $form ) {
78 $form->setWrapperLegend( false )
79 ->setHeaderHtml( $this->msg( 'lockdbtext' )->parseAsBlock() )
80 ->setSubmitTextMsg( 'lockbtn' );
81 }
82
83 public function onSubmit( array $data ) {
84 if ( !$data['Confirm'] ) {
85 return Status::newFatal( 'locknoconfirm' );
86 }
87
88 AtEase::suppressWarnings();
89 $fp = fopen( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ), 'w' );
90 AtEase::restoreWarnings();
91
92 if ( $fp === false ) {
93 # This used to show a file not found error, but the likeliest reason for fopen()
94 # to fail at this point is insufficient permission to write to the file...good old
95 # is_writable() is plain wrong in some cases, it seems...
96 return Status::newFatal( 'lockfilenotwritable' );
97 }
98 fwrite( $fp, $data['Reason'] );
99 $timestamp = wfTimestampNow();
100 $contLang = $this->getContentLanguage();
101 fwrite( $fp, "\n<p>" . $this->msg( 'lockedbyandtime',
102 $this->getUser()->getName(),
103 $contLang->date( $timestamp, false, false ),
104 $contLang->time( $timestamp, false, false )
105 )->inContentLanguage()->text() . "</p>\n" );
106 fclose( $fp );
107
108 return Status::newGood();
109 }
110
111 public function onSuccess() {
112 $out = $this->getOutput();
113 $out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) );
114 $out->addWikiMsg( 'lockdbsuccesstext' );
115 }
116
117 protected function getDisplayFormat() {
118 return 'ooui';
119 }
120
121 protected function getGroupName() {
122 return 'wiki';
123 }
124}
125
127class_alias( SpecialLockdb::class, 'SpecialLockdb' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
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:209
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.
getUser()
Shortcut to get the User executing this instance.
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.
getContentLanguage()
Shortcut to get content language.
getName()
Get the canonical, unlocalized name of this special page without namespace.
A form to make the database read-only (eg for maintenance purposes).
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
getDisplayFormat()
Get display format for the form.
getFormFields()
Get an HTMLForm descriptor array.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
requiresWrite()
Whether this action requires the wiki not to be locked, default to requiresPost()
onSubmit(array $data)
Process the form on submission.
doesWrites()
Indicates whether POST requests to this special page require write access to the wiki.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
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