*
* @var array $log
*/
- protected static $log = array();
+ protected static $log = [];
/**
* Debug messages from wfDebug().
*
* @var array $debug
*/
- protected static $debug = array();
+ protected static $debug = [];
/**
* SQL statements of the database queries.
*
* @var array $query
*/
- protected static $query = array();
+ protected static $query = [];
/**
* Is the debugger enabled?
*
* @var array $deprecationWarnings
*/
- protected static $deprecationWarnings = array();
+ protected static $deprecationWarnings = [];
/**
* Enabled the debugger and load resource module.
/**
* Adds a line to the log
*
- * @todo Add support for passing objects
- *
* @since 1.19
- * @param string $str
+ * @param mixed $str
*/
public static function log( $str ) {
if ( !self::$enabled ) {
return;
}
-
- self::$log[] = array(
+ if ( !is_string( $str ) ) {
+ $str = print_r( $str, true );
+ }
+ self::$log[] = [
'msg' => htmlspecialchars( $str ),
'type' => 'log',
'caller' => wfGetCaller(),
- );
+ ];
}
/**
* @since 1.19
*/
public static function clearLog() {
- self::$log = array();
- self::$deprecationWarnings = array();
+ self::$log = [];
+ self::$deprecationWarnings = [];
}
/**
self::sendMessage( $msg, $callerDescription, 'warning', $level );
if ( self::$enabled ) {
- self::$log[] = array(
+ self::$log[] = [
'msg' => htmlspecialchars( $msg ),
'type' => 'warn',
'caller' => $callerDescription['func'],
- );
+ ];
}
}
if ( self::$enabled ) {
$logMsg = htmlspecialchars( $msg ) .
- Html::rawElement( 'div', array( 'class' => 'mw-debug-backtrace' ),
- Html::element( 'span', array(), 'Backtrace:' ) . wfBacktrace()
+ Html::rawElement( 'div', [ 'class' => 'mw-debug-backtrace' ],
+ Html::element( 'span', [], 'Backtrace:' ) . wfBacktrace()
);
- self::$log[] = array(
+ self::$log[] = [
'msg' => $logMsg,
'type' => 'deprecated',
'caller' => $callerFunc,
- );
+ ];
}
}
$func = 'unknown';
}
- return array( 'file' => $file, 'func' => $func );
+ return [ 'file' => $file, 'func' => $func ];
}
/**
* @param string $str
* @param array $context
*/
- public static function debugMsg( $str, $context = array() ) {
+ public static function debugMsg( $str, $context = [] ) {
global $wgDebugComments, $wgShowDebug;
if ( self::$enabled || $wgDebugComments || $wgShowDebug ) {
$sql
);
- self::$query[] = array(
+ // last check for invalid utf8
+ $sql = UtfNormal\Validator::cleanUp( $sql );
+
+ self::$query[] = [
'sql' => $sql,
'function' => $function,
'master' => (bool)$isMaster,
'time' => 0.0,
'_start' => microtime( true ),
- );
+ ];
return count( self::$query ) - 1;
}
*/
protected static function getFilesIncluded( IContextSource $context ) {
$files = get_included_files();
- $fileList = array();
+ $fileList = [];
foreach ( $files as $file ) {
$size = filesize( $file );
- $fileList[] = array(
+ $fileList[] = [
'name' => $file,
'size' => $context->getLanguage()->formatSize( $size ),
- );
+ ];
}
return $fileList;
// Cannot use OutputPage::addJsConfigVars because those are already outputted
// by the time this method is called.
$html = ResourceLoader::makeInlineScript(
- ResourceLoader::makeConfigSetScript( array( 'debugInfo' => $debugInfo ) )
+ ResourceLoader::makeConfigSetScript( [ 'debugInfo' => $debugInfo ] )
);
}
*/
public static function getDebugInfo( IContextSource $context ) {
if ( !self::$enabled ) {
- return array();
+ return [];
}
global $wgVersion, $wgRequestTime;
// see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246
$realMemoryUsage = wfIsHHVM();
- return array(
+ return [
'mwVersion' => $wgVersion,
'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP',
'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION,
'log' => self::$log,
'debugLog' => self::$debug,
'queries' => self::$query,
- 'request' => array(
+ 'request' => [
'method' => $request->getMethod(),
'url' => $request->getRequestURL(),
'headers' => $request->getAllHeaders(),
'params' => $request->getValues(),
- ),
+ ],
'memory' => $context->getLanguage()->formatSize( memory_get_usage( $realMemoryUsage ) ),
'memoryPeak' => $context->getLanguage()->formatSize( memory_get_peak_usage( $realMemoryUsage ) ),
'includes' => self::getFilesIncluded( $context ),
- );
+ ];
}
}