From 3a83755646e624145fa73678c4cc7bec5aee58e3 Mon Sep 17 00:00:00 2001 From: gicode Date: Tue, 15 Nov 2011 18:53:20 +0000 Subject: [PATCH] Make wfExpandUrl use wfRemoveDotSegments on the resulting path. This finishes off bug 32168. Also follow-up r103199 (related) to use isset. --- RELEASE-NOTES-1.19 | 1 + includes/GlobalFunctions.php | 44 ++++++++++++++++++++++++------------ tests/parser/parserTests.txt | 2 +- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 2c57f474aa..c4a2cc043f 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -136,6 +136,7 @@ production. * (bug 32358) Do not display "No higher resolution available" for dimensionless files (like audio files) * (bug 32168) Add wfAssembleUrl for use in wfExpandUrl +* (bug 32168) fixed - wfExpandUrl expands dot segments now === API changes in 1.19 === * (bug 19838) siprop=interwikimap can now use the interwiki cache. diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 8e4f693766..5a9202e34f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -444,8 +444,11 @@ function wfAppendQuery( $url, $query ) { * like "subdir/foo.html", etc. * * @param $url String: either fully-qualified or a local path + query - * @param $defaultProto Mixed: one of the PROTO_* constants. Determines the protocol to use if $url or $wgServer is protocol-relative - * @return string Fully-qualified URL + * @param $defaultProto Mixed: one of the PROTO_* constants. Determines the + * protocol to use if $url or $wgServer is + * protocol-relative + * @return string Fully-qualified URL, current-path-relative URL or false if + * no valid URL can be constructed */ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { global $wgServer, $wgCanonicalServer, $wgInternalServer; @@ -478,13 +481,26 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { $defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 ); if ( substr( $url, 0, 2 ) == '//' ) { - return $defaultProtoWithoutSlashes . $url; + $url = $defaultProtoWithoutSlashes . $url; } elseif ( substr( $url, 0, 1 ) == '/' ) { // If $serverUrl is protocol-relative, prepend $defaultProtoWithoutSlashes, otherwise leave it alone - return ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url; - } else { + $url = ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url; + } + + $bits = wfParseUrl( $url ); + if ( $bits && isset( $bits['path'] ) ) { + $bits['path'] = wfRemoveDotSegments( $bits['path'] ); + return wfAssembleUrl( $bits ); + } elseif ( $bits ) { + # No path to expand return $url; + } elseif ( substr( $url, 0, 1 ) != '/' ) { + # URL is a relative path + return wfRemoveDotSegments( $url ); } + + # Expanded URL is not valid. + return false; } /** @@ -502,18 +518,18 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { function wfAssembleUrl( $urlParts ) { $result = ''; - if ( array_key_exists( 'delimiter', $urlParts ) ) { - if ( array_key_exists( 'scheme', $urlParts ) ) { + if ( isset( $urlParts['delimiter'] ) ) { + if ( isset( $urlParts['scheme'] ) ) { $result .= $urlParts['scheme']; } $result .= $urlParts['delimiter']; } - if ( array_key_exists( 'host', $urlParts ) ) { - if ( array_key_exists( 'user', $urlParts ) ) { + if ( isset( $urlParts['host'] ) ) { + if ( isset( $urlParts['user'] ) ) { $result .= $urlParts['user']; - if ( array_key_exists( 'pass', $urlParts ) ) { + if ( isset( $urlParts['pass'] ) ) { $result .= ':' . $urlParts['pass']; } $result .= '@'; @@ -521,20 +537,20 @@ function wfAssembleUrl( $urlParts ) { $result .= $urlParts['host']; - if ( array_key_exists( 'port', $urlParts ) ) { + if ( isset( $urlParts['port'] ) ) { $result .= ':' . $urlParts['port']; } } - if ( array_key_exists( 'path', $urlParts ) ) { + if ( isset( $urlParts['path'] ) ) { $result .= $urlParts['path']; } - if ( array_key_exists( 'query', $urlParts ) ) { + if ( isset( $urlParts['query'] ) ) { $result .= '?' . $urlParts['query']; } - if ( array_key_exists( 'fragment', $urlParts ) ) { + if ( isset( $urlParts['fragment'] ) ) { $result .= '#' . $urlParts['fragment']; } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 313842273f..d56726fd13 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -1871,7 +1871,7 @@ Inline interwiki link with empty title (bug 2372) !! input [[MeatBall:]] !! result -

MeatBall: +

MeatBall:

!! end -- 2.20.1