From 223498207fd236fd325ccc48a8370195231d8e61 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 12 Jul 2007 21:02:25 +0000 Subject: [PATCH] * (bug 9151) Fix relative subpage links with section fragments --- RELEASE-NOTES | 2 ++ includes/Parser.php | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e8da0534db..da36047cd6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Parser.php b/includes/Parser.php index ef66344bf3..34959437a5 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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; } } } -- 2.20.1