[Home]WikiPatches/AnchorsInFreeLinkBugFix

UseModWiki | WikiPatches | RecentChanges | Preferences

1. Bug Description

User can use named anchor in FreeLinks in UseMod Wiki 1.0. But the appearance is not so good. You can write test code like this:


* [[WikiPatches/AnchorsInFreeLinkBugFix#bottom|Goto bottom]]
* [[WikiPatches/AnchorsInFreeLinkBugFix#bottom]]

1.1. Before fix the bug, it looks like

1.2. After apply this bugfix, looks like

2. bugfix code

--- wiki.pl	2003-09-11 20:21:02.000000000 +0800
+++ wiki.pl.freelink	2003-11-16 22:36:36.468750000 +0800
@@ -301,9 +301,17 @@
       $AnyLetter = "[-,.()' _0-9A-Za-z]";
     }
   }
-  $FreeLinkPattern = "($AnyLetter+)";
+  $FreeLinkPattern = "($AnyLetter+";
   if ($UseSubpage) {
-    $FreeLinkPattern = "((?:(?:$AnyLetter+)?\\/)?$AnyLetter+)";
+    $FreeLinkPattern = "((?:(?:$AnyLetter+)?\\/)?$AnyLetter+";
+  }
+  if ($NamedAnchors)
+  {
+    $FreeLinkPattern .= "(?:#(?:\\w+))?)";
+  }
+  else
+  {
+    $FreeLinkPattern .= ")";
   }
   $FreeLinkPattern .= $QDelim;
   # Url-style links are delimited by one of:
@@ -1157,6 +1165,7 @@
 sub GetPageOrEditAnchoredLink {
   my ($id, $anchor, $name) = @_;
   my (@temp, $exists);
+  my $NamedFreeLink = 0;
 
   if ($name eq "") {
     $name = $id;
@@ -1164,6 +1173,10 @@
       $name =~ s/_/ /g;
     }
   }
+  else
+  {
+    $NamedFreeLink = 1;
+  }
   $id =~ s|^/|$MainPage/|;
   if ($FreeLinks) {
     $id = &FreeToNormal($id);
@@ -1179,7 +1192,7 @@
   }
   if ($exists) {
     $id = "$id#$anchor"  if $anchor;
-    $name = "$name#$anchor"  if $anchor && $NamedAnchors != 2;
+    $name = "$name#$anchor"  if $anchor && $NamedAnchors != 2 && !$NamedFreeLink;
     return &GetPageLinkText($id, $name);
   }
   if ($FreeLinks && !$EditNameLink) {
@@ -1196,7 +1209,8 @@
 
 sub GetPageOrEditLink {
     my ($id, $name) = @_;
-    return &GetPageOrEditAnchoredLink($id, "", $name);
+    my ($link, $anchor) = split( /#/, $id, 2);
+    return &GetPageOrEditAnchoredLink($link, $anchor, $name);
 }
 
 sub GetBackLinksSearchLink {

-- Johnson


Applied to my wiki and works well --BrianHunter


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited July 16, 2008 4:26 pm by MarkusLude (diff)
Search: