We still want details in page history
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 25327e6..e6aca47 100644 (file)
@@ -231,6 +231,20 @@ function wfDebug( $text, $logonly = false ) {
        }
 }
 
+/**
+ * Send a line giving PHP memory usage.
+ * @param $exact Bool : print exact values instead of kilobytes (default: false)
+ */
+function wfDebugMem( $exact = false ) {
+       $mem = memory_get_usage();
+       if( !$exact ) {
+               $mem = floor( $mem / 1024 ) . ' kilobytes';
+       } else {
+               $mem .= ' bytes';
+       }
+       wfDebug( "Memory usage: $mem\n" );
+}
+
 /**
  * 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.
@@ -241,12 +255,17 @@ function wfDebug( $text, $logonly = false ) {
  *                     log file is specified, (default true)
  */
 function wfDebugLog( $logGroup, $text, $public = true ) {
-       global $wgDebugLogGroups;
+       global $wgDebugLogGroups, $wgShowHostnames;
        if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n";
        if( isset( $wgDebugLogGroups[$logGroup] ) ) {
                $time = wfTimestamp( TS_DB );
                $wiki = wfWikiID();
-               wfErrorLog( "$time $wiki: $text", $wgDebugLogGroups[$logGroup] );
+               if ( $wgShowHostnames ) {
+                       $host = wfHostname();
+               } else {
+                       $host = '';
+               }
+               wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
        } else if ( $public === true ) {
                wfDebug( $text, true );
        }
@@ -753,18 +772,22 @@ function wfDebugDieBacktrace( $msg = '' ) {
  * @return string
  */
 function wfHostname() {
-       if ( function_exists( 'posix_uname' ) ) {
-               // This function not present on Windows
-               $uname = @posix_uname();
-       } else {
-               $uname = false;
-       }
-       if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
-               return $uname['nodename'];
-       } else {
-               # This may be a virtual server.
-               return $_SERVER['SERVER_NAME'];
+       static $host;
+       if ( is_null( $host ) ) {
+               if ( function_exists( 'posix_uname' ) ) {
+                       // This function not present on Windows
+                       $uname = @posix_uname();
+               } else {
+                       $uname = false;
+               }
+               if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
+                       $host = $uname['nodename'];
+               } else {
+                       # This may be a virtual server.
+                       $host = $_SERVER['SERVER_NAME'];
+               }
        }
+       return $host;
 }
 
        /**
@@ -1391,6 +1414,7 @@ function wfResetOutputBuffers( $resetGzipEncoding=true ) {
                                // Reset the 'Content-Encoding' field set by this handler
                                // so we can start fresh.
                                header( 'Content-Encoding:' );
+                               break;
                        }
                }
        }
@@ -2098,6 +2122,10 @@ function wfShellExec( $cmd, &$retval=null ) {
        passthru( $cmd, $retval );
        $output = ob_get_contents();
        ob_end_clean();
+
+       if ( $retval == 127 ) {
+               wfDebugLog( 'exec', "Possibly missing executable file: $cmd\n" );
+       }
        return $output;
 
 }
@@ -2242,28 +2270,6 @@ function wfArrayMerge( $array1/* ... */ ) {
        return $out;
 }
 
-/**
- * Merge multiple arrays together.
- * On encountering duplicate keys, merge the two, but ONLY if they're arrays.
- * PHP's array_merge_recursive() merges ANY duplicate values into arrays,
- * which is not fun
- */
-function wfArrayDeepMerge( $array1/* ... */ ) {
-       $out = $array1;
-       for( $i=1; $i< func_num_args(); $i++ ) {
-               foreach( func_get_arg( $i ) as $key => $value ) {
-                       if ( isset($out[$key]) && is_array($out[$key]) && is_array($value) ) {
-                               $out[$key] = wfArrayDeepMerge( $out[$key], $value );
-                       } elseif ( !isset($out[$key] || !$out[$key] ) {
-                               // Values that evaluate to true given precedence, for the primary purpose of merging permissions arrays.
-                               $out[$key] = $value;
-                       }
-               }
-       }
-       
-       return $out;
-}
-
 /**
  * Make a URL index, appropriate for the el_index field of externallinks.
  */