From 32290a00d1ba050d46e6824d9446cbfae8418717 Mon Sep 17 00:00:00 2001 From: vv221 Date: Fri, 3 Apr 2020 02:46:35 +0200 Subject: [PATCH] Ensure compatibility with "translate" plugin cf. https://www.dokuwiki.org/plugin:translate --- MenuItem.php | 17 ++++++++++++++++- action.php | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/MenuItem.php b/MenuItem.php index 4a1011b..5b14b6c 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -20,7 +20,22 @@ class MenuItem extends AbstractItem { $this->label = $label; parent::__construct(); // Edit the item to show a link to the requested children page - $this->id = $this->type.':'.$INFO['id']; + if ( ! plugin_isdisabled('translate') ) { + // If the "translate" plugin is activated, the language code should stay the top-level namespace + $translate_plugin =& plugin_load('helper', 'translate'); + $language = $translate_plugin->getPageLanguage(); + if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) { + $this->id = preg_replace( + "/^$language:/", + "$language:".$this->type.':', + $INFO['id'] + ); + } else { + $this->id = $this->type.':'.$INFO['id']; + } + } else { + $this->id = $this->type.':'.$INFO['id']; + } $this->params = []; } } diff --git a/action.php b/action.php index 69d5190..23ae1ee 100644 --- a/action.php +++ b/action.php @@ -41,10 +41,20 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin { if ( $event->data['view'] !== 'page' ) { return; } - // Get the list of children pages - $children_types = $this->getConf('children_list'); // Only add links if the current page is not included in a reserved namespace - $top_namespace = explode(':', $INFO['namespace'])[0]; + $children_types = $this->getConf('children_list'); + if ( ! plugin_isdisabled('translate') ) { + // Skip top-level namespace added by "translate" plugin + $translate_plugin =& plugin_load('helper', 'translate'); + $language = $translate_plugin->getPageLanguage(); + if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) { + $top_namespace = explode(':', $INFO['namespace'])[1]; + } else { + $top_namespace = explode(':', $INFO['namespace'])[0]; + } + } else { + $top_namespace = explode(':', $INFO['namespace'])[0]; + } if ( in_array($top_namespace, $children_types) ) { return; }