164ab5140SAndreas Gohr<?php 264ab5140SAndreas Gohr 364ab5140SAndreas Gohrnamespace dokuwiki\Action; 464ab5140SAndreas Gohr 564ab5140SAndreas Gohruse dokuwiki\Action\Exception\ActionDisabledException; 664ab5140SAndreas Gohruse dokuwiki\Action\Exception\ActionException; 7f21dad39SAndreas Gohruse dokuwiki\Action\Exception\FatalException; 864ab5140SAndreas Gohr 9ab583a1bSAndreas Gohr/** 10ab583a1bSAndreas Gohr * Class AbstractAction 11ab583a1bSAndreas Gohr * 12ab583a1bSAndreas Gohr * Base class for all actions 13ab583a1bSAndreas Gohr * 14ab583a1bSAndreas Gohr * @package dokuwiki\Action 15ab583a1bSAndreas Gohr */ 1664ab5140SAndreas Gohrabstract class AbstractAction { 1764ab5140SAndreas Gohr 1864ab5140SAndreas Gohr /** @var string holds the name of the action (lowercase class name, no namespace) */ 1964ab5140SAndreas Gohr protected $actionname; 2064ab5140SAndreas Gohr 2164ab5140SAndreas Gohr /** 2264ab5140SAndreas Gohr * AbstractAction constructor. 23*73522543SAndreas Gohr * 24*73522543SAndreas Gohr * @param string $actionname the name of this action (see getActioName() for caveats) 2564ab5140SAndreas Gohr */ 26*73522543SAndreas Gohr public function __construct($actionname) { 27*73522543SAndreas Gohr $this->actionname = $actionname; 2864ab5140SAndreas Gohr } 2964ab5140SAndreas Gohr 3064ab5140SAndreas Gohr /** 3164ab5140SAndreas Gohr * Return the minimum permission needed 3264ab5140SAndreas Gohr * 3364ab5140SAndreas Gohr * This needs to return one of the AUTH_* constants. It will be checked against 3464ab5140SAndreas Gohr * the current user and page after checkPermissions() ran through. If it fails, 3564ab5140SAndreas Gohr * the user will be shown the Denied action. 3664ab5140SAndreas Gohr * 3764ab5140SAndreas Gohr * @return int 3864ab5140SAndreas Gohr */ 3964ab5140SAndreas Gohr abstract function minimumPermission(); 4064ab5140SAndreas Gohr 4164ab5140SAndreas Gohr /** 4264ab5140SAndreas Gohr * Check permissions are correct to run this action 4364ab5140SAndreas Gohr * 4464ab5140SAndreas Gohr * @throws ActionException 4564ab5140SAndreas Gohr * @return void 4664ab5140SAndreas Gohr */ 4764ab5140SAndreas Gohr public function checkPermissions() { 4864ab5140SAndreas Gohr if(!actionOK($this->actionname)) throw new ActionDisabledException(); 4964ab5140SAndreas Gohr } 5064ab5140SAndreas Gohr 5164ab5140SAndreas Gohr /** 5264ab5140SAndreas Gohr * Process data 5364ab5140SAndreas Gohr * 5464ab5140SAndreas Gohr * This runs before any output is sent to the browser. 5564ab5140SAndreas Gohr * 5664ab5140SAndreas Gohr * Throw an Exception if a different action should be run after this step. 5764ab5140SAndreas Gohr * 5864ab5140SAndreas Gohr * @throws ActionException 5964ab5140SAndreas Gohr * @return void 6064ab5140SAndreas Gohr */ 6164ab5140SAndreas Gohr public function preProcess() { 6264ab5140SAndreas Gohr } 6364ab5140SAndreas Gohr 6464ab5140SAndreas Gohr /** 6564ab5140SAndreas Gohr * Output whatever content is wanted within tpl_content(); 66f21dad39SAndreas Gohr * 67f21dad39SAndreas Gohr * @fixme we may want to return a Ui class here 6864ab5140SAndreas Gohr */ 6964ab5140SAndreas Gohr public function tplContent() { 70f21dad39SAndreas Gohr throw new FatalException('No content for Action ' . $this->actionname); 71f21dad39SAndreas Gohr } 72f21dad39SAndreas Gohr 73f21dad39SAndreas Gohr /** 74*73522543SAndreas Gohr * Returns the name of this action 75*73522543SAndreas Gohr * 76*73522543SAndreas Gohr * This is usually the lowercased class name, but may differ for some actions. 77*73522543SAndreas Gohr * eg. the export_ modes or for the Plugin action. 78*73522543SAndreas Gohr * 79f21dad39SAndreas Gohr * @return string 80f21dad39SAndreas Gohr */ 81f21dad39SAndreas Gohr public function getActionName() { 82f21dad39SAndreas Gohr return $this->actionname; 8364ab5140SAndreas Gohr } 8464ab5140SAndreas Gohr} 85