$needle = null;
return;
}
-
+
if ( is_null( $needle ) ) {
$needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F' );
if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) || ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false ) ) {
/**
* Expand a potentially local URL to a fully-qualified URL. Assumes $wgServer
* is correct.
- *
+ *
* 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://
function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
global $wgServer, $wgCanonicalServer;
$serverUrl = $defaultProto === PROTO_CANONICAL ? $wgCanonicalServer : $wgServer;
-
+
if ( $defaultProto === PROTO_CURRENT ) {
$defaultProto = WebRequest::detectProtocol() . '://';
}
-
+
// Analyze $serverUrl to obtain its protocol
$bits = wfParseUrl( $serverUrl );
$serverHasProto = $bits && $bits['scheme'] != '';
-
+
if ( $defaultProto === PROTO_CANONICAL ) {
if ( $serverHasProto ) {
$defaultProto = $bits['scheme'] . '://';
$defaultProto = PROTO_HTTP;
}
}
-
+
$defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 );
-
+
if( substr( $url, 0, 2 ) == '//' ) {
return $defaultProtoWithoutSlashes . $url;
} elseif( substr( $url, 0, 1 ) == '/' ) {
// URLs weren't supported until 1.18
$retval = $wgUrlProtocols;
}
-
+
// Cache return value
if ( $includeProtocolRelative ) {
$withProtRel = $retval;
return $index;
}
+/**
+ * Check whether a given URL has a domain that occurs in a given set of domains
+ * @param $url string URL
+ * @param $domains array Array of domains (strings)
+ * @return bool True if the host part of $url ends in one of the strings in $domains
+ */
+function wfMatchesDomainList( $url, $domains ) {
+ $bits = wfParseUrl( $url );
+ if ( is_array( $bits ) && isset( $bits['host'] ) ) {
+ foreach ( (array)$domains as $domain ) {
+ // FIXME: This gives false positives. http://nds-nl.wikipedia.org will match nl.wikipedia.org
+ // We should use something that interprets dots instead
+ if ( substr( $bits['host'], -strlen( $domain ) ) === $domain ) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
/**
* Sends a line to the debug log if enabled or, optionally, to a comment in output.
* In normal operation this is a NOP.
* debug_backtrace is disabled, otherwise the output from
* debug_backtrace() (trimmed).
*
+ * @param $limit int This parameter can be used to limit the number of stack frames returned
+ *
* @return array of backtrace information
*/
function wfDebugBacktrace( $limit = 0 ) {
}
if ( $limit && version_compare( PHP_VERSION, '5.4.0', '>=' ) ) {
- return array_slice( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 1 ), 1 );
+ return array_slice( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit ), 1 );
} else {
return array_slice( debug_backtrace(), 1 );
}