From e137f57890b858217c1bae02703033f1a57e41ba Mon Sep 17 00:00:00 2001 From: vv221 Date: Fri, 3 Apr 2020 22:13:43 +0200 Subject: [PATCH] Ensure compatibility with "translation" plugin cf. https://www.dokuwiki.org/plugin:translation --- MenuItem.php | 23 +++++++++++++---------- action.php | 15 +++++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/MenuItem.php b/MenuItem.php index 2362e12..1fd401e 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -27,19 +27,22 @@ class MenuItem extends AbstractItem { protected function setTargetFromType() : void { global $INFO; global $plugin_controller; + $language = null; + // If one of the "translate" or "translation" plugins is activated, get the language code for the current page if ( ! $plugin_controller->isdisabled('translate') ) { - // If the "translate" plugin is activated, the language code should stay the top-level namespace $translate_plugin =& $plugin_controller->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']; - } + } elseif ( ! $plugin_controller->isdisabled('translation') ) { + $translation_plugin =& $plugin_controller->load('helper', 'translation'); + $language = $translation_plugin->getLangPart($INFO['id']); + } + // If the top level namespace is a language one, the children namespace should be inserted inside it + 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']; } diff --git a/action.php b/action.php index d64ccf8..9062349 100644 --- a/action.php +++ b/action.php @@ -81,15 +81,18 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin { protected function getTopLevelNamespace() : ?string { global $INFO; global $plugin_controller; + $language = null; + // If one of the "translate" or "translation" plugins is activated, get the language code for the current page if ( ! $plugin_controller->isdisabled('translate') ) { - // Skip top-level namespace added by "translate" plugin $translate_plugin =& $plugin_controller->load('helper', 'translate'); $language = $translate_plugin->getPageLanguage(); - if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) { - return explode(':', $INFO['namespace'])[1]; - } else { - return explode(':', $INFO['namespace'])[0]; - } + } elseif ( ! $plugin_controller->isdisabled('translation') ) { + $translation_plugin =& $plugin_controller->load('helper', 'translation'); + $language = $translation_plugin->getLangPart($INFO['id']); + } + // Skip top-level language namespace if one is in use + if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) { + return explode(':', $INFO['namespace'])[1]; } else { return explode(':', $INFO['namespace'])[0]; }