$query = wfArrayToCgi( $query );
}
if ( $query != '' ) {
+ // Remove the fragment, if there is one
+ $fragment = false;
+ $hashPos = strpos( $url, '#' );
+ if ( $hashPos !== false ) {
+ $fragment = substr( $url, $hashPos );
+ $url = substr( $url, 0, $hashPos );
+ }
+
+ // Add parameter
if ( false === strpos( $url, '?' ) ) {
$url .= '?';
} else {
$url .= '&';
}
$url .= $query;
+
+ // Put the fragment back
+ if ( $fragment !== false ) {
+ $url .= $fragment;
+ }
}
return $url;
}
'baz=quux&foo=baz',
'http://www.example.org/index.php?foo=bar&baz=quux&foo=baz',
'Modify query string'
+ ],
+ [
+ 'http://www.example.org/index.php#baz',
+ 'foo=bar',
+ 'http://www.example.org/index.php?foo=bar#baz',
+ 'URL with fragment'
+ ],
+ [
+ 'http://www.example.org/index.php?foo=bar#baz',
+ 'quux=blah',
+ 'http://www.example.org/index.php?foo=bar&quux=blah#baz',
+ 'URL with query string and fragment'
]
];
}