From 63f4c24a0e28972284b35159430ed3466a71f63f Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 1 Jan 2013 12:32:34 +0100 Subject: [PATCH] Reconstruct missing id in IO_WIKIPAGE_READ and PARSER_CACHE_USE events When p_cached_instructions() is called without the $id parameter the id is also missing in the IO_WIKIPAGE_READ and PARSER_CACHE_USE events. However in both events the file path is supplied and using pathID() the path can be used for getting the id. --- action.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/action.php b/action.php index 9aab30a..2071697 100644 --- a/action.php +++ b/action.php @@ -29,13 +29,23 @@ public function register($controller) { * @param mixed $param Optional parameters (not used) */ function handle_read(Doku_Event $event, $param) { - global $ACT; + global $ACT, $conf; static $stack = array(); // handle only reads of the current revision if ($event->data[3]) return; $id = $event->data[2]; if ($event->data[1]) $id = $event->data[1].':'.$id; + + if (!$id) { + // try to reconstruct the id from the filename + $path = $event->data[0][0]; + if (strpos($path, $conf['datadir']) === 0) { + $path = substr($path, strlen($conf['datadir'])+1); + $id = pathID($path); + } + } + if (isset($stack[$id])) return; // Don't change the page when the user is currently changing the page content or the page is locked by another user @@ -57,9 +67,18 @@ function handle_read(Doku_Event $event, $param) { * @param mixed $param Optional parameters (not used) */ function handle_cache(Doku_Event $event, $param) { + global $conf; /** @var $cache cache_parser */ $cache = $event->data; $id = $cache->page; + if (!$id) { + // try to reconstruct the id from the filename + $path = $cache->file; + if (strpos($path, $conf['datadir']) === 0) { + $path = substr($path, strlen($conf['datadir'])+1); + $id = pathID($path); + } + } if ($id) { $meta = p_get_metadata($id, 'plugin_pagemove', METADATA_DONT_RENDER); if ($meta && isset($meta['moves'])) {