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