Skip to content

Commit

Permalink
Use the new media usage index from DokuWiki core if available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michitux committed Oct 29, 2013
1 parent ec7eb75 commit fa5ce2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -117,14 +119,16 @@ 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);
if (is_array($instructions)) {
$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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit fa5ce2c

Please sign in to comment.