Merge "filebackend: deprecate FileBackend::getWikiId()"
[lhc/web/wiklou.git] / includes / specials / SpecialLockdb.php
index a229fa3..c7c45b5 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A form to make the database readonly (eg for maintenance purposes).
  *
@@ -34,7 +36,7 @@ class SpecialLockdb extends FormSpecialPage {
        }
 
        public function doesWrites() {
-               return true;
+               return false;
        }
 
        public function requiresWrite() {
@@ -47,6 +49,9 @@ class SpecialLockdb extends FormSpecialPage {
                if ( !is_writable( dirname( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) ) {
                        throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' );
                }
+               if ( file_exists( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) {
+                       throw new ErrorPageError( 'lockdb', 'databaselocked' );
+               }
        }
 
        protected function getFormFields() {
@@ -65,23 +70,21 @@ class SpecialLockdb extends FormSpecialPage {
        }
 
        protected function alterForm( HTMLForm $form ) {
-               $form->setWrapperLegend( false );
-               $form->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() );
-               $form->setSubmitTextMsg( 'lockbtn' );
+               $form->setWrapperLegend( false )
+                       ->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() )
+                       ->setSubmitTextMsg( 'lockbtn' );
        }
 
        public function onSubmit( array $data ) {
-               global $wgContLang;
-
                if ( !$data['Confirm'] ) {
                        return Status::newFatal( 'locknoconfirm' );
                }
 
-               MediaWiki\suppressWarnings();
+               Wikimedia\suppressWarnings();
                $fp = fopen( $this->getConfig()->get( 'ReadOnlyFile' ), 'w' );
-               MediaWiki\restoreWarnings();
+               Wikimedia\restoreWarnings();
 
-               if ( false === $fp ) {
+               if ( $fp === false ) {
                        # This used to show a file not found error, but the likeliest reason for fopen()
                        # to fail at this point is insufficient permission to write to the file...good old
                        # is_writable() is plain wrong in some cases, it seems...
@@ -89,10 +92,11 @@ class SpecialLockdb extends FormSpecialPage {
                }
                fwrite( $fp, $data['Reason'] );
                $timestamp = wfTimestampNow();
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
                fwrite( $fp, "\n<p>" . $this->msg( 'lockedbyandtime',
                        $this->getUser()->getName(),
-                       $wgContLang->date( $timestamp, false, false ),
-                       $wgContLang->time( $timestamp, false, false )
+                       $contLang->date( $timestamp, false, false ),
+                       $contLang->time( $timestamp, false, false )
                )->inContentLanguage()->text() . "</p>\n" );
                fclose( $fp );
 
@@ -105,6 +109,10 @@ class SpecialLockdb extends FormSpecialPage {
                $out->addWikiMsg( 'lockdbsuccesstext' );
        }
 
+       protected function getDisplayFormat() {
+               return 'ooui';
+       }
+
        protected function getGroupName() {
                return 'wiki';
        }