From 81f9e22b2e291e7d7b0156600c1f0dd4591fd4f8 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Thu, 18 May 2017 11:41:25 +0200
Subject: [PATCH] allow actions to throw exception that are shown to the user

---
 inc/Action/Exception/ActionException.php | 15 +++++++++++++++
 inc/ActionRouter.php                     |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/inc/Action/Exception/ActionException.php b/inc/Action/Exception/ActionException.php
index e9a480cc5..386364c59 100644
--- a/inc/Action/Exception/ActionException.php
+++ b/inc/Action/Exception/ActionException.php
@@ -15,8 +15,12 @@ namespace dokuwiki\Action\Exception;
  */
 class ActionException extends \Exception {
 
+    /** @var string the new action */
     protected $newaction;
 
+    /** @var bool should the exception's message be shown to the user? */
+    protected $displayToUser = false;
+
     /**
      * ActionException constructor.
      *
@@ -36,4 +40,15 @@ class ActionException extends \Exception {
     public function getNewAction() {
         return $this->newaction;
     }
+
+    /**
+     * Should this Exception's message be shown to the user?
+     *
+     * @param null|bool $set when null is given, the current setting is not changed
+     * @return bool
+     */
+    public function displayToUser($set = null) {
+        if(!is_null($set)) $this->displayToUser = $set;
+        return $set;
+    }
 }
diff --git a/inc/ActionRouter.php b/inc/ActionRouter.php
index 0abc0dc24..1e8f65bab 100644
--- a/inc/ActionRouter.php
+++ b/inc/ActionRouter.php
@@ -88,6 +88,11 @@ class ActionRouter {
                 msg('Action disabled: ' . hsc($presetup), -1);
             }
 
+            // some actions may request the display of a message
+            if($e->displayToUser()) {
+                msg(hsc($e->getMessage()), -1);
+            }
+
             // do setup for new action
             $this->transitionAction($presetup, $actionname);
 
-- 
GitLab