getConfig()->get( 'ReadOnlyFile' ) ) ) ) { throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' ); } if ( file_exists( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) { throw new ErrorPageError( 'lockdb', 'databaselocked' ); } } protected function getFormFields() { return [ 'Reason' => [ 'type' => 'textarea', 'rows' => 4, 'vertical-label' => true, 'label-message' => 'enterlockreason', ], 'Confirm' => [ 'type' => 'toggle', 'label-message' => 'lockconfirm', ], ]; } protected function alterForm( HTMLForm $form ) { $form->setWrapperLegend( false ) ->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() ) ->setSubmitTextMsg( 'lockbtn' ); } public function onSubmit( array $data ) { global $wgContLang; if ( !$data['Confirm'] ) { return Status::newFatal( 'locknoconfirm' ); } Wikimedia\suppressWarnings(); $fp = fopen( $this->getConfig()->get( 'ReadOnlyFile' ), 'w' ); Wikimedia\restoreWarnings(); if ( false === $fp ) { # 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... return Status::newFatal( 'lockfilenotwritable' ); } fwrite( $fp, $data['Reason'] ); $timestamp = wfTimestampNow(); fwrite( $fp, "\n

" . $this->msg( 'lockedbyandtime', $this->getUser()->getName(), $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) )->inContentLanguage()->text() . "

\n" ); fclose( $fp ); return Status::newGood(); } public function onSuccess() { $out = $this->getOutput(); $out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) ); $out->addWikiMsg( 'lockdbsuccesstext' ); } protected function getDisplayFormat() { return 'ooui'; } protected function getGroupName() { return 'wiki'; } }