X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Factions%2FRollbackAction.php;h=e2fc265f96d95923cfbfa9544a54e23efb460292;hb=284778405b0e41c57b3085958401e07b6ca742e6;hp=3e6d4028a45196d2ab2ecd9b627d0c0342e86ce5;hpb=04e6f695837f03add4a41ce3d8e612ff807a82ff;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/actions/RollbackAction.php b/includes/actions/RollbackAction.php index 3e6d4028a4..e2fc265f96 100644 --- a/includes/actions/RollbackAction.php +++ b/includes/actions/RollbackAction.php @@ -25,7 +25,7 @@ * * @ingroup Actions */ -class RollbackAction extends FormlessAction { +class RollbackAction extends FormAction { public function getName() { return 'rollback'; @@ -35,21 +35,59 @@ class RollbackAction extends FormlessAction { return 'rollback'; } - /** - * Temporarily unused message keys due to T88044/T136375: - * - confirm-rollback-top - * - confirm-rollback-button - * - rollbackfailed - * - rollback-missingparam - * - rollback-success-notify - */ + protected function usesOOUI() { + return true; + } + + protected function getDescription() { + return ''; + } + + public function doesWrites() { + return true; + } + + public function onSuccess() { + return false; + } + + public function onSubmit( $data ) { + return false; + } + + protected function alterForm( HTMLForm $form ) { + $form->setWrapperLegendMsg( 'confirm-rollback-top' ); + $form->setSubmitTextMsg( 'confirm-rollback-button' ); + $form->setTokenSalt( 'rollback' ); + + $from = $this->getRequest()->getVal( 'from' ); + if ( $from === null ) { + throw new BadRequestError( 'rollbackfailed', 'rollback-missingparam' ); + } + foreach ( [ 'from', 'bot', 'hidediff', 'summary', 'token' ] as $param ) { + $val = $this->getRequest()->getVal( $param ); + if ( $val !== null ) { + $form->addHiddenField( $param, $val ); + } + } + } /** * @throws ErrorPageError + * @throws ReadOnlyError + * @throws ThrottledError */ - public function onView() { - // TODO: use $this->useTransactionalTimeLimit(); when POST only - wfTransactionalTimeLimit(); + public function show() { + if ( $this->getUser()->getOption( 'showrollbackconfirmation' ) == false || + $this->getRequest()->wasPosted() ) { + $this->handleRollbackRequest(); + } else { + $this->showRollbackConfirmationForm(); + } + } + + public function handleRollbackRequest() { + $this->enableTransactionalTimelimit(); $request = $this->getRequest(); $user = $this->getUser(); @@ -69,15 +107,6 @@ class RollbackAction extends FormlessAction { ] ); } - // @TODO: remove this hack once rollback uses POST (T88044) - $fname = __METHOD__; - $trxLimits = $this->context->getConfig()->get( 'TrxProfilerLimits' ); - $trxProfiler = Profiler::instance()->getTransactionProfiler(); - $trxProfiler->setExpectations( $trxLimits['POST'], $fname ); - DeferredUpdates::addCallableUpdate( function () use ( $trxProfiler, $trxLimits, $fname ) { - $trxProfiler->setExpectations( $trxLimits['PostSend-POST'], $fname ); - } ); - $data = null; $errors = $this->page->doRollback( $from, @@ -92,9 +121,7 @@ class RollbackAction extends FormlessAction { throw new ThrottledError; } - if ( isset( $errors[0][0] ) && - ( $errors[0][0] == 'alreadyrolled' || $errors[0][0] == 'cantrollback' ) - ) { + if ( $this->hasRollbackRelatedErrors( $errors ) ) { $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) ); $errArray = $errors[0]; $errMsg = array_shift( $errArray ); @@ -166,11 +193,51 @@ class RollbackAction extends FormlessAction { } } - protected function getDescription() { - return ''; + /** + * Enables transactional time limit for POST and GET requests to RollbackAction + * @throws ConfigException + */ + private function enableTransactionalTimelimit() { + // If Rollbacks are made POST-only, use $this->useTransactionalTimeLimit() + wfTransactionalTimeLimit(); + if ( !$this->getRequest()->wasPosted() ) { + /** + * We apply the higher POST limits on GET requests + * to prevent logstash.wikimedia.org from being spammed + */ + $fname = __METHOD__; + $trxLimits = $this->context->getConfig()->get( 'TrxProfilerLimits' ); + $trxProfiler = Profiler::instance()->getTransactionProfiler(); + $trxProfiler->redefineExpectations( $trxLimits['POST'], $fname ); + DeferredUpdates::addCallableUpdate( function () use ( $trxProfiler, $trxLimits, $fname + ) { + $trxProfiler->redefineExpectations( $trxLimits['PostSend-POST'], $fname ); + } ); + } } - public function doesWrites() { - return true; + private function showRollbackConfirmationForm() { + $form = $this->getForm(); + if ( $form->show() ) { + $this->onSuccess(); + } + } + + protected function getFormFields() { + return [ + 'intro' => [ + 'type' => 'info', + 'vertical-label' => true, + 'raw' => true, + 'default' => $this->msg( 'confirm-rollback-bottom' )->parse() + ] + ]; + } + + private function hasRollbackRelatedErrors( array $errors ) { + return isset( $errors[0][0] ) && + ( $errors[0][0] == 'alreadyrolled' || + $errors[0][0] == 'cantrollback' + ); } }