xref: /dokuwiki/inc/Action/AbstractAction.php (revision 64ab5140f7b1c996873fbfe9bab26d9202fbb773)
1*64ab5140SAndreas Gohr<?php
2*64ab5140SAndreas Gohr
3*64ab5140SAndreas Gohrnamespace dokuwiki\Action;
4*64ab5140SAndreas Gohr
5*64ab5140SAndreas Gohruse dokuwiki\Action\Exception\ActionDisabledException;
6*64ab5140SAndreas Gohruse dokuwiki\Action\Exception\ActionException;
7*64ab5140SAndreas Gohr
8*64ab5140SAndreas Gohrabstract class AbstractAction {
9*64ab5140SAndreas Gohr
10*64ab5140SAndreas Gohr    /** @var string holds the name of the action (lowercase class name, no namespace) */
11*64ab5140SAndreas Gohr    protected $actionname;
12*64ab5140SAndreas Gohr
13*64ab5140SAndreas Gohr    /**
14*64ab5140SAndreas Gohr     * AbstractAction constructor.
15*64ab5140SAndreas Gohr     */
16*64ab5140SAndreas Gohr    public function __construct() {
17*64ab5140SAndreas Gohr        // http://stackoverflow.com/a/27457689/172068
18*64ab5140SAndreas Gohr        $this->actionname = strtolower(substr(strrchr(get_class($this), '\\'), 1));
19*64ab5140SAndreas Gohr    }
20*64ab5140SAndreas Gohr
21*64ab5140SAndreas Gohr    /**
22*64ab5140SAndreas Gohr     * Return the minimum permission needed
23*64ab5140SAndreas Gohr     *
24*64ab5140SAndreas Gohr     * This needs to return one of the AUTH_* constants. It will be checked against
25*64ab5140SAndreas Gohr     * the current user and page after checkPermissions() ran through. If it fails,
26*64ab5140SAndreas Gohr     * the user will be shown the Denied action.
27*64ab5140SAndreas Gohr     *
28*64ab5140SAndreas Gohr     * @return int
29*64ab5140SAndreas Gohr     */
30*64ab5140SAndreas Gohr    abstract function minimumPermission();
31*64ab5140SAndreas Gohr
32*64ab5140SAndreas Gohr    /**
33*64ab5140SAndreas Gohr     * Check permissions are correct to run this action
34*64ab5140SAndreas Gohr     *
35*64ab5140SAndreas Gohr     * @throws ActionException
36*64ab5140SAndreas Gohr     * @return void
37*64ab5140SAndreas Gohr     */
38*64ab5140SAndreas Gohr    public function checkPermissions() {
39*64ab5140SAndreas Gohr        if(!actionOK($this->actionname)) throw new ActionDisabledException();
40*64ab5140SAndreas Gohr    }
41*64ab5140SAndreas Gohr
42*64ab5140SAndreas Gohr    /**
43*64ab5140SAndreas Gohr     * Process data
44*64ab5140SAndreas Gohr     *
45*64ab5140SAndreas Gohr     * This runs before any output is sent to the browser.
46*64ab5140SAndreas Gohr     *
47*64ab5140SAndreas Gohr     * Throw an Exception if a different action should be run after this step.
48*64ab5140SAndreas Gohr     *
49*64ab5140SAndreas Gohr     * @throws ActionException
50*64ab5140SAndreas Gohr     * @return void
51*64ab5140SAndreas Gohr     */
52*64ab5140SAndreas Gohr    public function preProcess() {
53*64ab5140SAndreas Gohr    }
54*64ab5140SAndreas Gohr
55*64ab5140SAndreas Gohr    /**
56*64ab5140SAndreas Gohr     * Output whatever content is wanted within tpl_content();
57*64ab5140SAndreas Gohr     */
58*64ab5140SAndreas Gohr    public function tplContent() {
59*64ab5140SAndreas Gohr        echo 'No content for this action';
60*64ab5140SAndreas Gohr    }
61*64ab5140SAndreas Gohr}
62