- if (bestlink($page, $2) eq $old) {
- $link=$new;
- if ($linktext =~ m/\/*?[A-Z]/) {
- # preserve leading cap
- $link=ucfirst($link);
+ if (bestlink($page, linkpage($linktext)) eq $old) {
+ $link=pagetitle($new, 1);
+ $link=~s/ /_/g;
+ if ($linktext =~ m/.*\/*?[A-Z]/) {
+ # preserve leading cap of last component
+ my @bits=split("/", $link);
+ $link=join("/", @bits[0..$#bits-1], ucfirst($bits[$#bits]));