From: Alexandre Emsenhuber Date: Tue, 25 Oct 2011 18:20:44 +0000 (+0000) Subject: Port Special:Lockdb and Special:Unlockdb to HTMLForm using FormSpecialPage X-Git-Tag: 1.31.0-rc.0~26916 X-Git-Url: http://git.cyclocoop.org//%22%22._DIR_PLUGIN_FULLCALENDAR.%22prive/themes/spip/images/event_edit.png/%22?a=commitdiff_plain;h=574e8bf3f956c939c8215341ff0ade06af7adcd8;p=lhc%2Fweb%2Fwiklou.git Port Special:Lockdb and Special:Unlockdb to HTMLForm using FormSpecialPage --- diff --git a/includes/specials/SpecialLockdb.php b/includes/specials/SpecialLockdb.php index 85421c3d93..9dec018e34 100644 --- a/includes/specials/SpecialLockdb.php +++ b/includes/specials/SpecialLockdb.php @@ -26,88 +26,53 @@ * * @ingroup SpecialPage */ -class SpecialLockdb extends SpecialPage { +class SpecialLockdb extends FormSpecialPage { var $reason = ''; public function __construct() { parent::__construct( 'Lockdb', 'siteadmin' ); } - public function execute( $par ) { - $this->setHeaders(); - - # Permission check - if( !$this->userCanExecute( $this->getUser() ) ) { - $this->displayRestrictionError(); - return; - } + public function requiresWrite() { + return false; + } - $this->outputHeader(); + public function userCanExecute( User $user ) { + parent::userCanExecute( $user ); # If the lock file isn't writable, we can do sweet bugger all global $wgReadOnlyFile; - if( !is_writable( dirname( $wgReadOnlyFile ) ) ) { - $this->getOutput()->addWikiMsg( 'lockfilenotwritable' ); - return; - } - - $request = $this->getRequest(); - $action = $request->getVal( 'action' ); - $this->reason = $request->getVal( 'wpLockReason', '' ); - - if ( $action == 'success' ) { - $this->showSuccess(); - } elseif ( $action == 'submit' && $request->wasPosted() && - $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) { - $this->doSubmit(); - } else { - $this->showForm(); + if ( !is_writable( dirname( $wgReadOnlyFile ) ) ) { + throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' ); } } - private function showForm( $err = '' ) { - $out = $this->getOutput(); - $out->addWikiMsg( 'lockdbtext' ); - - if ( $err != '' ) { - $out->setSubtitle( wfMsg( 'formerror' ) ); - $out->addHTML( '

' . htmlspecialchars( $err ) . "

\n" ); - } - - $out->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', array( 'id' => 'mw-input-wplockconfirm' ) ) . " - - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . - Html::openElement( 'label', array( 'for' => 'mw-input-wplockconfirm' ) ) . - wfMsgHtml( 'lockconfirm' ) . " - - - - - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . " - " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . " - - -
 
\n" . - Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" . - Html::closeElement( 'form' ) + protected function getFormFields() { + return array( + 'Reason' => array( + 'type' => 'textarea', + 'rows' => 4, + 'vertical-label' => true, + 'label-message' => 'enterlockreason', + ), + 'Confirm' => array( + 'type' => 'toggle', + 'label-message' => 'lockconfirm', + ), ); + } + protected function alterForm( HTMLForm $form ) { + $form->setWrapperLegend( false ); + $form->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() ); + $form->setSubmitTextMsg( 'lockbtn' ); } - private function doSubmit() { + public function onSubmit( array $data ) { global $wgContLang, $wgReadOnlyFile; - if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) { - $this->showForm( wfMsg( 'locknoconfirm' ) ); - return; + if ( !$data['Confirm'] ) { + return Status::newFatal( 'locknoconfirm' ); } wfSuppressWarnings(); @@ -118,10 +83,9 @@ class SpecialLockdb extends SpecialPage { # 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... - $this->getOutput()->addWikiMsg( 'lockfilenotwritable' ); - return; + return Status::newFatal( 'lockfilenotwritable' ); } - fwrite( $fp, $this->reason ); + fwrite( $fp, $data['Reason'] ); $timestamp = wfTimestampNow(); fwrite( $fp, "\n

" . wfMsgExt( 'lockedbyandtime', @@ -132,12 +96,11 @@ class SpecialLockdb extends SpecialPage { ) . "

\n" ); fclose( $fp ); - $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); + return Status::newGood(); } - private function showSuccess() { + public function onSuccess() { $out = $this->getOutput(); - $out->setPagetitle( wfMsg( 'lockdb' ) ); $out->setSubtitle( wfMsg( 'lockdbsuccesssub' ) ); $out->addWikiMsg( 'lockdbsuccesstext' ); } diff --git a/includes/specials/SpecialUnlockdb.php b/includes/specials/SpecialUnlockdb.php index 0443864e15..115e617287 100644 --- a/includes/specials/SpecialUnlockdb.php +++ b/includes/specials/SpecialUnlockdb.php @@ -26,85 +26,46 @@ * * @ingroup SpecialPage */ -class SpecialUnlockdb extends SpecialPage { +class SpecialUnlockdb extends FormSpecialPage { public function __construct() { parent::__construct( 'Unlockdb', 'siteadmin' ); } - public function execute( $par ) { - $this->setHeaders(); - - # Permission check - if( !$this->userCanExecute( $this->getUser() ) ) { - $this->displayRestrictionError(); - return; - } - - $this->outputHeader(); - - $request = $this->getRequest(); - $action = $request->getVal( 'action' ); - - if ( $action == 'success' ) { - $this->showSuccess(); - } elseif ( $action == 'submit' && $request->wasPosted() && - $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) { - $this->doSubmit(); - } else { - $this->showForm(); - } + public function requiresWrite() { + return false; } - private function showForm( $err = '' ) { - global $wgReadOnlyFile; - - $out = $this->getOutput(); - - if( !file_exists( $wgReadOnlyFile ) ) { - $out->addWikiMsg( 'databasenotlocked' ); - return; - } - - $out->addWikiMsg( 'unlockdbtext' ); + public function userCanExecute( User $user ) { + parent::userCanExecute( $user ); - if ( $err != '' ) { - $out->setSubtitle( wfMsg( 'formerror' ) ); - $out->addHTML( '

' . htmlspecialchars( $err ) . "

\n" ); + # If the lock file isn't writable, we can do sweet bugger all + global $wgReadOnlyFile; + if ( !file_exists( $wgReadOnlyFile ) ) { + throw new ErrorPageError( 'lockdb', 'databasenotlocked' ); } + } - $out->addHTML( - Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST', - 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . " - - - " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . " - " . Html::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wpunlockconfirm' ) ) . " - - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . - Html::openElement( 'label', array( 'for' => 'mw-input-wpunlockconfirm' ) ) . - wfMsgHtml( 'unlockconfirm' ) . " - - - - - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . " - " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . " - - -
 
\n" . - Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" . - Html::closeElement( 'form' ) + protected function getFormFields() { + return array( + 'Confirm' => array( + 'type' => 'toggle', + 'label-message' => 'unlockconfirm', + ), ); + } + protected function alterForm( HTMLForm $form ) { + $form->setWrapperLegend( false ); + $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() ); + $form->setSubmitTextMsg( 'unlockbtn' ); } - private function doSubmit() { + public function onSubmit( array $data ) { global $wgReadOnlyFile; - if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) { - $this->showForm( wfMsg( 'locknoconfirm' ) ); - return; + if ( !$data['Confirm'] ) { + return Status::newFatal( 'locknoconfirm' ); } wfSuppressWarnings(); @@ -112,13 +73,13 @@ class SpecialUnlockdb extends SpecialPage { wfRestoreWarnings(); if ( $res ) { - $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); + return Status::newGood(); } else { - $this->getOutput()->addWikiMsg( 'filedeleteerror', $wgReadOnlyFile ); + return Status::newFatal( 'filedeleteerror', $wgReadOnlyFile ); } } - private function showSuccess() { + public function onSuccess() { $out = $this->getOutput(); $out->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) ); $out->addWikiMsg( 'unlockdbsuccesstext' );