Skip to content

Commit

Permalink
prevent plugin embeds from being affected by patch_links and add perm…
Browse files Browse the repository at this point in the history
… check to do push translation
  • Loading branch information
NetaliDev committed Jun 4, 2022
1 parent 50e872b commit a3a5150
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -470,8 +473,8 @@ private function insert_ignore_tags($text): string {
// prevent deepl from breaking headings
$text = preg_replace('/={1,6}/', '<ignore>${0}</ignore>', $text);

// fix for the template plugin
$text = preg_replace('/\{\{template>[\s\S]*?}}/', '<ignore>${0}</ignore>', $text);
// fix for plugins like tag or template
$text = preg_replace('/\{\{[\s\w]+?>[\s\S]*?}}/', '<ignore>${0}</ignore>', $text);

// ignore links in wikitext (outside of dokuwiki-links)
$text = preg_replace('/\S+:\/\/\S+/', '<ignore>${0}</ignore>', $text);
Expand Down Expand Up @@ -545,8 +548,8 @@ private function remove_ignore_tags($text): string {
$text = preg_replace('/<ignore>(<file[\s\S]*?>[\s\S]*?<\/file>)<\/ignore>/', '${1}', $text);
$text = preg_replace('/<ignore>(<code[\s\S]*?>[\s\S]*?<\/code>)<\/ignore>/', '${1}', $text);

// fix for the template plugin
$text = preg_replace('/<ignore>(\{\{template>[\s\S]*?}})<\/ignore>/', '${1}', $text);
// fix for plugins like tag or template
$text = preg_replace('/<ignore>(\{\{[\s\w]+?>[\s\S]*?}})<\/ignore>/', '${1}', $text);

// prevent deepl from breaking headings
$text = preg_replace('/<ignore>(={1,6})<\/ignore>/','${1}', $text);
Expand Down

0 comments on commit a3a5150

Please sign in to comment.