Fix mediawiki.ui.checkbox loading in mobile
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index fe12a07..4c2b772 100644 (file)
@@ -176,21 +176,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 +194,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.
@@ -246,7 +210,7 @@ function wfArrayMerge( $array1 /*...*/ ) {
  *             array( 'y' )
  *     )
  *
- * @param array [$array1,...]
+ * @param array $array1,...
  * @return array
  */
 function wfMergeErrorArrays( /*...*/ ) {
@@ -1179,7 +1143,7 @@ function wfDeprecated( $function, $version = false, $component = false, $callerO
  * Send a warning either to the debug log or in a PHP error depending on
  * $wgDevelopmentWarnings. To log warnings in production, use wfLogWarning() instead.
  *
- * @param string $msg message to send
+ * @param string $msg Message to send
  * @param int $callerOffset Number of items to go back in the backtrace to
  *        find the correct caller (1 = function calling wfWarn, ...)
  * @param int $level PHP error level; defaults to E_USER_NOTICE;
@@ -1438,7 +1402,7 @@ function wfGetLangObj( $langcode = false ) {
  * This function replaces all old wfMsg* functions.
  *
  * @param string $key Message key
- * @param mixed [$params,...] Normal message parameters
+ * @param mixed $params,... Normal message parameters
  * @return Message
  *
  * @since 1.17
@@ -1459,7 +1423,7 @@ function wfMessage( $key /*...*/ ) {
  * for the first message which is non-empty. If all messages are empty then an
  * instance of the first message key is returned.
  *
- * @param string|string[] [$keys,...] Message keys
+ * @param string|string[] $keys,... Message keys
  * @return Message
  *
  * @since 1.18
@@ -1479,7 +1443,7 @@ function wfMessageFallback( /*...*/ ) {
  *
  * @deprecated since 1.18
  *
- * @param string $key lookup key for the message, usually
+ * @param string $key Lookup key for the message, usually
  *    defined in languages/Language.php
  *
  * Parameters to the message, which can be used to insert variable text into
@@ -1664,7 +1628,7 @@ function wfMsgReplaceArgs( $message, $args ) {
  * @deprecated since 1.18
  *
  * @param string $key
- * @param string [$args,...] Parameters
+ * @param string $args,... Parameters
  * @return string
  */
 function wfMsgHtml( $key ) {
@@ -1685,7 +1649,7 @@ function wfMsgHtml( $key ) {
  * @deprecated since 1.18
  *
  * @param string $key
- * @param string [$args,...] Parameters
+ * @param string $args,... Parameters
  * @return string
  */
 function wfMsgWikiHtml( $key ) {
@@ -1807,19 +1771,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
@@ -1873,7 +1824,7 @@ function wfReportTime() {
        $responseTime = round( ( microtime( true ) - $wgRequestTime ) * 1000 );
        $reportVars = array( 'wgBackendResponseTime' => $responseTime );
        if ( $wgShowHostnames ) {
-               $reportVars[ 'wgHostname' ] = wfHostname();
+               $reportVars['wgHostname'] = wfHostname();
        }
        return Skin::makeVariablesScript( $reportVars );
 }
@@ -2116,16 +2067,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
@@ -2276,7 +2217,7 @@ function wfClearOutputBuffers() {
  * factors
  *
  * @param string $accept
- * @param string $def default
+ * @param string $def Default
  * @return float[] Associative array of string => float pairs
  */
 function wfAcceptToPrefs( $accept, $def = '*/*' ) {
@@ -2701,7 +2642,7 @@ function wfIniGetBool( $setting ) {
  * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
  * earlier distro releases of PHP)
  *
- * @param string [$args,...]
+ * @param string $args,...
  * @return string
  */
 function wfEscapeShellArg( /*...*/ ) {
@@ -2785,7 +2726,9 @@ function wfShellExecDisabled() {
  * Execute a shell command, with time and memory limits mirrored from the PHP
  * configuration if supported.
  *
- * @param string $cmd Command line, properly escaped for shell.
+ * @param string|string[] $cmd If string, a properly shell-escaped command line,
+ *   or an array of unescaped arguments, in which case each value will be escaped
+ *   Example:   [ 'convert', '-font', 'font name' ] would produce "'convert' '-font' 'font name'"
  * @param null|mixed &$retval Optional, will receive the program's exit code.
  *   (non-zero is usually failure). If there is an error from
  *   read, select, or proc_open(), this will be set to -1.
@@ -2834,6 +2777,15 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                        $envcmd .= "$k=" . escapeshellarg( $v ) . ' ';
                }
        }
+       if ( is_array( $cmd ) ) {
+               // Command line may be given as an array, escape each value and glue them together with a space
+               $cmdVals = array();
+               foreach ( $cmd as $val ) {
+                       $cmdVals[] = wfEscapeShellArg( $val );
+               }
+               $cmd = implode( ' ', $cmdVals );
+       }
+
        $cmd = $envcmd . $cmd;
 
        $useLogPipe = false;
@@ -3020,7 +2972,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
  * @param string $cmd Command line, properly escaped for shell.
  * @param null|mixed &$retval Optional, will receive the program's exit code.
  *   (non-zero is usually failure)
- * @param array $environ optional environment variables which should be
+ * @param array $environ Optional environment variables which should be
  *   added to the executed command environment.
  * @param array $limits Optional array with limits(filesize, memory, time, walltime)
  *   this overwrites the global wgMaxShell* limits.
@@ -3468,7 +3420,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
 /**
  * Check if there is sufficient entropy in php's built-in session generation
  *
- * @return bool true = there is sufficient entropy
+ * @return bool True = there is sufficient entropy
  */
 function wfCheckEntropy() {
        return (
@@ -3574,7 +3526,7 @@ function wfGetPrecompiledData( $name ) {
 /**
  * Get a cache key
  *
- * @param string [$args,...]
+ * @param string $args,...
  * @return string
  */
 function wfMemcKey( /*...*/ ) {
@@ -3591,7 +3543,7 @@ function wfMemcKey( /*...*/ ) {
  *
  * @param string $db
  * @param string $prefix
- * @param string [$args,...]
+ * @param string $args,...
  * @return string
  */
 function wfForeignMemcKey( $db, $prefix /*...*/ ) {
@@ -3663,7 +3615,7 @@ function &wfGetDB( $db, $groups = array(), $wiki = false ) {
 /**
  * Get a load balancer object.
  *
- * @param string|bool $wiki wiki ID, or false for the current wiki
+ * @param string|bool $wiki Wiki ID, or false for the current wiki
  * @return LoadBalancer
  */
 function wfGetLB( $wiki = false ) {
@@ -3683,7 +3635,7 @@ function &wfGetLBFactory() {
  * Find a file.
  * Shortcut for RepoGroup::singleton()->findFile()
  *
- * @param string $title or Title object
+ * @param string $title String or Title object
  * @param array $options Associative array of options:
  *     time:           requested time for an archived image, or false for the
  *                     current version. An image object will be returned which was
@@ -3750,7 +3702,7 @@ function wfScript( $script = 'index' ) {
 /**
  * Get the script URL.
  *
- * @return string script URL
+ * @return string Script URL
  */
 function wfGetScriptUrl() {
        if ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
@@ -3800,6 +3752,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
@@ -3815,19 +3768,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;
 }
 
 /**
@@ -4031,7 +3986,7 @@ function wfRunHooks( $event, array $args = array(), $deprecatedVersion = null )
  * Also be careful when using this function to read unsigned 32 bit integer
  * because php might make it negative.
  *
- * @throws MWException if $data not long enough, or if unpack fails
+ * @throws MWException If $data not long enough, or if unpack fails
  * @return array Associative array of the extracted data
  */
 function wfUnpack( $format, $data, $length = false ) {