Ensure compatibility with "translate" plugin

cf. https://www.dokuwiki.org/plugin:translate
This commit is contained in:
vv221 2020-04-03 02:46:35 +02:00
parent a45accac4b
commit 32290a00d1
2 changed files with 29 additions and 4 deletions

View file

@ -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
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 = [];
}
}

View file

@ -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
$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;
}