MediaWiki REL1_39
|
A service to expand, parse, and otherwise manipulate URLs. More...
Public Member Functions | |
__construct (array $options=[]) | |
assemble (array $urlParts) | |
This function will reassemble a URL parsed with parse(). | |
expand (string $url, $defaultProto=PROTO_FALLBACK) | |
Expand a potentially local URL to a fully-qualified URL. | |
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) | |
parse_url() work-alike, but non-broken. | |
removeDotSegments (string $urlPath) | |
Remove all dot-segments in the provided URL path. | |
validAbsoluteProtocols () | |
Like validProtocols(), but excludes '//' from the protocol list. | |
validProtocols () | |
Returns a regular expression of recognized URL protocols. | |
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 17 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 69 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.
MediaWiki\Utils\UrlUtils::assemble | ( | array | $urlParts | ) |
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 228 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::expand | ( | string | $url, |
$defaultProto = PROTO_FALLBACK ) |
Expand a potentially local URL to a fully-qualified URL.
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
BadMethodCallException | if no server was passed to the constructor |
string | $url | Either fully-qualified or a local path + query |
string | int | null | $defaultProto | One of the PROTO_* constants. Determines the protocol to use if $url or SERVER is protocol-relative |
Definition at line 118 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 491 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 211 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 198 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 513 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::parse | ( | string | $url | ) |
parse_url() work-alike, but non-broken.
Differences:
1) Handles protocols that don't use :// (e.g., mailto: and news:, as well as protocol-relative URLs) correctly. 2) Adds a "delimiter" element to the array (see (2)). 3) Verifies that the protocol is on the UrlProtocols allowed list. 4) Rejects some invalid URLs that parse_url doesn't, e.g. the empty string or URLs starting with a line feed character.
string | $url | A URL to parse |
Definition at line 425 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::removeDotSegments | ( | string | $urlPath | ) |
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 279 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 369 of file UrlUtils.php.
MediaWiki\Utils\UrlUtils::validProtocols | ( | ) |
Returns a regular expression of recognized URL protocols.
Definition at line 355 of file UrlUtils.php.
Referenced by Parser\__construct().
const MediaWiki\Utils\UrlUtils::CANONICAL_SERVER = 'canonicalServer' |
Definition at line 19 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::FALLBACK_PROTOCOL = 'fallbackProtocol' |
Definition at line 21 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::HTTPS_PORT = 'httpsPort' |
Definition at line 22 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::INTERNAL_SERVER = 'internalServer' |
Definition at line 20 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::SERVER = 'server' |
Definition at line 18 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().
const MediaWiki\Utils\UrlUtils::VALID_PROTOCOLS = 'validProtocols' |
Definition at line 23 of file UrlUtils.php.
Referenced by MediaWiki\Utils\UrlUtils\__construct().