* (bug 9151) Fix relative subpage links with section fragments
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 12 Jul 2007 21:02:25 +0000 (21:02 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 12 Jul 2007 21:02:25 +0000 (21:02 +0000)
RELEASE-NOTES
includes/Parser.php

index e8da053..da36047 100644 (file)
@@ -285,6 +285,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   Now matches the selection behavior on Mozilla / Safari.
   Patch by Alex Smotrov.
 * Don't show non-functional toolbar buttons on Opera 7 anymore
+* (bug 9151) Fix relative subpage links with section fragments
+
 
 == API changes since 1.10 ==
 
index ef66344..3495943 100644 (file)
@@ -1927,12 +1927,18 @@ class Parser
                wfProfileIn( $fname );
                $ret = $target; # default return value is no change
 
-               # bug 7425
-               $target = trim( $target );
-
                # Some namespaces don't allow subpages,
                # so only perform processing if subpages are allowed
                if( $this->areSubpagesAllowed() ) {
+                       $hash = strpos( $target, '#' );
+                       if( $hash !== false ) {
+                               $suffix = substr( $target, $hash );
+                               $target = substr( $target, 0, $hash );
+                       } else {
+                               $suffix = '';
+                       }
+                       # bug 7425
+                       $target = trim( $target );
                        # Look at the first character
                        if( $target != '' && $target{0} == '/' ) {
                                # / at end means we don't want the slash to be shown
@@ -1944,9 +1950,9 @@ class Parser
                                        $noslash = substr( $target, 1 );
                                }
 
-                               $ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash);
+                               $ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
                                if( '' === $text ) {
-                                       $text = $target;
+                                       $text = $target . $suffix;
                                } # this might be changed for ugliness reasons
                        } else {
                                # check for .. subpage backlinks
@@ -1964,13 +1970,14 @@ class Parser
                                                if( substr( $nodotdot, -1, 1 ) == '/' ) {
                                                        $nodotdot = substr( $nodotdot, 0, -1 );
                                                        if( '' === $text ) {
-                                                               $text = $nodotdot;
+                                                               $text = $nodotdot . $suffix;
                                                        }
                                                }
                                                $nodotdot = trim( $nodotdot );
                                                if( $nodotdot != '' ) {
                                                        $ret .= '/' . $nodotdot;
                                                }
+                                               $ret .= $suffix;
                                        }
                                }
                        }