MediaWiki master
|
A service to expand, parse, and otherwise manipulate URLs. More...
Public Member Functions | |
__construct (array $options=[]) | |
expand (string $url, $defaultProto=PROTO_FALLBACK) | |
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives). | |
expandIRI (string $url) | |
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode characters with their UTF-8 original forms for more compact display and legibility for local audiences. | |
getCanonicalServer () | |
Get the canonical server, i.e. | |
getServer ( $proto) | |
Get the wiki's "server", i.e. | |
matchesDomainList (string $url, array $domains) | |
Check whether a given URL has a domain that occurs in a given set of domains. | |
parse (string $url) | |
Advanced and configurable version of parse_url(). | |
validAbsoluteProtocols () | |
Like validProtocols(), but excludes '//' from the protocol list. | |
validProtocols () | |
Returns a partial regular expression of recognized URL protocols, e.g. | |
Static Public Member Functions | |
static | assemble (array $urlParts) |
This function will reassemble a URL parsed with parse(). | |
static | removeDotSegments (string $urlPath) |
Remove all dot-segments in the provided URL path. | |
Public Attributes | |
const | CANONICAL_SERVER = 'canonicalServer' |
const | FALLBACK_PROTOCOL = 'fallbackProtocol' |
const | HTTPS_PORT = 'httpsPort' |
const | INTERNAL_SERVER = 'internalServer' |
const | SERVER = 'server' |
const | VALID_PROTOCOLS = 'validProtocols' |
A service to expand, parse, and otherwise manipulate URLs.
Definition at line 16 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::__construct | ( | array | $options = [] | ) |
array | $options | All keys are optional, but if you omit SERVER then calling expand() (and getServer(), expandIRI(), and matchesDomainList()) will throw. Recognized keys:
|
Definition at line 68 of file UrlUtils.php.
References MediaWiki\Utils\UrlUtils\CANONICAL_SERVER, MediaWiki\Utils\UrlUtils\expand(), MediaWiki\Utils\UrlUtils\FALLBACK_PROTOCOL, MediaWiki\Utils\UrlUtils\HTTPS_PORT, MediaWiki\Utils\UrlUtils\INTERNAL_SERVER, PROTO_HTTP, MediaWiki\Utils\UrlUtils\SERVER, and MediaWiki\Utils\UrlUtils\VALID_PROTOCOLS.
|
static |
This function will reassemble a URL parsed with parse().
This is useful if you need to edit part of a URL and put it back together.
This is the basic structure used (brackets contain keys for $urlParts): [scheme][delimiter][user]:[pass]@[host]:[port][path]?[query]#[fragment]
array | $urlParts | URL parts, as output from parse() |
Definition at line 233 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::expand | ( | string | $url, |
$defaultProto = PROTO_FALLBACK ) |
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
The meaning of the PROTO_* constants is as follows: PROTO_HTTP: Output a URL starting with http:// PROTO_HTTPS: Output a URL starting with https:// PROTO_RELATIVE: Output a URL starting with // (protocol-relative URL) PROTO_FALLBACK: Output a URL starting with the FALLBACK_PROTOCOL option PROTO_CURRENT: Legacy alias for PROTO_FALLBACK PROTO_CANONICAL: For URLs without a domain, like /w/index.php, use CANONICAL_SERVER. For protocol-relative URLs, use the protocol of CANONICAL_SERVER PROTO_INTERNAL: Like PROTO_CANONICAL, but uses INTERNAL_SERVER instead of CANONICAL_SERVER
If $url specifies a protocol, or $url is domain-relative and $wgServer specifies a protocol, PROTO_HTTP, PROTO_HTTPS, PROTO_RELATIVE and PROTO_CURRENT do not change that.
Parent references (/../) in the path are resolved (as in ::removeDotSegments).
BadMethodCallException | if no server was passed to the constructor |
string | $url | An URL; can be absolute (e.g. http://example.com/foo/bar), protocol-relative (//example.com/foo/bar) or domain-relative (/foo/bar). |
string | int | null | $defaultProto | One of the PROTO_* constants, as described above. |
Definition at line 124 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct(), and wfExpandUrl().
MediaWiki\Utils\UrlUtils::expandIRI | ( | string | $url | ) |
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode characters with their UTF-8 original forms for more compact display and legibility for local audiences.
BadMethodCallException | if no server was passed to the constructor |
string | $url |
Definition at line 472 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::getCanonicalServer | ( | ) |
Get the canonical server, i.e.
the canonical protocol and host part of the wiki's URL.
Definition at line 217 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::getServer | ( | $proto | ) |
Get the wiki's "server", i.e.
the protocol and host part of the URL, with a protocol specified using a PROTO_* constant as in expand()
BadMethodCallException | if no server was passed to the constructor |
string | int | null | $proto | One of the PROTO_* constants. |
Definition at line 204 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::matchesDomainList | ( | string | $url, |
array | $domains ) |
Check whether a given URL has a domain that occurs in a given set of domains.
BadMethodCallException | if no server was passed to the constructor |
string | $url | |
array | $domains | Array of domains (strings) |
Definition at line 492 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::parse | ( | string | $url | ) |
Advanced and configurable version of parse_url().
1) Add a "delimiter" element to the array, which helps permits to blindly re-assemble any URL regardless of protocol, including those that don't use ://
, such as "mailto:" and "news:". 2) Reject URLs with protocols not in $wgUrlProtocols. 3) Reject relative or incomplete URLs that parse_url would return a partial array for.
If all you need is to extract parts of an HTTP or HTTPS URL (i.e. not specific to site-configurable extra protocols, or user input) then parse_url()
can be used directly instead.
string | $url | A URL to parse |
Definition at line 421 of file UrlUtils.php.
References $url.
|
static |
Remove all dot-segments in the provided URL path.
For example, '/a/./b/../c/' becomes '/a/c/'. For details on the algorithm, please see RFC3986 section 5.2.4.
string | $urlPath | URL path, potentially containing dot-segments |
Definition at line 283 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::validAbsoluteProtocols | ( | ) |
Like validProtocols(), but excludes '//' from the protocol list.
Use this if you need a regex that matches all URL protocols but does not match protocol-relative URLs
Definition at line 365 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::validProtocols | ( | ) |
Returns a partial regular expression of recognized URL protocols, e.g.
"http:\\/\\/|https:\\/\\/"
Definition at line 354 of file UrlUtils.php.
Referenced by MediaWiki\Parser\Parser\__construct().
const MediaWiki\Utils\UrlUtils::CANONICAL_SERVER = 'canonicalServer' |
Definition at line 18 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::FALLBACK_PROTOCOL = 'fallbackProtocol' |
Definition at line 20 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::HTTPS_PORT = 'httpsPort' |
Definition at line 21 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::INTERNAL_SERVER = 'internalServer' |
Definition at line 19 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::SERVER = 'server' |
Definition at line 17 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::VALID_PROTOCOLS = 'validProtocols' |
Definition at line 22 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().