Constructor
new mw.Uri([uri], [options])
#
Construct a new URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
uri |
Object | string |
optional |
URI string, or an Object with appropriate properties (especially
another URI object to clone). Object must have non-blank |
options |
mw.Uri.UriOptions | boolean |
optional |
Object with options, or (backwards compatibility) a boolean for strictMode |
- Source:
Throws:
-
when the query string or fragment contains an unknown % sequence
- Type
- Error
Properties
/dir/dir.2/index.htm
(always present).
{ a: '0', b: '', c: 'value' }
(always present).
Methods
clone() → {Object}
#
extend(parameters) → {Object}
#
getAuthority() → {string}
#
Get the userInfo, host and port section of the URI.
In most real-world URLs this is simply the hostname, but the definition of 'authority' section is more general.
- Source:
Returns:
- Type
- string
getQueryString() → {string}
#
Get the query arguments of the URL, encoded into a string.
Does not preserve the original order of arguments passed in the URI. Does handle escaping.
- Source:
Returns:
- Type
- string
getRelativePath() → {string}
#
toString() → {string}
#
Get the entire URI string.
Note that the output may not be precisely the same as the constructor input, due to order of query arguments. Note also that the fragment is not always roundtripped as-is; some characters will become encoded, including the slash character, which can cause problems with e.g. mediawiki.router. It is recommended to use the native URL class (via web2017-polyfills, which loads a polyfill if needed) in contexts where the fragment is important.
- Source:
Returns:
The URI string
- Type
- string
decode(s) → {string}static
#
encode(s) → {string}static
#
Encode a value for inclusion in a url.
Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more
compliant with RFC 3986. Similar to rawurlencode from PHP and our JS library
mw.util.rawurlencode
, except this also replaces spaces with +
.
Parameters:
Name | Type | Description |
---|---|---|
s |
string | String to encode |
- Source:
Returns:
Encoded string for URI
- Type
- string
Type Definitions
UriOptions
#
Options for mw.Uri object.
Type:
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
strictMode |
boolean |
optional |
false | Trigger strict mode parsing of the url. |
overrideKeys |
boolean |
optional |
false | Whether to let duplicate query parameters
override each other ( |
arrayParams |
boolean |
optional |
false | Whether to parse array query parameters (e.g.
|
- Source: