about summary refs log tree commit diff stats
path: root/wiki/inc/Action/AbstractAction.php
diff options
context:
space:
mode:
authorahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
committerahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
commit0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch)
treeb2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/inc/Action/AbstractAction.php
parentf57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff)
downloadsite-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/inc/Action/AbstractAction.php')
-rw-r--r--wiki/inc/Action/AbstractAction.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/wiki/inc/Action/AbstractAction.php b/wiki/inc/Action/AbstractAction.php
new file mode 100644
index 0000000..ea86238
--- /dev/null
+++ b/wiki/inc/Action/AbstractAction.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace dokuwiki\Action;
+
+use dokuwiki\Action\Exception\ActionDisabledException;
+use dokuwiki\Action\Exception\ActionException;
+use dokuwiki\Action\Exception\FatalException;
+
+/**
+ * Class AbstractAction
+ *
+ * Base class for all actions
+ *
+ * @package dokuwiki\Action
+ */
+abstract class AbstractAction {
+
+    /** @var string holds the name of the action (lowercase class name, no namespace) */
+    protected $actionname;
+
+    /**
+     * AbstractAction constructor.
+     *
+     * @param string $actionname the name of this action (see getActionName() for caveats)
+     */
+    public function __construct($actionname = '') {
+        if($actionname !== '') {
+            $this->actionname = $actionname;
+        } else {
+            // http://stackoverflow.com/a/27457689/172068
+            $this->actionname = strtolower(substr(strrchr(get_class($this), '\\'), 1));
+        }
+    }
+
+    /**
+     * Return the minimum permission needed
+     *
+     * This needs to return one of the AUTH_* constants. It will be checked against
+     * the current user and page after checkPermissions() ran through. If it fails,
+     * the user will be shown the Denied action.
+     *
+     * @return int
+     */
+    abstract public function minimumPermission();
+
+    /**
+     * Check conditions are met to run this action
+     *
+     * @throws ActionException
+     * @return void
+     */
+    public function checkPreconditions() {
+    }
+
+    /**
+     * Process data
+     *
+     * This runs before any output is sent to the browser.
+     *
+     * Throw an Exception if a different action should be run after this step.
+     *
+     * @throws ActionException
+     * @return void
+     */
+    public function preProcess() {
+    }
+
+    /**
+     * Output whatever content is wanted within tpl_content();
+     *
+     * @fixme we may want to return a Ui class here
+     */
+    public function tplContent() {
+        throw new FatalException('No content for Action ' . $this->actionname);
+    }
+
+    /**
+     * Returns the name of this action
+     *
+     * This is usually the lowercased class name, but may differ for some actions.
+     * eg. the export_ modes or for the Plugin action.
+     *
+     * @return string
+     */
+    public function getActionName() {
+        return $this->actionname;
+    }
+}