diff --git a/wicked/lib/Page/MergeOrRename.php b/wicked/lib/Page/MergeOrRename.php index 6860f716e6d..5936c8242d4 100644 --- a/wicked/lib/Page/MergeOrRename.php +++ b/wicked/lib/Page/MergeOrRename.php @@ -225,12 +225,30 @@ public function handleAction() $wikiWord = '/^' . Wicked::REGEXP_WIKIWORD . '$/'; + $changelog = sprintf(_("Changed references from %s to %s"), + $referrer, $new_name); + + if (preg_match($wikiWord, $new_name)) { + $replaceWith = $new_name; + } else { + $replaceWith = '((' . $new_name . '))'; + } + + $from = array('/\(\(' . preg_quote($referrer, '/') . '\)\)/'); + $to = array($replaceWith); + + // If this works as a bare wiki word, replace that, too. + if (preg_match($wikiWord, $referrer)) { + $from[] = '/\b' . preg_quote($referrer, '/') . '\b/'; + $to[] = $replaceWith; + } + // We don't check permissions on these pages since we want references // to be fixed even if the user doing the editing couldn't fix that // page, and fixing references is likely to never be a destructive // action, and the user can't supply their own data for it. $references = Horde_Util::getFormData('ref', array()); - foreach ($references as $name => $value) { + foreach (array_keys($references) as $name) { $page_name = quoted_printable_decode($name); // Fix up for self-references. @@ -247,24 +265,6 @@ public function handleAction() continue; } - $changelog = sprintf(_("Changed references from %s to %s"), - $referrer, $new_name); - - if (preg_match($wikiWord, $new_name)) { - $replaceWith = $new_name; - } else { - $replaceWith = '((' . $new_name . '))'; - } - - $from = array('/\(\(' . preg_quote($referrer, '/') . '\)\)/'); - $to = array($replaceWith); - - // If this works as a bare wiki word, replace that, too. - if (preg_match($wikiWord, $referrer)) { - $from[] = '/\b' . preg_quote($referrer, '/') . '\b/'; - $to[] = $replaceWith; - } - $newText = preg_replace($from, $to, $refPage['page_text']); $wicked->updateText($page_name, $newText, $changelog); }