wfBaseConvert(): Work around PHP Bug #50175
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index b40b007..cfe9a87 100644 (file)
@@ -38,6 +38,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 if ( !function_exists( 'mb_substr' ) ) {
        /**
         * @codeCoverageIgnore
+        * @see Fallback::mb_substr
         * @return string
         */
        function mb_substr( $str, $start, $count = 'end' ) {
@@ -46,6 +47,7 @@ if ( !function_exists( 'mb_substr' ) ) {
 
        /**
         * @codeCoverageIgnore
+        * @see Fallback::mb_substr_split_unicode
         * @return int
         */
        function mb_substr_split_unicode( $str, $splitPos ) {
@@ -56,6 +58,7 @@ if ( !function_exists( 'mb_substr' ) ) {
 if ( !function_exists( 'mb_strlen' ) ) {
        /**
         * @codeCoverageIgnore
+        * @see Fallback::mb_strlen
         * @return int
         */
        function mb_strlen( $str, $enc = '' ) {
@@ -66,6 +69,7 @@ if ( !function_exists( 'mb_strlen' ) ) {
 if ( !function_exists( 'mb_strpos' ) ) {
        /**
         * @codeCoverageIgnore
+        * @see Fallback::mb_strpos
         * @return int
         */
        function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
@@ -76,6 +80,7 @@ if ( !function_exists( 'mb_strpos' ) ) {
 if ( !function_exists( 'mb_strrpos' ) ) {
        /**
         * @codeCoverageIgnore
+        * @see Fallback::mb_strrpos
         * @return int
         */
        function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
@@ -88,6 +93,7 @@ if ( !function_exists( 'mb_strrpos' ) ) {
 if ( !function_exists( 'gzdecode' ) ) {
        /**
         * @codeCoverageIgnore
+        * @param string $data
         * @return string
         */
        function gzdecode( $data ) {
@@ -176,21 +182,6 @@ function wfArrayDiff2_cmp( $a, $b ) {
        }
 }
 
-/**
- * Array lookup
- * Returns an array where the values in array $b are replaced by the
- * values in array $a with the corresponding keys
- *
- * @deprecated since 1.22; use array_intersect_key()
- * @param array $a
- * @param array $b
- * @return array
- */
-function wfArrayLookup( $a, $b ) {
-       wfDeprecated( __FUNCTION__, '1.22' );
-       return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
-}
-
 /**
  * Appends to second array if $value differs from that in $default
  *
@@ -209,27 +200,6 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
        }
 }
 
-/**
- * Backwards array plus for people who haven't bothered to read the PHP manual
- * XXX: will not darn your socks for you.
- *
- * @deprecated since 1.22; use array_replace()
- *
- * @param array $array1 Initial array to merge.
- * @param array $array2,... Variable list of arrays to merge.
- * @return array
- */
-function wfArrayMerge( $array1 /*...*/ ) {
-       wfDeprecated( __FUNCTION__, '1.22' );
-       $args = func_get_args();
-       $args = array_reverse( $args, true );
-       $out = array();
-       foreach ( $args as $arg ) {
-               $out += $arg;
-       }
-       return $out;
-}
-
 /**
  * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal
  * e.g.
@@ -1807,19 +1777,6 @@ function wfEmptyMsg( $key ) {
        return MessageCache::singleton()->get( $key, /*useDB*/true, /*content*/false ) === false;
 }
 
-/**
- * Throw a debugging exception. This function previously once exited the process,
- * but now throws an exception instead, with similar results.
- *
- * @deprecated since 1.22; just throw an MWException yourself
- * @param string $msg Message shown when dying.
- * @throws MWException
- */
-function wfDebugDieBacktrace( $msg = '' ) {
-       wfDeprecated( __FUNCTION__, '1.22' );
-       throw new MWException( $msg );
-}
-
 /**
  * Fetch server name for use in error reporting etc.
  * Use real server name if available, so we know which machine
@@ -2116,16 +2073,6 @@ function wfEscapeWikiText( $text ) {
        return $text;
 }
 
-/**
- * Get the current unix timestamp with microseconds.  Useful for profiling
- * @deprecated since 1.22; call microtime() directly
- * @return float
- */
-function wfTime() {
-       wfDeprecated( __FUNCTION__, '1.22' );
-       return microtime( true );
-}
-
 /**
  * Sets dest to source and returns the original value of dest
  * If source is NULL, it just returns the value, it doesn't set the variable
@@ -3419,7 +3366,10 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
        );
 
        if ( extension_loaded( 'gmp' ) && ( $engine == 'auto' || $engine == 'gmp' ) ) {
-               $result = gmp_strval( gmp_init( $input, $sourceBase ), $destBase );
+               // Removing leading zeros works around broken base detection code in
+               // some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
+               // <https://bugs.php.net/bug.php?id=55398>).
+               $result = gmp_strval( gmp_init( ltrim( $input, '0' ), $sourceBase ), $destBase );
        } elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
                $decimal = '0';
                foreach ( str_split( strtolower( $input ) ) as $char ) {
@@ -3811,6 +3761,7 @@ function wfGetNull() {
  * @param float|null $ifWritesSince Only wait if writes were done since this UNIX timestamp
  * @param string|bool $wiki Wiki identifier accepted by wfGetLB
  * @param string|bool $cluster Cluster name accepted by LBFactory. Default: false.
+ * @return bool Success (able to connect and no timeouts reached)
  */
 function wfWaitForSlaves( $ifWritesSince = false, $wiki = false, $cluster = false ) {
        // B/C: first argument used to be "max seconds of lag"; ignore such values
@@ -3826,19 +3777,21 @@ function wfWaitForSlaves( $ifWritesSince = false, $wiki = false, $cluster = fals
        // Prevents permission error when getting master position
        if ( $lb->getServerCount() > 1 ) {
                if ( $ifWritesSince && !$lb->hasMasterConnection() ) {
-                       return; // assume no writes done
+                       return true; // assume no writes done
                }
                $dbw = $lb->getConnection( DB_MASTER, array(), $wiki );
                if ( $ifWritesSince && $dbw->lastDoneWrites() < $ifWritesSince ) {
-                       return; // no writes since the last wait
+                       return true; // no writes since the last wait
                }
                $pos = $dbw->getMasterPos();
                // The DBMS may not support getMasterPos() or the whole
                // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
                if ( $pos !== false ) {
-                       $lb->waitForAll( $pos );
+                       return $lb->waitForAll( $pos, PHP_SAPI === 'cli' ? 86400 : null );
                }
        }
+
+       return true;
 }
 
 /**