From a3a5150738607b40da94c9daba8a30867ee9d5df Mon Sep 17 00:00:00 2001 From: Netali Date: Sat, 4 Jun 2022 11:01:58 +0200 Subject: [PATCH] prevent plugin embeds from being affected by patch_links and add perm check to do push translation --- action.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/action.php b/action.php index f0e44eb..005f08a 100644 --- a/action.php +++ b/action.php @@ -188,7 +188,7 @@ private function push_translate(Doku_Event $event): void { } // check permissions - $perm = auth_quickaclcheck($ID); + $perm = auth_quickaclcheck($lang_id); $exists = page_exists($lang_id); if (($exists and $perm < AUTH_EDIT) or (!$exists and $perm < AUTH_CREATE)) { msg($this->getLang('msg_translation_fail_no_permissions') . $lang_id, -1); @@ -289,6 +289,10 @@ private function check_do_push_translate(): bool { if (!$INFO['exists']) return false; + // only allow push translation if the user can edit this page + $perm = auth_quickaclcheck($ID); + if ($perm < AUTH_EDIT) return false; + // if default language is in namespace: only allow push translation from that namespace if($this->getConf('default_lang_in_ns')) { $split_id = explode(':', $ID); @@ -386,10 +390,8 @@ private function patch_links($text, $target_lang, $ns): string { foreach ($matches as $match) { - if (strpos($match[1], '://') !== false) { - // external link --> skip - continue; - } + // external link --> skip + if (strpos($match[1], '://') !== false) continue; $resolved_id = $match[1]; @@ -426,10 +428,11 @@ private function patch_links($text, $target_lang, $ns): string { foreach ($matches as $match) { - if (strpos($match[1], '://') !== false) { - // external image --> skip - continue; - } + // external image --> skip + if (strpos($match[1], '://') !== false) continue; + + // skip things like {{tag>...}} + if (strpos($match[1], '>') !== false) continue; $resolved_id = $match[1]; @@ -470,8 +473,8 @@ private function insert_ignore_tags($text): string { // prevent deepl from breaking headings $text = preg_replace('/={1,6}/', '${0}', $text); - // fix for the template plugin - $text = preg_replace('/\{\{template>[\s\S]*?}}/', '${0}', $text); + // fix for plugins like tag or template + $text = preg_replace('/\{\{[\s\w]+?>[\s\S]*?}}/', '${0}', $text); // ignore links in wikitext (outside of dokuwiki-links) $text = preg_replace('/\S+:\/\/\S+/', '${0}', $text); @@ -545,8 +548,8 @@ private function remove_ignore_tags($text): string { $text = preg_replace('/([\s\S]*?<\/file>)<\/ignore>/', '${1}', $text); $text = preg_replace('/([\s\S]*?<\/code>)<\/ignore>/', '${1}', $text); - // fix for the template plugin - $text = preg_replace('/(\{\{template>[\s\S]*?}})<\/ignore>/', '${1}', $text); + // fix for plugins like tag or template + $text = preg_replace('/(\{\{[\s\w]+?>[\s\S]*?}})<\/ignore>/', '${1}', $text); // prevent deepl from breaking headings $text = preg_replace('/(={1,6})<\/ignore>/','${1}', $text);