Skip to content
Snippets Groups Projects
Commit a3f6fae6 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Add action plugin hooks back into the ActionRouter

This is not how integration of plugins would ideally be done in this new
system. Ideally an action plugin would actually implement an instance of
AbstractAction and would just fall into the normal flow of actions here.

However to not break a gazillion of existing plugins, this is just add
the existing two events into the new system through the use of a Plugin
action.

Maybe we could add "new" action plugins later.
parent ab583a1b
No related branches found
No related tags found
No related merge requests found
<?php
namespace dokuwiki\Action;
/**
* Class Plugin
*
* Used to run action plugins
*
* @package dokuwiki\Action
*/
class Plugin extends AbstractAction {
/** @inheritdoc */
function minimumPermission() {
return AUTH_NONE;
}
/**
* Outputs nothing but a warning unless an action plugin overwrites it
*
* @inheritdoc
* @triggers TPL_ACT_UNKNOWN
*/
public function tplContent() {
$evt = new \Doku_Event('TPL_ACT_UNKNOWN', $this->actionname);
if($evt->advise_before()) {
msg('Failed to handle action: ' . hsc($this->actionname), -1);
}
$evt->advise_after();
}
/**
* Set the action name
*
* This class handles arbitrary names by passing them to action plugins
* later in tplContent(). The actual name (=$ACT) is via this function
* in ActionRouter::setupAction()
*
* @param string $actionname
*/
public function setActionName($actionname) {
$this->actionname = $actionname;
}
}
<?php
/**
* Created by IntelliJ IDEA.
* User: andi
* Date: 2/10/17
* Time: 3:18 PM
*/
namespace dokuwiki;
......@@ -13,7 +7,12 @@ use dokuwiki\Action\Exception\ActionDisabledException;
use dokuwiki\Action\Exception\ActionException;
use dokuwiki\Action\Exception\FatalException;
use dokuwiki\Action\Exception\NoActionException;
use dokuwiki\Action\Plugin;
/**
* Class ActionRouter
* @package dokuwiki
*/
class ActionRouter {
/** @var AbstractAction */
......@@ -24,8 +23,15 @@ class ActionRouter {
/**
* ActionRouter constructor. Singleton, thus protected!
*
* Sets up the correct action based on the $ACT global. Writes back
* the selected action to $ACT
*/
protected function __construct() {
global $ACT;
$ACT = act_clean($ACT);
$this->setupAction($ACT);
$ACT = $this->action->getActionName();
}
/**
......@@ -45,14 +51,15 @@ class ActionRouter {
* Setup the given action
*
* Instantiates the right class, runs permission checks and pre-processing and
* seta $action
* sets $action
*
* @param string $actionname
* @triggers ACTION_ACT_PREPROCESS
* @fixme implement redirect on action change with post
* @fixme add event handling
* @fixme add the action name back to $ACT for plugins relying on it
*/
protected function setupAction($actionname) {
$presetup = $actionname;
try {
$this->action = $this->loadAction($actionname);
$this->action->checkPermissions();
......@@ -61,25 +68,38 @@ class ActionRouter {
} catch(ActionException $e) {
// we should have gotten a new action
$newaction = $e->getNewAction();
$actionname = $e->getNewAction();
// no infinite recursion
if($newaction === $actionname) {
if($actionname == $presetup) {
// FIXME this doesn't catch larger circles
$this->handleFatalException(new FatalException('Infinite loop in actions', 500, $e));
}
// this one should trigger a user message
if(is_a($e, ActionDisabledException::class)) {
msg('Action disabled: ' . hsc($actionname), -1);
msg('Action disabled: ' . hsc($presetup), -1);
}
// do setup for new action
$this->setupAction($newaction);
$this->setupAction($actionname);
} catch(NoActionException $e) {
// FIXME here the unknown event needs to be run
$this->action = $this->loadAction('show');
// give plugins an opportunity to process the actionname
$evt = new \Doku_Event('ACTION_ACT_PREPROCESS', $actionname);
if($evt->advise_before()) {
if($actionname == $presetup) {
// no plugin changed the action, complain and switch to show
msg('Action unknown: ' . hsc($actionname), -1);
$actionname = 'show';
}
$this->setupAction($actionname);
} else {
// event said the action should be kept, assume action plugin will handle it later
$this->action = new Plugin();
$this->action->setActionName($actionname);
}
$evt->advise_after();
} catch(\Exception $e) {
$this->handleFatalException($e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment