WatchAction: Clean up redundant getFormFields() and show()
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 29 Sep 2015 01:45:34 +0000 (18:45 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 29 Sep 2015 01:46:45 +0000 (18:46 -0700)
* 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
includes/actions/PurgeAction.php
includes/actions/WatchAction.php

index 9decf90..aa201d7 100644 (file)
@@ -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
         */
index ed0bff7..e5da172 100644 (file)
@@ -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();
        }
index 51108c0..30b83d7 100644 (file)
@@ -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() ) {