]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
FormAction extends ManagedAction
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 18 May 2014 11:31:31 +0000 (13:31 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 18 May 2014 11:31:51 +0000 (13:31 +0200)
handlePost is now more naturally called and doesn't require a separate
'handle' function for each subclass.

lib/action.php
lib/formaction.php
lib/managedaction.php

index 5ed943761c7752197a14e93005029018cbc48671..402e73c19d8b83959609bc1c8d66884bc7ae1a32 100644 (file)
@@ -58,7 +58,8 @@ class Action extends HTMLOutputter // lawsuit
     protected $ajax   = false;
     protected $menus  = true;
     protected $needLogin = false;
-    protected $needPost = false;
+    protected $needPost = false;    // implies canPost if true
+    protected $canPost = false;     // can this action handle POST method?
 
     // The currently scoped profile (normally Profile::current; from $this->auth_user for API)
     protected $scoped = null;
@@ -143,6 +144,11 @@ class Action extends HTMLOutputter // lawsuit
             $this->clientError(_('This method requires a POST.'), 405);
         }
 
+        // needPost, of course, overrides canPost if true
+        if (!$this->canPost) {
+            $this->canPost = $this->needPost;
+        }
+
         $this->args = common_copy_args($args);
 
         // This could be set with get_called_action and then
index a3e5498aad2e59f38678857cb6e4419c86d5c70e..60d9b3ce130a843ab458fbd3f995ae21d7704ac2 100644 (file)
@@ -41,11 +41,12 @@ if (!defined('STATUSNET')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  * @link     http://status.net/
  */
-class FormAction extends Action
+class FormAction extends ManagedAction
 {
     protected $form = null;
     protected $type = null;
     protected $needLogin = true;
+    protected $canPost = true;
 
     protected function prepare(array $args=array()) {
         parent::prepare($args);
@@ -63,22 +64,6 @@ class FormAction extends Action
         return true;
     }
 
-    protected function handle()
-    {
-        parent::handle();
-
-        if ($this->isPost()) {
-            try {
-                $msg = $this->handlePost();
-                $this->showForm($msg, true);
-            } catch (Exception $e) {
-                $this->showForm($e->getMessage());
-            }
-        } else {
-            $this->showForm();
-        }
-    }
-
     public function isReadOnly($args) {
         return !$this->isPost();
     }
@@ -113,22 +98,14 @@ class FormAction extends Action
         return null;
     }
 
-    public function showForm($msg=null, $success=false)
-    {
-        if ($success) {
-            $this->msg = $msg;
-        } else {
-            $this->error = $msg;
-        }
-        $this->showPage();
-    }
-
     /**
      * Gets called from handle() if isPost() is true;
      * @return void
      */
     protected function handlePost()
     {
+        parent::handlePost();
+
         // check for this before token since all POST and FILES data
         // is losts when size is exceeded
         if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
index 580d8c09e3c72e3abb6b73affd82178544534711..318df320e1cf6c19cf4e12ece68782aaea80682a 100644 (file)
@@ -39,6 +39,14 @@ class ManagedAction extends Action
     {
         parent::handle();
 
+        if ($this->canPost && $this->isPost()) {
+            try {
+                $this->msg = $this->handlePost();
+            } catch (Exception $e) {
+                $this->error = $e->getMessage();
+            }
+        }
+
         if (StatusNet::isAjax()) {
             $this->showAjax();
         } else {
@@ -46,6 +54,11 @@ class ManagedAction extends Action
         }
     }
 
+    protected function handlePost()
+    {
+        // This will only be run if the Action has the property canPost==true
+    }
+
     public function showAjax()
     {
         $this->startHTML('text/xml;charset=utf-8');