From fa5ce2caec7b02834d4b3e57e67faa17163df565 Mon Sep 17 00:00:00 2001 From: Michael Hamann <michael@content-space.de> Date: Tue, 29 Oct 2013 22:52:57 +0100 Subject: [PATCH] Use the new media usage index from DokuWiki core if available Note that you need to rebuild the search index after this change in order to get correct link updates after media moves, this should happen automatically for visited pages. The index that is created in the pagemove plugin is now identical to the one that is created in DokuWiki core from the Autumn 2013 release on so you won't need to manually rebuild the index after updating DokuWiki. --- action.php | 8 ++++++-- helper.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/action.php b/action.php index dcb4200..a889cfc 100644 --- a/action.php +++ b/action.php @@ -107,7 +107,9 @@ function handle_cache(Doku_Event $event, $param) { * @param array $param Optional parameters (unused) */ public function handle_index_version(Doku_Event $event, $param) { - $event->data['plugin_pagemove'] = 0.1; + // From indexer version 6 on the media references are indexed by DokuWiki itself + if ($event->data['dokuwiki'] < 6) + $event->data['plugin_pagemove'] = 0.2; } /** @@ -117,6 +119,8 @@ public function handle_index_version(Doku_Event $event, $param) { * @param array $param Optional parameters (unused) */ public function index_media_use(Doku_Event $event, $param) { + // From indexer version 6 on the media references are indexed by DokuWiki itself + if (INDEXER_VERSION >= 6) return; $id = $event->data['page']; $media_references = array(); $instructions = p_cached_instructions(wikiFn($id), false, $id); @@ -124,7 +128,7 @@ public function index_media_use(Doku_Event $event, $param) { $this->get_media_references_from_instructions($instructions, $media_references, $id); } $media_references = array_unique($media_references); - $event->data['metadata']['pagemove_media'] = $media_references; + $event->data['metadata']['relation_media'] = $media_references; } /** diff --git a/helper.php b/helper.php index 5ddda97..13d96ee 100644 --- a/helper.php +++ b/helper.php @@ -517,7 +517,7 @@ public function move_media(&$opts, $checkonly = false) { * End of init (checks) */ - $affected_pages = idx_get_indexer()->lookupKey('pagemove_media', $opts['id']); + $affected_pages = idx_get_indexer()->lookupKey('relation_media', $opts['id']); $data = array('opts' => &$opts, 'affected_pages' => &$affected_pages); // give plugins the option to add their own meta files to the list of files that need to be moved @@ -531,7 +531,7 @@ public function move_media(&$opts, $checkonly = false) { } else { $Indexer = new helper_plugin_pagemove_indexer(); // copy of the new code } - if (($idx_msg = $Indexer->renameMetaValue('pagemove_media', $opts['id'], $opts['new_id'])) !== true) { + if (($idx_msg = $Indexer->renameMetaValue('relation_media', $opts['id'], $opts['new_id'])) !== true) { msg('Error while updating the search index '.$idx_msg, -1); return false; }