1<?php 2 3namespace dokuwiki\Action; 4 5use dokuwiki\Action\Exception\ActionException; 6use dokuwiki\Action\Exception\FatalException; 7 8/** 9 * Class AbstractAction 10 * 11 * Base class for all actions 12 * 13 * @package dokuwiki\Action 14 */ 15abstract class AbstractAction 16{ 17 /** @var string holds the name of the action (lowercase class name, no namespace) */ 18 protected $actionname; 19 20 /** 21 * AbstractAction constructor. 22 * 23 * @param string $actionname the name of this action (see getActionName() for caveats) 24 */ 25 public function __construct($actionname = '') 26 { 27 if ($actionname !== '') { 28 $this->actionname = $actionname; 29 } else { 30 // As of PHP 8 this seems to be the fastest way to get the name: 31 $n = explode('\\', get_class($this)); 32 $this->actionname = array_pop($n); 33 } 34 } 35 36 /** 37 * Return the minimum permission needed 38 * 39 * This needs to return one of the AUTH_* constants. It will be checked against 40 * the current user and page after checkPermissions() ran through. If it fails, 41 * the user will be shown the Denied action. 42 * 43 * @return int 44 */ 45 abstract public function minimumPermission(); 46 47 /** 48 * Check conditions are met to run this action 49 * 50 * @throws ActionException 51 * @return void 52 */ 53 public function checkPreconditions() 54 { 55 } 56 57 /** 58 * Process data 59 * 60 * This runs before any output is sent to the browser. 61 * 62 * Throw an Exception if a different action should be run after this step. 63 * 64 * @throws ActionException 65 * @return void 66 */ 67 public function preProcess() 68 { 69 } 70 71 /** 72 * Output whatever content is wanted within tpl_content(); 73 * 74 * @fixme we may want to return a Ui class here 75 * @throws FatalException 76 */ 77 public function tplContent() 78 { 79 throw new FatalException('No content for Action ' . $this->actionname); 80 } 81 82 /** 83 * Returns the name of this action 84 * 85 * This is usually the lowercased class name, but may differ for some actions. 86 * eg. the export_ modes or for the Plugin action. 87 * 88 * @return string 89 */ 90 public function getActionName() 91 { 92 return $this->actionname; 93 } 94} 95