Skip to content

Commit

Permalink
Reconstruct missing id in IO_WIKIPAGE_READ and PARSER_CACHE_USE events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michitux committed Jan 1, 2013
1 parent 1666890 commit 63f4c24
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])) {
Expand Down

0 comments on commit 63f4c24

Please sign in to comment.