put in r110285 again now that 1.19 branched
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index a49d231..ab93508 100644 (file)
@@ -911,20 +911,15 @@ function wfIsDebugRawPage() {
  * @return string
  */
 function wfDebugTimer() {
-       global $wgDebugTimestamps;
+       global $wgDebugTimestamps, $wgRequestTime;
+
        if ( !$wgDebugTimestamps ) {
                return '';
        }
-       static $start = null;
 
-       if ( $start === null ) {
-               $start = microtime( true );
-               $prefix = "\n$start";
-       } else {
-               $prefix = sprintf( "%6.4f", microtime( true ) - $start );
-       }
-       $mem = sprintf( "%5.1fM", ( memory_get_usage( true ) / (1024*1024) ) );
-       return "$prefix $mem  " ;
+       $prefix = sprintf( "%6.4f", microtime( true ) - $wgRequestTime );
+       $mem = sprintf( "%5.1fM", ( memory_get_usage( true ) / ( 1024 * 1024 ) ) );
+       return "$prefix $mem  ";
 }
 
 /**
@@ -952,16 +947,12 @@ function wfDebugMem( $exact = false ) {
  *                     log file is specified, (default true)
  */
 function wfDebugLog( $logGroup, $text, $public = true ) {
-       global $wgDebugLogGroups, $wgShowHostnames;
+       global $wgDebugLogGroups;
        $text = trim( $text ) . "\n";
        if( isset( $wgDebugLogGroups[$logGroup] ) ) {
                $time = wfTimestamp( TS_DB );
                $wiki = wfWikiID();
-               if ( $wgShowHostnames ) {
-                       $host = wfHostname();
-               } else {
-                       $host = '';
-               }
+               $host = wfHostname();
                if ( wfRunHooks( 'Debug', array( $text, $logGroup ) ) ) {
                        wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
                }
@@ -976,14 +967,97 @@ function wfDebugLog( $logGroup, $text, $public = true ) {
  * @param $text String: database error message.
  */
 function wfLogDBError( $text ) {
-       global $wgDBerrorLog, $wgDBname;
+       global $wgDBerrorLog;
        if ( $wgDBerrorLog ) {
-               $host = trim(`hostname`);
-               $text = date( 'D M j G:i:s T Y' ) . "\t$host\t$wgDBname\t$text";
+               $host = wfHostname();
+               $wiki = wfWikiID();
+               $text = date( 'D M j G:i:s T Y' ) . "\t$host\t$wiki\t$text";
                wfErrorLog( $text, $wgDBerrorLog );
        }
 }
 
+/**
+ * Throws a warning that $function is deprecated
+ *
+ * @param $function String
+ * @param $version String|false: Added in 1.19.
+ * @param $component String|false: Added in 1.19.
+ * 
+ * @return null
+ */
+function wfDeprecated( $function, $version = false, $component = false ) {
+       static $functionsWarned = array();
+
+       MWDebug::deprecated( $function, $version, $component );
+
+       if ( !isset( $functionsWarned[$function] ) ) {
+               $functionsWarned[$function] = true;
+               
+               if ( $version ) {
+                       global $wgDeprecationReleaseLimit;
+                       
+                       if ( $wgDeprecationReleaseLimit && $component === false ) {
+                               # Strip -* off the end of $version so that branches can use the
+                               # format #.##-branchname to avoid issues if the branch is merged into
+                               # a version of MediaWiki later than what it was branched from
+                               $comparableVersion = preg_replace( '/-.*$/', '', $version );
+                               
+                               # If the comparableVersion is larger than our release limit then
+                               # skip the warning message for the deprecation
+                               if ( version_compare( $wgDeprecationReleaseLimit, $comparableVersion, '<' ) ) {
+                                       return;
+                               }
+                       }
+                       
+                       $component = $component === false ? 'MediaWiki' : $component;
+                       wfWarn( "Use of $function was deprecated in $component $version.", 2 );
+               } else {
+                       wfWarn( "Use of $function is deprecated.", 2 );
+               }
+       }
+}
+
+/**
+ * Send a warning either to the debug log or in a PHP error depending on
+ * $wgDevelopmentWarnings
+ *
+ * @param $msg String: message to send
+ * @param $callerOffset Integer: number of items to go back in the backtrace to
+ *        find the correct caller (1 = function calling wfWarn, ...)
+ * @param $level Integer: PHP error level; only used when $wgDevelopmentWarnings
+ *        is true
+ */
+function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
+       global $wgDevelopmentWarnings;
+
+       MWDebug::warning( $msg, $callerOffset + 2 );
+
+       $callers = wfDebugBacktrace();
+       if ( isset( $callers[$callerOffset + 1] ) ) {
+               $callerfunc = $callers[$callerOffset + 1];
+               $callerfile = $callers[$callerOffset];
+               if ( isset( $callerfile['file'] ) && isset( $callerfile['line'] ) ) {
+                       $file = $callerfile['file'] . ' at line ' . $callerfile['line'];
+               } else {
+                       $file = '(internal function)';
+               }
+               $func = '';
+               if ( isset( $callerfunc['class'] ) ) {
+                       $func .= $callerfunc['class'] . '::';
+               }
+               if ( isset( $callerfunc['function'] ) ) {
+                       $func .= $callerfunc['function'];
+               }
+               $msg .= " [Called from $func in $file]";
+       }
+
+       if ( $wgDevelopmentWarnings ) {
+               trigger_error( $msg, $level );
+       } else {
+               wfDebug( "$msg\n" );
+       }
+}
+
 /**
  * Log to a file without getting "file size exceeded" signals.
  *
@@ -1064,8 +1138,7 @@ function wfLogProfilingData() {
 
        // Get total page request time and only show pages that longer than
        // $wgProfileLimit time (default is 0)
-       $now = wfTime();
-       $elapsed = $now - $wgRequestTime;
+       $elapsed = microtime( true ) - $wgRequestTime;
        if ( $elapsed <= $wgProfileLimit ) {
                return;
        }
@@ -1482,13 +1555,18 @@ function wfMsgExt( $key, $options ) {
        }
 
        $messageCache = MessageCache::singleton();
-       if( in_array( 'parse', $options, true ) ) {
-               $string = $messageCache->parse( $string, null, true, !$forContent, $langCodeObj )->getText();
-       } elseif ( in_array( 'parseinline', $options, true ) ) {
-               $string = $messageCache->parse( $string, null, true, !$forContent, $langCodeObj )->getText();
-               $m = array();
-               if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
-                       $string = $m[1];
+       $parseInline = in_array( 'parseinline', $options, true );
+       if( in_array( 'parse', $options, true ) || $parseInline ) {
+               $string = $messageCache->parse( $string, null, true, !$forContent, $langCodeObj );
+               if ( $string instanceof ParserOutput ) {
+                       $string = $string->getText();
+               }
+
+               if ( $parseInline ) {
+                       $m = array();
+                       if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
+                               $string = $m[1];
+                       }
                }
        } elseif ( in_array( 'parsemag', $options, true ) ) {
                $string = $messageCache->transform( $string,
@@ -1568,8 +1646,7 @@ function wfHostname() {
 function wfReportTime() {
        global $wgRequestTime, $wgShowHostnames;
 
-       $now = wfTime();
-       $elapsed = $now - $wgRequestTime;
+       $elapsed = microtime( true ) - $wgRequestTime;
 
        return $wgShowHostnames
                ? sprintf( '<!-- Served by %s in %01.3f secs. -->', wfHostname(), $elapsed )
@@ -1927,7 +2004,7 @@ function wfHttpError( $code, $label, $desc ) {
        $wgOut->sendCacheControl();
 
        header( 'Content-type: text/html; charset=utf-8' );
-       print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">".
+       print "<!doctype html>" .
                '<html><head><title>' .
                htmlspecialchars( $label ) .
                '</title></head><body><h1>' .
@@ -3488,88 +3565,6 @@ function wfGetNull() {
                : '/dev/null';
 }
 
-/**
- * Throws a warning that $function is deprecated
- *
- * @param $function String
- * @param $version String|false: Added in 1.19.
- * @param $component String|false: Added in 1.19.
- * 
- * @return null
- */
-function wfDeprecated( $function, $version = false, $component = false ) {
-       static $functionsWarned = array();
-
-       MWDebug::deprecated( $function, $version, $component );
-
-       if ( !isset( $functionsWarned[$function] ) ) {
-               $functionsWarned[$function] = true;
-               
-               if ( $version ) {
-                       global $wgDeprecationReleaseLimit;
-                       
-                       if ( $wgDeprecationReleaseLimit && $component === false ) {
-                               # Strip -* off the end of $version so that branches can use the
-                               # format #.##-branchname to avoid issues if the branch is merged into
-                               # a version of MediaWiki later than what it was branched from
-                               $comparableVersion = preg_replace( '/-.*$/', '', $version );
-                               
-                               # If the comparableVersion is larger than our release limit then
-                               # skip the warning message for the deprecation
-                               if ( version_compare( $wgDeprecationReleaseLimit, $comparableVersion, '<' ) ) {
-                                       return;
-                               }
-                       }
-                       
-                       $component = $component === false ? 'MediaWiki' : $component;
-                       wfWarn( "Use of $function was deprecated in $component $version.", 2 );
-               } else {
-                       wfWarn( "Use of $function is deprecated.", 2 );
-               }
-       }
-}
-
-/**
- * Send a warning either to the debug log or in a PHP error depending on
- * $wgDevelopmentWarnings
- *
- * @param $msg String: message to send
- * @param $callerOffset Integer: number of items to go back in the backtrace to
- *        find the correct caller (1 = function calling wfWarn, ...)
- * @param $level Integer: PHP error level; only used when $wgDevelopmentWarnings
- *        is true
- */
-function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
-       global $wgDevelopmentWarnings;
-
-       MWDebug::warning( $msg, $callerOffset + 2 );
-
-       $callers = wfDebugBacktrace();
-       if ( isset( $callers[$callerOffset + 1] ) ) {
-               $callerfunc = $callers[$callerOffset + 1];
-               $callerfile = $callers[$callerOffset];
-               if ( isset( $callerfile['file'] ) && isset( $callerfile['line'] ) ) {
-                       $file = $callerfile['file'] . ' at line ' . $callerfile['line'];
-               } else {
-                       $file = '(internal function)';
-               }
-               $func = '';
-               if ( isset( $callerfunc['class'] ) ) {
-                       $func .= $callerfunc['class'] . '::';
-               }
-               if ( isset( $callerfunc['function'] ) ) {
-                       $func .= $callerfunc['function'];
-               }
-               $msg .= " [Called from $func in $file]";
-       }
-
-       if ( $wgDevelopmentWarnings ) {
-               trigger_error( $msg, $level );
-       } else {
-               wfDebug( "$msg\n" );
-       }
-}
-
 /**
  * Modern version of wfWaitForSlaves(). Instead of looking at replication lag
  * and waiting for it to go down, this waits for the slaves to catch up to the