Skip to content

Commit

Permalink
Calculate only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Nov 27, 2014
1 parent 69c855f commit 7ffc21c
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions wicked/lib/Page/MergeOrRename.php
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down

0 comments on commit 7ffc21c

Please sign in to comment.