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.
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.
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
21 namespace MediaWiki\Specials
;
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
;
32 * A form to make the database read-only (eg for maintenance purposes).
34 * See also @ref $wgReadOnlyFile.
36 * @ingroup SpecialPage
38 class SpecialLockdb
extends FormSpecialPage
{
40 public function __construct() {
41 parent
::__construct( 'Lockdb', 'siteadmin' );
44 public function doesWrites() {
48 public function requiresWrite() {
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' );
58 if ( file_exists( $this->getConfig()->get( MainConfigNames
::ReadOnlyFile
) ) ) {
59 throw new ErrorPageError( 'lockdb', 'databaselocked' );
63 protected function getFormFields() {
68 'label-message' => 'enterlockreason',
72 'label-message' => 'lockconfirm',
77 protected function alterForm( HTMLForm
$form ) {
78 $form->setWrapperLegend( false )
79 ->setHeaderHtml( $this->msg( 'lockdbtext' )->parseAsBlock() )
80 ->setSubmitTextMsg( 'lockbtn' );
83 public function onSubmit( array $data ) {
84 if ( !$data['Confirm'] ) {
85 return Status
::newFatal( 'locknoconfirm' );
88 AtEase
::suppressWarnings();
89 $fp = fopen( $this->getConfig()->get( MainConfigNames
::ReadOnlyFile
), 'w' );
90 AtEase
::restoreWarnings();
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' );
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" );
108 return Status
::newGood();
111 public function onSuccess() {
112 $out = $this->getOutput();
113 $out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) );
114 $out->addWikiMsg( 'lockdbsuccesstext' );
117 protected function getDisplayFormat() {
121 protected function getGroupName() {
126 /** @deprecated class alias since 1.41 */
127 class_alias( SpecialLockdb
::class, 'SpecialLockdb' );