Work around HHVM bug with stdin/stdout in proc_open()
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index ff91ba0..1eb5c3e 100644 (file)
@@ -495,7 +495,7 @@ function wfAppendQuery( $url, $query ) {
  *    no valid URL can be constructed
  */
 function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
-       global $wgServer, $wgCanonicalServer, $wgInternalServer;
+       global $wgServer, $wgCanonicalServer, $wgInternalServer, $wgRequest;
        $serverUrl = $wgServer;
        if ( $defaultProto === PROTO_CANONICAL ) {
                $serverUrl = $wgCanonicalServer;
@@ -505,7 +505,7 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
                $serverUrl = $wgInternalServer;
        }
        if ( $defaultProto === PROTO_CURRENT ) {
-               $defaultProto = WebRequest::detectProtocol() . '://';
+               $defaultProto = $wgRequest->getProtocol() . '://';
        }
 
        // Analyze $serverUrl to obtain its protocol
@@ -1008,7 +1008,12 @@ function wfDebugMem( $exact = false ) {
 
 /**
  * Send a line to a supplementary debug log file, if configured, or main debug log if not.
- * $wgDebugLogGroups[$logGroup] should be set to a filename to send to a separate log.
+ * To configure a supplementary log file, set $wgDebugLogGroups[$logGroup] to a string
+ * filename or an associative array mapping 'destination' to the desired filename. The
+ * associative array may also contain a 'sample' key with an integer value, specifying
+ * a sampling factor.
+ *
+ * @since 1.23 support for sampling log messages via $wgDebugLogGroups.
  *
  * @param $logGroup String
  * @param $text String
@@ -1018,14 +1023,28 @@ function wfDebugMem( $exact = false ) {
 function wfDebugLog( $logGroup, $text, $public = true ) {
        global $wgDebugLogGroups;
        $text = trim( $text ) . "\n";
-       if ( isset( $wgDebugLogGroups[$logGroup] ) ) {
-               $time = wfTimestamp( TS_DB );
-               $wiki = wfWikiID();
-               $host = wfHostname();
-               wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
-       } elseif ( $public === true ) {
-               wfDebug( "[$logGroup] $text", false );
+
+       if ( !isset( $wgDebugLogGroups[$logGroup] ) ) {
+               if ( $public === true ) {
+                       wfDebug( "[$logGroup] $text", false );
+               }
+               return;
+       }
+
+       $logConfig = $wgDebugLogGroups[$logGroup];
+       if ( is_array( $logConfig ) ) {
+               if ( isset( $logConfig['sample'] ) && mt_rand( 1, $logConfig['sample'] ) !== 1 ) {
+                       return;
+               }
+               $destination = $logConfig['destination'];
+       } else {
+               $destination = strval( $logConfig );
        }
+
+       $time = wfTimestamp( TS_DB );
+       $wiki = wfWikiID();
+       $host = wfHostname();
+       wfErrorLog( "$time $host $wiki: $text", $destination );
 }
 
 /**
@@ -2836,6 +2855,15 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
        if ( $useLogPipe ) {
                $desc[3] = array( 'pipe', 'w' );
        }
+
+       # TODO/FIXME: This is a bad hack to workaround an HHVM bug that prevents
+       # proc_open() from opening stdin/stdout, so use /dev/null *for now*
+       # See bug 56597 / https://github.com/facebook/hhvm/issues/1247 for more info
+       if ( wfIsHHVM() ) {
+               $desc[0] = array( 'file', '/dev/null', 'r' );
+               $desc[2] = array( 'file', '/dev/null', 'w' );
+       }
+
        $pipes = null;
        $proc = proc_open( $cmd, $desc, $pipes );
        if ( !$proc ) {
@@ -3305,18 +3333,6 @@ function wfRelativePath( $path, $from ) {
        return implode( DIRECTORY_SEPARATOR, $pieces );
 }
 
-/**
- * Do any deferred updates and clear the list
- *
- * @deprecated since 1.19
- * @see DeferredUpdates::doUpdate()
- * @param $commit string
- */
-function wfDoUpdates( $commit = '' ) {
-       wfDeprecated( __METHOD__, '1.19' );
-       DeferredUpdates::doUpdates( $commit );
-}
-
 /**
  * Convert an arbitrarily-long digit string from one numeric base
  * to another, optionally zero-padding to a minimum column width.
@@ -3423,19 +3439,6 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
        return str_pad( $result, $pad, '0', STR_PAD_LEFT );
 }
 
-/**
- * Create an object with a given name and an array of construct parameters
- *
- * @param $name String
- * @param array $p parameters
- * @return object
- * @deprecated since 1.18, warnings in 1.18, removal in 1.20
- */
-function wfCreateObject( $name, $p ) {
-       wfDeprecated( __FUNCTION__, '1.18' );
-       return MWFunction::newObj( $name, $p );
-}
-
 /**
  * @return bool
  */
@@ -3825,21 +3828,6 @@ function wfWaitForSlaves( $maxLag = false, $wiki = false, $cluster = false ) {
        }
 }
 
-/**
- * Used to be used for outputting text in the installer/updater
- * @deprecated since 1.18, warnings in 1.18, remove in 1.20
- */
-function wfOut( $s ) {
-       wfDeprecated( __FUNCTION__, '1.18' );
-       global $wgCommandLineMode;
-       if ( $wgCommandLineMode ) {
-               echo $s;
-       } else {
-               echo htmlspecialchars( $s );
-       }
-       flush();
-}
-
 /**
  * Count down from $n to zero on the terminal, with a one-second pause
  * between showing each number. For use in command-line scripts.