diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/debug | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/debug')
-rw-r--r-- | includes/debug/MWDebug.php (renamed from includes/debug/Debug.php) | 121 |
1 files changed, 82 insertions, 39 deletions
diff --git a/includes/debug/Debug.php b/includes/debug/MWDebug.php index 6e9ccc41..c2f22233 100644 --- a/includes/debug/Debug.php +++ b/includes/debug/MWDebug.php @@ -31,7 +31,6 @@ * @since 1.19 */ class MWDebug { - /** * Log lines * @@ -83,7 +82,7 @@ class MWDebug { * enabled. * * @since 1.19 - * @param $out OutputPage + * @param OutputPage $out */ public static function addModules( OutputPage $out ) { if ( self::$enabled ) { @@ -97,7 +96,7 @@ class MWDebug { * @todo Add support for passing objects * * @since 1.19 - * @param $str string + * @param string $str */ public static function log( $str ) { if ( !self::$enabled ) { @@ -133,12 +132,12 @@ class MWDebug { * Adds a warning entry to the log * * @since 1.19 - * @param $msg string - * @param $callerOffset int - * @param $level int A PHP error level. See sendWarning() - * @param $log string: 'production' will always trigger a php error, 'auto' - * will trigger an error if $wgDevelopmentWarnings is true, and 'debug' - * will only write to the debug log(s). + * @param string $msg + * @param int $callerOffset + * @param int $level A PHP error level. See sendMessage() + * @param string $log 'production' will always trigger a php error, 'auto' + * will trigger an error if $wgDevelopmentWarnings is true, and 'debug' + * will only write to the debug log(s). * * @return mixed */ @@ -155,7 +154,7 @@ class MWDebug { $callerDescription = self::getCallerDescription( $callerOffset ); - self::sendWarning( $msg, $callerDescription, $level ); + self::sendMessage( $msg, $callerDescription, 'warning', $level ); if ( self::$enabled ) { self::$log[] = array( @@ -179,13 +178,14 @@ class MWDebug { * @param string $function Function that is deprecated. * @param string|bool $version Version in which the function was deprecated. * @param string|bool $component Component to which the function belongs. - * If false, it is assumbed the function is in MediaWiki core. - * @param $callerOffset integer: How far up the callstack is the original + * If false, it is assumbed the function is in MediaWiki core. + * @param int $callerOffset How far up the callstack is the original * caller. 2 = function that called the function that called * MWDebug::deprecated() (Added in 1.20). - * @return mixed */ - public static function deprecated( $function, $version = false, $component = false, $callerOffset = 2 ) { + public static function deprecated( $function, $version = false, + $component = false, $callerOffset = 2 + ) { $callerDescription = self::getCallerDescription( $callerOffset ); $callerFunc = $callerDescription['func']; @@ -227,7 +227,12 @@ class MWDebug { if ( $sendToLog ) { global $wgDevelopmentWarnings; // we could have a more specific $wgDeprecationWarnings setting. - self::sendWarning( $msg, $callerDescription, $wgDevelopmentWarnings ? E_USER_DEPRECATED : false ); + self::sendMessage( + $msg, + $callerDescription, + 'deprecated', + $wgDevelopmentWarnings ? E_USER_DEPRECATED : false + ); } if ( self::$enabled ) { @@ -247,9 +252,9 @@ class MWDebug { /** * Get an array describing the calling function at a specified offset. * - * @param $callerOffset integer: How far up the callstack is the original + * @param int $callerOffset How far up the callstack is the original * caller. 0 = function that called getCallerDescription() - * @return array with two keys: 'file' and 'func' + * @return array Array with two keys: 'file' and 'func' */ private static function getCallerDescription( $callerOffset ) { $callers = wfDebugBacktrace(); @@ -282,21 +287,22 @@ class MWDebug { } /** - * Send a warning to the debug log and optionally also trigger a PHP + * Send a message to the debug log and optionally also trigger a PHP * error, depending on the $level argument. * - * @param $msg string Message to send - * @param $caller array caller description get from getCallerDescription() - * @param $level int|bool error level to use; set to false to not trigger an error + * @param string $msg Message to send + * @param array $caller Caller description get from getCallerDescription() + * @param string $group Log group on which to send the message + * @param int|bool $level Error level to use; set to false to not trigger an error */ - private static function sendWarning( $msg, $caller, $level ) { + private static function sendMessage( $msg, $caller, $group, $level ) { $msg .= ' [Called from ' . $caller['func'] . ' in ' . $caller['file'] . ']'; if ( $level !== false ) { trigger_error( $msg, $level ); } - wfDebug( "$msg\n" ); + wfDebugLog( $group, $msg, 'log' ); } /** @@ -304,7 +310,7 @@ class MWDebug { * Do NOT use this method, use MWDebug::log or wfDebug() * * @since 1.19 - * @param $str string + * @param string $str */ public static function debugMsg( $str ) { global $wgDebugComments, $wgShowDebug; @@ -318,9 +324,9 @@ class MWDebug { * Begins profiling on a database query * * @since 1.19 - * @param $sql string - * @param $function string - * @param $isMaster bool + * @param string $sql + * @param string $function + * @param bool $isMaster * @return int ID number of the query to pass to queryTime or -1 if the * debugger is disabled */ @@ -329,6 +335,28 @@ class MWDebug { return -1; } + // Replace invalid UTF-8 chars with a square UTF-8 character + // This prevents json_encode from erroring out due to binary SQL data + $sql = preg_replace( + '/( + [\xC0-\xC1] # Invalid UTF-8 Bytes + | [\xF5-\xFF] # Invalid UTF-8 Bytes + | \xE0[\x80-\x9F] # Overlong encoding of prior code point + | \xF0[\x80-\x8F] # Overlong encoding of prior code point + | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start + | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start + | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start + | (?<=[\x0-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle + | (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4] + |[\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence + | (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence + | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence + | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2) + )/x', + '■', + $sql + ); + self::$query[] = array( 'sql' => $sql, 'function' => $function, @@ -344,7 +372,7 @@ class MWDebug { * Calculates how long a query took. * * @since 1.19 - * @param $id int + * @param int $id */ public static function queryTime( $id ) { if ( $id === -1 || !self::$enabled ) { @@ -358,7 +386,7 @@ class MWDebug { /** * Returns a list of files included, along with their size * - * @param $context IContextSource + * @param IContextSource $context * @return array */ protected static function getFilesIncluded( IContextSource $context ) { @@ -379,7 +407,7 @@ class MWDebug { * Returns the HTML to add to the page for the toolbar * * @since 1.19 - * @param $context IContextSource + * @param IContextSource $context * @return string */ public static function getDebugHTML( IContextSource $context ) { @@ -445,10 +473,15 @@ class MWDebug { $display = "\xc2\xa0"; } - if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) { + if ( !$ident + && $diff < 0 + && substr( $display, 0, 9 ) != 'Entering ' + && substr( $display, 0, 8 ) != 'Exiting ' + ) { $ident = $curIdent; $diff = 0; - $display = '<span style="background:yellow;">' . nl2br( htmlspecialchars( $display ) ) . '</span>'; + $display = '<span style="background:yellow;">' . + nl2br( htmlspecialchars( $display ) ) . '</span>'; } else { $display = nl2br( htmlspecialchars( $display ) ); } @@ -460,7 +493,7 @@ class MWDebug { } else { $ret .= str_repeat( "<ul><li>\n", $diff ); } - $ret .= "<tt>$display</tt>\n"; + $ret .= "<code>$display</code>\n"; $curIdent = $ident; } @@ -473,8 +506,8 @@ class MWDebug { /** * Append the debug info to given ApiResult * - * @param $context IContextSource - * @param $result ApiResult + * @param IContextSource $context + * @param ApiResult $result */ public static function appendDebugInfoToApiResult( IContextSource $context, ApiResult $result ) { if ( !self::$enabled ) { @@ -501,13 +534,14 @@ class MWDebug { $result->setIndexedTagName( $debugInfo['debugLog'], 'msg' ); $result->setIndexedTagName( $debugInfo['queries'], 'query' ); $result->setIndexedTagName( $debugInfo['includes'], 'queries' ); + $result->setIndexedTagName( $debugInfo['profile'], 'function' ); $result->addValue( null, 'debuginfo', $debugInfo ); } /** * Returns the HTML to add to the page for the toolbar * - * @param $context IContextSource + * @param IContextSource $context * @return array */ public static function getDebugInfo( IContextSource $context ) { @@ -517,9 +551,17 @@ class MWDebug { global $wgVersion, $wgRequestTime; $request = $context->getRequest(); + + // HHVM's reported memory usage from memory_get_peak_usage() + // is not useful when passing false, but we continue passing + // false for consistency of historical data in zend. + // see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246 + $realMemoryUsage = wfIsHHVM(); + return array( 'mwVersion' => $wgVersion, - 'phpVersion' => PHP_VERSION, + 'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP', + 'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), @@ -533,9 +575,10 @@ class MWDebug { 'headers' => $request->getAllHeaders(), 'params' => $request->getValues(), ), - 'memory' => $context->getLanguage()->formatSize( memory_get_usage() ), - 'memoryPeak' => $context->getLanguage()->formatSize( memory_get_peak_usage() ), + 'memory' => $context->getLanguage()->formatSize( memory_get_usage( $realMemoryUsage ) ), + 'memoryPeak' => $context->getLanguage()->formatSize( memory_get_peak_usage( $realMemoryUsage ) ), 'includes' => self::getFilesIncluded( $context ), + 'profile' => Profiler::instance()->getRawData(), ); } } |