setHeaders(); # Permission check if( !$this->userCanExecute( $wgUser ) ) { $this->displayRestrictionError(); return; } $this->outputHeader(); # If the lock file isn't writable, we can do sweet bugger all global $wgReadOnlyFile; if( !is_writable( dirname( $wgReadOnlyFile ) ) ) { self::notWritable(); return; } $action = $wgRequest->getVal( 'action' ); $this->reason = $wgRequest->getVal( 'wpLockReason', '' ); if ( $action == 'success' ) { $this->showSuccess(); } elseif ( $action == 'submit' && $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { $this->doSubmit(); } else { $this->showForm(); } } private function showForm( $err = '' ) { global $wgOut, $wgUser; $wgOut->addWikiMsg( 'lockdbtext' ); if ( $err != '' ) { $wgOut->setSubtitle( wfMsg( 'formerror' ) ); $wgOut->addHTML( '

' . htmlspecialchars( $err ) . "

\n" ); } $wgOut->addHTML( Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST', 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" . wfMsgHtml( 'enterlockreason' ) . ":\n" . Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). " " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . " " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . " " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . wfMsgHtml( 'lockconfirm' ) . " " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . " " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
 
\n" . Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" . Html::closeElement( 'form' ) ); } private function doSubmit() { global $wgOut, $wgUser, $wgContLang, $wgRequest; global $wgReadOnlyFile; if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) { $this->showForm( wfMsg( 'locknoconfirm' ) ); return; } wfSuppressWarnings(); $fp = fopen( $wgReadOnlyFile, 'w' ); wfRestoreWarnings(); 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... self::notWritable(); return; } fwrite( $fp, $this->reason ); $timestamp = wfTimestampNow(); fwrite( $fp, "\n

" . wfMsgExt( 'lockedbyandtime', array( 'content', 'parsemag' ), $wgUser->getName(), $wgContLang->date( $timestamp ), $wgContLang->time( $timestamp ) ) . "

\n" ); fclose( $fp ); $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); } private function showSuccess() { global $wgOut; $wgOut->setPagetitle( wfMsg( 'lockdb' ) ); $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) ); $wgOut->addWikiMsg( 'lockdbsuccesstext' ); } public static function notWritable() { global $wgOut; $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' ); } }