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