function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
return Fallback::mb_strpos( $haystack, $needle, $offset, $encoding );
}
-
+
}
if( !function_exists( 'mb_strrpos' ) ) {
* "days=7&limit=100". Options in the first array override options in the second.
* Options set to "" will not be output.
*
- * @param $array1 Array( String|Array )
- * @param $array2 Array( String|Array )
+ * @param $array1 Array ( String|Array )
+ * @param $array2 Array ( String|Array )
+ * @param $prefix String
* @return String
*/
-function wfArrayToCGI( $array1, $array2 = null ) {
+function wfArrayToCGI( $array1, $array2 = null, $prefix = '' ) {
if ( !is_null( $array2 ) ) {
$array1 = $array1 + $array2;
}
if ( $cgi != '' ) {
$cgi .= '&';
}
+ if ( $prefix !== '' ) {
+ $key = $prefix . "[$key]";
+ }
if ( is_array( $value ) ) {
$firstTime = true;
- foreach ( $value as $v ) {
- $cgi .= ( $firstTime ? '' : '&') .
- urlencode( $key . '[]' ) . '=' .
- urlencode( $v );
+ foreach ( $value as $k => $v ) {
+ $cgi .= $firstTime ? '' : '&';
+ if ( is_array( $v ) ) {
+ $cgi .= wfArrayToCGI( $v, null, $key . "[$k]" );
+ } else {
+ $cgi .= urlencode( $key . "[$k]" ) . '=' . urlencode( $v );
+ }
$firstTime = false;
}
} else {
if ( is_object( $value ) ) {
$value = $value->__toString();
}
- $cgi .= urlencode( $key ) . '=' .
- urlencode( $value );
+ $cgi .= urlencode( $key ) . '=' . urlencode( $value );
}
}
}
* @return array Array version of input
*/
function wfCgiToArray( $query ) {
- if( isset( $query[0] ) && $query[0] == '?' ) {
+ if ( isset( $query[0] ) && $query[0] == '?' ) {
$query = substr( $query, 1 );
}
$bits = explode( '&', $query );
$ret = array();
- foreach( $bits as $bit ) {
- if( $bit === '' ) {
+ foreach ( $bits as $bit ) {
+ if ( $bit === '' ) {
continue;
}
list( $key, $value ) = explode( '=', $bit );
$key = urldecode( $key );
$value = urldecode( $value );
- $ret[$key] = $value;
+ if ( strpos( $key, '[' ) !== false ) {
+ $keys = array_reverse( explode( '[', $key ) );
+ $key = array_pop( $keys );
+ $temp = $value;
+ foreach ( $keys as $k ) {
+ $k = substr( $k, 0, -1 );
+ $temp = array( $k => $temp );
+ }
+ if ( isset( $ret[$key] ) ) {
+ $ret[$key] = array_merge( $ret[$key], $temp );
+ } else {
+ $ret[$key] = $temp;
+ }
+ } else {
+ $ret[$key] = $value;
+ }
}
return $ret;
}
/* 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'];
}
# Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
if ( ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' )
- || (
- isset( $_SERVER['SCRIPT_NAME'] )
- && substr( $_SERVER['SCRIPT_NAME'], -8 ) == 'load.php'
- ) )
+ || (
+ isset( $_SERVER['SCRIPT_NAME'] )
+ && substr( $_SERVER['SCRIPT_NAME'], -8 ) == 'load.php'
+ ) )
{
$cache = true;
} else {
/**
* Get microsecond timestamps for debug logs
- *
+ *
* @return string
*/
function wfDebugTimer() {
function wfMsg( $key ) {
$args = func_get_args();
array_shift( $args );
- return wfMsgReal( $key, $args, true );
+ return wfMsgReal( $key, $args );
}
/**
* @param $transform Boolean: whether to parse magic words, etc.
* @return string
*/
-function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
+function wfMsgGetKey( $key, $useDB = true, $langCode = false, $transform = true ) {
wfRunHooks( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) );
$cache = MessageCache::singleton();
function wfMsgHtml( $key ) {
$args = func_get_args();
array_shift( $args );
- return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key, true ) ), $args );
+ return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key ) ), $args );
}
/**
$args = func_get_args();
array_shift( $args );
return wfMsgReplaceArgs(
- MessageCache::singleton()->parse( wfMsgGetKey( $key, true ), null, /* can't be set to false */ true )->getText(),
+ MessageCache::singleton()->parse( wfMsgGetKey( $key ), null, /* can't be set to false */ true )->getText(),
$args );
}
* Fetch server name for use in error reporting etc.
* Use real server name if available, so we know which machine
* in a server farm generated the current page.
- *
+ *
* @return string
*/
function wfHostname() {
function in_string( $needle, $str, $insensitive = false ) {
$func = 'strpos';
if( $insensitive ) $func = 'stripos';
-
+
return $func( $str, $needle ) !== false;
}
function wfSpecialList( $page, $details ) {
- global $wgContLang;
- $details = $details ? ' ' . $wgContLang->getDirMark() . "($details)" : '';
+ $details = $details ? ' ' . wfUILang()->getDirMark() . "($details)" : '';
return $page . $details;
}
global $IP;
require_once( "$IP/includes/cache/MemcachedSessions.php" );
}
- session_set_save_handler( 'memsess_open', 'memsess_close', 'memsess_read',
+ 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
+ // 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' );
* master position. Use this when updating very large numbers of rows, as
* in maintenance scripts, to avoid causing too much lag. Of course, this is
* a no-op if there are no slaves.
- *
+ *
* @param $maxLag Integer (deprecated)
* @param $wiki mixed Wiki identifier accepted by wfGetLB
* @return null
function wfOut( $s ) {
wfDeprecated( __METHOD__ );
global $wgCommandLineMode;
- if ( $wgCommandLineMode && !defined( 'MEDIAWIKI_INSTALL' ) ) {
+ if ( $wgCommandLineMode ) {
echo $s;
} else {
echo htmlspecialchars( $s );
$codeBCP = array();
foreach ( $codeSegment as $segNo => $seg ) {
if ( count( $codeSegment ) > 0 ) {
- // when previous segment is x, it is a private segment and should be lc
+ // when previous segment is x, it is a private segment and should be lc
if( $segNo > 0 && strtolower( $codeSegment[($segNo - 1)] ) == 'x') {
$codeBCP[$segNo] = strtolower( $seg );
// ISO 3166 country code
function wfRunHooks( $event, $args = array() ) {
return Hooks::run( $event, $args );
}
+
+/**
+ * Unserialize a string to a PHP value without throwing E_NOTICE. Simply a
+ * wrapper around unserialize()
+ *
+ * @param $data string The serialized string
+ * @return mixed
+ */
+function wfUnserialize( $data ) {
+ wfSuppressWarnings();
+ $result = unserialize( $data );
+ wfRestoreWarnings();
+ return $result;
+}