From 27a8bad9b0b430876e713d27c38a51cb651195c2 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 28 Sep 2015 18:45:34 -0700 Subject: [PATCH] WatchAction: Clean up redundant getFormFields() and show() * Make FormAction::getFormFields not abstract. In most cases this will just be an empty array. This is in prep for RollbackAction as well. * Remove redundant show() in WatchAction. This used to do custom stuff, but after 77cdf1919 it does exactly the same as the parent FormAction::show. * Don't add 'redirectparams' hidden field if there were no custom query parameters (e.g. plain index.php?title=..&action=..) Change-Id: Ia7f9bb0367c49a23179e9fefa9f529fa8aef8f52 --- includes/actions/FormAction.php | 16 +++++++++++----- includes/actions/PurgeAction.php | 8 -------- includes/actions/WatchAction.php | 24 ------------------------ 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/includes/actions/FormAction.php b/includes/actions/FormAction.php index 9decf9068d..aa201d7be1 100644 --- a/includes/actions/FormAction.php +++ b/includes/actions/FormAction.php @@ -31,7 +31,10 @@ abstract class FormAction extends Action { * Get an HTMLForm descriptor array * @return array */ - abstract protected function getFormFields(); + protected function getFormFields() { + // Default to an empty form with just a submit button + return array(); + } /** * Add pre- or post-text to the form @@ -75,7 +78,9 @@ abstract class FormAction extends Action { $this->getRequest()->getQueryValues(), array( 'action' => null, 'title' => null ) ); - $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); + if ( $params ) { + $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); + } $form->addPreText( $this->preText() ); $form->addPostText( $this->postText() ); @@ -88,9 +93,10 @@ abstract class FormAction extends Action { } /** - * Process the form on POST submission. If you return false from getFormFields(), - * this will obviously never be reached. If you don't want to do anything with the - * form, just return false here + * Process the form on POST submission. + * + * If you don't want to do anything with the form, just return false here. + * * @param array $data * @return bool|array True for success, false for didn't-try, array of errors on failure */ diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php index ed0bff7b97..e5da172393 100644 --- a/includes/actions/PurgeAction.php +++ b/includes/actions/PurgeAction.php @@ -44,14 +44,6 @@ class PurgeAction extends FormAction { return ''; } - /** - * Just get an empty form with a single submit button - * @return array - */ - protected function getFormFields() { - return array(); - } - public function onSubmit( $data ) { return $this->page->doPurge(); } diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index 51108c07a8..30b83d70f4 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -42,36 +42,12 @@ class WatchAction extends FormAction { return $this->msg( 'addwatch' )->escaped(); } - /** - * Just get an empty form with a single submit button - * @return array - */ - protected function getFormFields() { - return array(); - } - public function onSubmit( $data ) { self::doWatch( $this->getTitle(), $this->getUser() ); return true; } - /** - * This can be either formed or formless depending on the session token given - */ - public function show() { - $this->setHeaders(); - - $user = $this->getUser(); - // This will throw exceptions if there's a problem - $this->checkCanExecute( $user ); - - $form = $this->getForm(); - if ( $form->show() ) { - $this->onSuccess(); - } - } - protected function checkCanExecute( User $user ) { // Must be logged in if ( $user->isAnon() ) { -- 2.20.1