summaryrefslogtreecommitdiff
path: root/includes/debug/Debug.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-12-08 09:55:49 +0100
commit4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch)
treeaf68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /includes/debug/Debug.php
parentaf4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff)
Update to MediaWiki 1.22.0
Diffstat (limited to 'includes/debug/Debug.php')
-rw-r--r--includes/debug/Debug.php74
1 files changed, 41 insertions, 33 deletions
diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php
index 8c39e1a1..6e9ccc41 100644
--- a/includes/debug/Debug.php
+++ b/includes/debug/Debug.php
@@ -1,6 +1,6 @@
<?php
/**
- * Debug toolbar related code
+ * Debug toolbar related code.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
*/
/**
- * New debugger system that outputs a toolbar on page view
+ * New debugger system that outputs a toolbar on page view.
*
* By default, most methods do nothing ( self::$enabled = false ). You have
* to explicitly call MWDebug::init() to enabled them.
@@ -35,28 +35,28 @@ class MWDebug {
/**
* Log lines
*
- * @var array
+ * @var array $log
*/
protected static $log = array();
/**
- * Debug messages from wfDebug()
+ * Debug messages from wfDebug().
*
- * @var array
+ * @var array $debug
*/
protected static $debug = array();
/**
- * Queries
+ * SQL statements of the databses queries.
*
- * @var array
+ * @var array $query
*/
protected static $query = array();
/**
* Is the debugger enabled?
*
- * @var bool
+ * @var bool $enabled
*/
protected static $enabled = false;
@@ -64,7 +64,7 @@ class MWDebug {
* Array of functions that have already been warned, formatted
* function-caller to prevent a buttload of warnings
*
- * @var array
+ * @var array $deprecationWarnings
*/
protected static $deprecationWarnings = array();
@@ -135,10 +135,24 @@ class MWDebug {
* @since 1.19
* @param $msg string
* @param $callerOffset int
- * @param int $level A PHP error level. See sendWarning()
+ * @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).
+ *
* @return mixed
*/
- public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
+ public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE, $log = 'auto' ) {
+ global $wgDevelopmentWarnings;
+
+ if ( $log === 'auto' && !$wgDevelopmentWarnings ) {
+ $log = 'debug';
+ }
+
+ if ( $log === 'debug' ) {
+ $level = false;
+ }
+
$callerDescription = self::getCallerDescription( $callerOffset );
self::sendWarning( $msg, $callerDescription, $level );
@@ -212,7 +226,8 @@ class MWDebug {
}
if ( $sendToLog ) {
- self::sendWarning( $msg, $callerDescription, E_USER_DEPRECATED );
+ global $wgDevelopmentWarnings; // we could have a more specific $wgDeprecationWarnings setting.
+ self::sendWarning( $msg, $callerDescription, $wgDevelopmentWarnings ? E_USER_DEPRECATED : false );
}
if ( self::$enabled ) {
@@ -267,23 +282,21 @@ class MWDebug {
}
/**
- * Send a warning either to the debug log or by triggering an user PHP
- * error depending on $wgDevelopmentWarnings.
+ * Send a warning to the debug log and optionally also trigger a PHP
+ * error, depending on the $level argument.
*
- * @param string $msg Message to send
- * @param array $caller caller description get from getCallerDescription()
- * @param $level error level to use if $wgDevelopmentWarnings is true
+ * @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
*/
private static function sendWarning( $msg, $caller, $level ) {
- global $wgDevelopmentWarnings;
-
$msg .= ' [Called from ' . $caller['func'] . ' in ' . $caller['file'] . ']';
- if ( $wgDevelopmentWarnings ) {
+ if ( $level !== false ) {
trigger_error( $msg, $level );
- } else {
- wfDebug( "$msg\n" );
}
+
+ wfDebug( "$msg\n" );
}
/**
@@ -297,7 +310,7 @@ class MWDebug {
global $wgDebugComments, $wgShowDebug;
if ( self::$enabled || $wgDebugComments || $wgShowDebug ) {
- self::$debug[] = rtrim( $str );
+ self::$debug[] = rtrim( UtfNormal::cleanUp( $str ) );
}
}
@@ -319,7 +332,7 @@ class MWDebug {
self::$query[] = array(
'sql' => $sql,
'function' => $function,
- 'master' => (bool) $isMaster,
+ 'master' => (bool)$isMaster,
'time' => 0.0,
'_start' => microtime( true ),
);
@@ -471,10 +484,10 @@ class MWDebug {
// output errors as debug info, when display_errors is on
// this is necessary for all non html output of the api, because that clears all errors first
$obContents = ob_get_contents();
- if( $obContents ) {
+ if ( $obContents ) {
$obContentArray = explode( '<br />', $obContents );
- foreach( $obContentArray as $obContent ) {
- if( trim( $obContent ) ) {
+ foreach ( $obContentArray as $obContent ) {
+ if ( trim( $obContent ) ) {
self::debugMsg( Sanitizer::stripAllTags( $obContent ) );
}
}
@@ -485,15 +498,10 @@ class MWDebug {
$result->setIndexedTagName( $debugInfo, 'debuginfo' );
$result->setIndexedTagName( $debugInfo['log'], 'line' );
- foreach( $debugInfo['debugLog'] as $index => $debugLogText ) {
- $vals = array();
- ApiResult::setContent( $vals, $debugLogText );
- $debugInfo['debugLog'][$index] = $vals; //replace
- }
$result->setIndexedTagName( $debugInfo['debugLog'], 'msg' );
$result->setIndexedTagName( $debugInfo['queries'], 'query' );
$result->setIndexedTagName( $debugInfo['includes'], 'queries' );
- $result->addValue( array(), 'debuginfo', $debugInfo );
+ $result->addValue( null, 'debuginfo', $debugInfo );
}
/**