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 9*ab583a1bSAndreas Gohr/** 10*ab583a1bSAndreas Gohr * Class AbstractAction 11*ab583a1bSAndreas Gohr * 12*ab583a1bSAndreas Gohr * Base class for all actions 13*ab583a1bSAndreas Gohr * 14*ab583a1bSAndreas Gohr * @package dokuwiki\Action 15*ab583a1bSAndreas 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. 2364ab5140SAndreas Gohr */ 2464ab5140SAndreas Gohr public function __construct() { 2564ab5140SAndreas Gohr // http://stackoverflow.com/a/27457689/172068 2664ab5140SAndreas Gohr $this->actionname = strtolower(substr(strrchr(get_class($this), '\\'), 1)); 2764ab5140SAndreas Gohr } 2864ab5140SAndreas Gohr 2964ab5140SAndreas Gohr /** 3064ab5140SAndreas Gohr * Return the minimum permission needed 3164ab5140SAndreas Gohr * 3264ab5140SAndreas Gohr * This needs to return one of the AUTH_* constants. It will be checked against 3364ab5140SAndreas Gohr * the current user and page after checkPermissions() ran through. If it fails, 3464ab5140SAndreas Gohr * the user will be shown the Denied action. 3564ab5140SAndreas Gohr * 3664ab5140SAndreas Gohr * @return int 3764ab5140SAndreas Gohr */ 3864ab5140SAndreas Gohr abstract function minimumPermission(); 3964ab5140SAndreas Gohr 4064ab5140SAndreas Gohr /** 4164ab5140SAndreas Gohr * Check permissions are correct to run this action 4264ab5140SAndreas Gohr * 4364ab5140SAndreas Gohr * @throws ActionException 4464ab5140SAndreas Gohr * @return void 4564ab5140SAndreas Gohr */ 4664ab5140SAndreas Gohr public function checkPermissions() { 4764ab5140SAndreas Gohr if(!actionOK($this->actionname)) throw new ActionDisabledException(); 4864ab5140SAndreas Gohr } 4964ab5140SAndreas Gohr 5064ab5140SAndreas Gohr /** 5164ab5140SAndreas Gohr * Process data 5264ab5140SAndreas Gohr * 5364ab5140SAndreas Gohr * This runs before any output is sent to the browser. 5464ab5140SAndreas Gohr * 5564ab5140SAndreas Gohr * Throw an Exception if a different action should be run after this step. 5664ab5140SAndreas Gohr * 5764ab5140SAndreas Gohr * @throws ActionException 5864ab5140SAndreas Gohr * @return void 5964ab5140SAndreas Gohr */ 6064ab5140SAndreas Gohr public function preProcess() { 6164ab5140SAndreas Gohr } 6264ab5140SAndreas Gohr 6364ab5140SAndreas Gohr /** 6464ab5140SAndreas Gohr * Output whatever content is wanted within tpl_content(); 65f21dad39SAndreas Gohr * 66f21dad39SAndreas Gohr * @fixme we may want to return a Ui class here 6764ab5140SAndreas Gohr */ 6864ab5140SAndreas Gohr public function tplContent() { 69f21dad39SAndreas Gohr throw new FatalException('No content for Action ' . $this->actionname); 70f21dad39SAndreas Gohr } 71f21dad39SAndreas Gohr 72f21dad39SAndreas Gohr /** 73f21dad39SAndreas Gohr * @return string 74f21dad39SAndreas Gohr */ 75f21dad39SAndreas Gohr public function getActionName() { 76f21dad39SAndreas Gohr return $this->actionname; 7764ab5140SAndreas Gohr } 7864ab5140SAndreas Gohr} 79