$cgi = '';
foreach ( $array1 as $key => $value ) {
- if ( !is_null($value) && $value !== false ) {
+ if ( $value !== false ) {
if ( $cgi != '' ) {
$cgi .= '&';
}
} else {
if ( is_object( $value ) ) {
$value = $value->__toString();
+ } elseif( !is_null( $value ) ) {
+ $cgi .= urlencode( $key ) . '=' . urlencode( $value );
+ } else {
+ $cgi .= urlencode( $key );
}
- $cgi .= urlencode( $key ) . '=' . urlencode( $value );
}
}
}
continue;
}
if ( strpos( $bit, '=' ) === false ) {
- // Pieces like &qwerty become 'qwerty' => '' (at least this is what php does)
- $key = $bit;
- $value = '';
+ // Pieces like &qwerty become 'qwerty' => null
+ $key = urldecode( $bit );
+ $value = null;
} else {
list( $key, $value ) = explode( '=', $bit );
+ $key = urldecode( $key );
+ $value = urldecode( $value );
}
- $key = urldecode( $key );
- $value = urldecode( $value );
+
if ( strpos( $key, '[' ) !== false ) {
$keys = array_reverse( explode( '[', $key ) );
$key = array_pop( $keys );
* Append a query string to an existing URL, which may or may not already
* have query string parameters already. If so, they will be combined.
*
+ * @deprecated in 1.20. Use Uri class.
* @param $url String
* @param $query Mixed: string or associative array
* @return string
*/
function wfAppendQuery( $url, $query ) {
- if ( is_array( $query ) ) {
- $query = wfArrayToCgi( $query );
- }
- if( $query != '' ) {
- if( false === strpos( $url, '?' ) ) {
- $url .= '?';
- } else {
- $url .= '&';
- }
- $url .= $query;
- }
- return $url;
+ $obj = new Uri( $url );
+ $obj->extendQuery( $query );
+ return $obj->toString();
}
/**
* @todo Need to integrate this into wfExpandUrl (bug 32168)
*
* @since 1.19
+ * @deprecated
* @param $urlParts Array URL parts, as output from wfParseUrl
* @return string URL assembled from its component parts
*/
function wfAssembleUrl( $urlParts ) {
- $result = '';
-
- if ( isset( $urlParts['delimiter'] ) ) {
- if ( isset( $urlParts['scheme'] ) ) {
- $result .= $urlParts['scheme'];
- }
-
- $result .= $urlParts['delimiter'];
- }
-
- if ( isset( $urlParts['host'] ) ) {
- if ( isset( $urlParts['user'] ) ) {
- $result .= $urlParts['user'];
- if ( isset( $urlParts['pass'] ) ) {
- $result .= ':' . $urlParts['pass'];
- }
- $result .= '@';
- }
-
- $result .= $urlParts['host'];
-
- if ( isset( $urlParts['port'] ) ) {
- $result .= ':' . $urlParts['port'];
- }
- }
-
- if ( isset( $urlParts['path'] ) ) {
- $result .= $urlParts['path'];
- }
-
- if ( isset( $urlParts['query'] ) ) {
- $result .= '?' . $urlParts['query'];
- }
-
- if ( isset( $urlParts['fragment'] ) ) {
- $result .= '#' . $urlParts['fragment'];
- }
-
- return $result;
+ $obj = new Uri( $urlParts );
+ return $obj->toString();
}
/**
* 2) Handles protocols that don't use :// (e.g., mailto: and news: , as well as protocol-relative URLs) correctly
* 3) Adds a "delimiter" element to the array, either '://', ':' or '//' (see (2))
*
+ * @deprecated
* @param $url String: a URL to parse
* @return Array: bits of the URL in an associative array, per PHP docs
*/
function wfParseUrl( $url ) {
- global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php
-
- // Protocol-relative URLs are handled really badly by parse_url(). It's so bad that the easiest
- // way to handle them is to just prepend 'http:' and strip the protocol out later
- $wasRelative = substr( $url, 0, 2 ) == '//';
- if ( $wasRelative ) {
- $url = "http:$url";
- }
- wfSuppressWarnings();
- $bits = parse_url( $url );
- wfRestoreWarnings();
- // parse_url() returns an array without scheme for some invalid URLs, e.g.
- // parse_url("%0Ahttp://example.com") == array( 'host' => '%0Ahttp', 'path' => 'example.com' )
- if ( !$bits || !isset( $bits['scheme'] ) ) {
- return false;
- }
-
- // most of the protocols are followed by ://, but mailto: and sometimes news: not, check for it
- if ( in_array( $bits['scheme'] . '://', $wgUrlProtocols ) ) {
- $bits['delimiter'] = '://';
- } elseif ( in_array( $bits['scheme'] . ':', $wgUrlProtocols ) ) {
- $bits['delimiter'] = ':';
- // parse_url detects for news: and mailto: the host part of an url as path
- // We have to correct this wrong detection
- if ( isset( $bits['path'] ) ) {
- $bits['host'] = $bits['path'];
- $bits['path'] = '';
- }
- } else {
- return false;
- }
-
- /* Provide an empty host for eg. file:/// urls (see bug 28627) */
- if ( !isset( $bits['host'] ) ) {
- $bits['host'] = '';
-
- /* parse_url loses the third / for file:///c:/ urls (but not on variants) */
- if ( substr( $bits['path'], 0, 1 ) !== '/' ) {
- $bits['path'] = '/' . $bits['path'];
- }
- }
-
- // If the URL was protocol-relative, fix scheme and delimiter
- if ( $wasRelative ) {
- $bits['scheme'] = '';
- $bits['delimiter'] = '//';
- }
- return $bits;
+ $obj = new Uri( $url );
+ return $obj->getComponents();
}
/**
* @param $logonly Bool: set true to avoid appearing in HTML when $wgDebugComments is set
*/
function wfDebug( $text, $logonly = false ) {
- global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
- global $wgDebugLogPrefix, $wgShowDebug;
-
- static $cache = array(); // Cache of unoutputted messages
+ global $wgDebugLogFile, $wgProfileOnly, $wgDebugRawPage, $wgDebugLogPrefix;
if ( !$wgDebugRawPage && wfIsDebugRawPage() ) {
return;
$text = preg_replace( '/[^\n]/', $timer . '\0', $text, 1 );
}
- if ( ( $wgDebugComments || $wgShowDebug ) && !$logonly ) {
- $cache[] = $text;
-
- if ( isset( $wgOut ) && is_object( $wgOut ) ) {
- // add the message and any cached messages to the output
- array_map( array( $wgOut, 'debug' ), $cache );
- $cache = array();
- }
+ if ( !$logonly ) {
+ MWDebug::debugMsg( $text );
}
+
if ( wfRunHooks( 'Debug', array( $text, null /* no log group */ ) ) ) {
if ( $wgDebugLogFile != '' && !$wgProfileOnly ) {
# Strip unprintables; they can switch terminal modes when binary data
wfErrorLog( $text, $wgDebugLogFile );
}
}
-
- MWDebug::debugMsg( $text );
}
/**
* @param $text String: database error message.
*/
function wfLogDBError( $text ) {
- global $wgDBerrorLog;
+ global $wgDBerrorLog, $wgDBerrorLogTZ;
+ static $logDBErrorTimeZoneObject = null;
+
if ( $wgDBerrorLog ) {
$host = wfHostname();
$wiki = wfWikiID();
- $text = date( 'D M j G:i:s T Y' ) . "\t$host\t$wiki\t$text";
+
+ if ( $wgDBerrorLogTZ && !$logDBErrorTimeZoneObject ) {
+ $logDBErrorTimeZoneObject = new DateTimeZone( $wgDBerrorLogTZ );
+ }
+
+ // Workaround for https://bugs.php.net/bug.php?id=52063
+ // Can be removed when min PHP > 5.3.2
+ if ( $logDBErrorTimeZoneObject === null ) {
+ $d = date_create( "now" );
+ } else {
+ $d = date_create( "now", $logDBErrorTimeZoneObject );
+ }
+ $date = $d->format( 'D M j G:i:s T Y' );
+
+ $text = "$date\t$host\t$wiki\t$text";
wfErrorLog( $text, $wgDBerrorLog );
}
}
* Use wfMsgForContent() instead if the message should NOT
* change depending on the user preferences.
*
+ * @deprecated since 1.18
+ *
* @param $key String: lookup key for the message, usually
* defined in languages/Language.php
*
/**
* Same as above except doesn't transform the message
*
+ * @deprecated since 1.18
+ *
* @param $key String
* @return String
*/
* customize potentially hundreds of messages in
* order to, e.g., fix a link in every possible language.
*
+ * @deprecated since 1.18
+ *
* @param $key String: lookup key for the message, usually
* defined in languages/Language.php
* @return String
/**
* Same as above except doesn't transform the message
*
+ * @deprecated since 1.18
+ *
* @param $key String
* @return String
*/
/**
* Really get a message
*
+ * @deprecated since 1.18
+ *
* @param $key String: key to get.
* @param $args
* @param $useDB Boolean
/**
* Fetch a message string value, but don't replace any keys yet.
*
+ * @deprecated since 1.18
+ *
* @param $key String
* @param $useDB Bool
* @param $langCode String: Code of the language to get the message for, or
/**
* Replace message parameter keys on the given formatted output.
*
+ * @deprecated since 1.18
+ *
* @param $message String
* @param $args Array
* @return string
* to pre-escape them if you really do want plaintext, or just wrap
* the whole thing in htmlspecialchars().
*
+ * @deprecated since 1.18
+ *
* @param $key String
* @param string ... parameters
* @return string
* to pre-escape them if you really do want plaintext, or just wrap
* the whole thing in htmlspecialchars().
*
+ * @deprecated since 1.18
+ *
* @param $key String
* @param string ... parameters
* @return string
/**
* Returns message in the requested format
+ *
+ * @deprecated since 1.18
+ *
* @param $key String: key of the message
* @param $options Array: processing rules. Can take the following options:
* <i>parse</i>: parses wikitext to HTML
* looked up didn't exist but a XHTML string, this function checks for the
* nonexistance of messages by checking the MessageCache::get() result directly.
*
+ * @deprecated since 1.18. Use Message::isDisabled().
+ *
* @param $key String: the message key looked up
* @return Boolean True if the message *doesn't* exist.
*/
* @return String
*/
function wfShowingResults( $offset, $limit ) {
- global $wgLang;
- return wfMsgExt(
- 'showingresults',
- array( 'parseinline' ),
- $wgLang->formatNum( $limit ),
- $wgLang->formatNum( $offset + 1 )
- );
+ return wfMessage( 'showingresults' )->numParams( $limit, $offset + 1 )->parse();
}
/**
global $wgDirectoryMode;
if ( FileBackend::isStoragePath( $dir ) ) { // sanity
- throw new MWException( __FUNCTION__ . " given storage path `$dir`.");
+ throw new MWException( __FUNCTION__ . " given storage path '$dir'." );
}
if ( !is_null( $caller ) ) {
* (non-zero is usually failure)
* @param $environ Array optional environment variables which should be
* added to the executed command environment.
+ * @param $limits Array optional array with limits(filesize, memory, time)
+ * this overwrites the global wgShellMax* limits.
* @return string collected stdout as a string (trailing newlines stripped)
*/
-function wfShellExec( $cmd, &$retval = null, $environ = array() ) {
+function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array() ) {
global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime;
static $disabled;
$cmd = $envcmd . $cmd;
if ( php_uname( 's' ) == 'Linux' ) {
- $time = intval( $wgMaxShellTime );
- $mem = intval( $wgMaxShellMemory );
- $filesize = intval( $wgMaxShellFileSize );
+ $time = intval ( isset($limits['time']) ? $limits['time'] : $wgMaxShellTime );
+ $mem = intval ( isset($limits['memory']) ? $limits['memory'] : $wgMaxShellMemory );
+ $filesize = intval ( isset($limits['filesize']) ? $limits['filesize'] : $wgMaxShellFileSize );
if ( $time > 0 && $mem > 0 ) {
$script = "$IP/bin/ulimit4.sh";
* http://bugs.php.net/bug.php?id=33898
*
* PHP's basename() only considers '\' a pathchar on Windows and Netware.
- * We'll consider it so always, as we don't want \s in our Unix paths either.
+ * We'll consider it so always, as we don't want '\s' in our Unix paths either.
*
* @param $path String
* @param $suffix String: to remove if present
* @param $sessionId Bool
*/
function wfSetupSession( $sessionId = false ) {
- global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
+ global $wgSessionsInMemcached, $wgSessionsInObjectCache, $wgCookiePath, $wgCookieDomain,
$wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler;
- if( $wgSessionsInMemcached ) {
- if ( !defined( 'MW_COMPILED' ) ) {
- global $IP;
- require_once( "$IP/includes/cache/MemcachedSessions.php" );
- }
- session_set_save_handler( 'memsess_open', 'memsess_close', 'memsess_read',
- 'memsess_write', 'memsess_destroy', 'memsess_gc' );
-
- // It's necessary to register a shutdown function to call session_write_close(),
- // because by the time the request shutdown function for the session module is
- // called, $wgMemc has already been destroyed. Shutdown functions registered
- // this way are called before object destruction.
- register_shutdown_function( 'memsess_write_close' );
+ if( $wgSessionsInObjectCache || $wgSessionsInMemcached ) {
+ ObjectCacheSessionHandler::install();
} elseif( $wgSessionHandler && $wgSessionHandler != ini_get( 'session.save_handler' ) ) {
# Only set this if $wgSessionHandler isn't null and session.save_handler
# hasn't already been set to the desired value (that causes errors)
/**
* Get the path to a specified script file, respecting file
* extensions; this is a wrapper around $wgScriptExtension etc.
+ * except for 'index' and 'load' which use $wgScript/$wgLoadScript
*
* @param $script String: script filename, sans extension
* @return String
*/
function wfScript( $script = 'index' ) {
- global $wgScriptPath, $wgScriptExtension;
- return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+ global $wgScriptPath, $wgScriptExtension, $wgScript, $wgLoadScript;
+ if ( $script === 'index' ) {
+ return $wgScript;
+ } else if ( $script === 'load' ) {
+ return $wgLoadScript;
+ } else {
+ return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+ }
}
/**
/**
* Replace all invalid characters with -
+ * Additional characters can be defined in $wgIllegalFileChars (see bug 20489)
+ * By default, $wgIllegalFileChars = ':'
*
* @param $name Mixed: filename to process
* @return String
*/
function wfStripIllegalFilenameChars( $name ) {
global $wgIllegalFileChars;
+ $illegalFileChars = $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '';
$name = wfBaseName( $name );
$name = preg_replace(
- "/[^" . Title::legalChars() . "]" .
- ( $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '' ) .
- "/",
+ "/[^" . Title::legalChars() . "]" . $illegalFileChars . "/",
'-',
$name
);
$badImages = $badImageCache;
} else { // cache miss
if ( $blacklist === null ) {
- $blacklist = wfMsgForContentNoTrans( 'bad_image_list' ); // site list
+ $blacklist = wfMessage( 'bad_image_list' )->inContentLanguage()->plain(); // site list
}
# Build the list now
$badImages = array();