MediaWiki  1.23.0
MWDebug Class Reference

New debugger system that outputs a toolbar on page view. More...

Static Public Member Functions

static addModules (OutputPage $out)
 Add ResourceLoader modules to the OutputPage object if debugging is enabled. More...
 
static appendDebugInfoToApiResult (IContextSource $context, ApiResult $result)
 Append the debug info to given ApiResult. More...
 
static clearLog ()
 Clears internal log array and deprecation tracking. More...
 
static debugMsg ( $str)
 This is a method to pass messages from wfDebug to the pretty debugger. More...
 
static deprecated ( $function, $version=false, $component=false, $callerOffset=2)
 Show a warning that $function is deprecated. More...
 
static getDebugHTML (IContextSource $context)
 Returns the HTML to add to the page for the toolbar. More...
 
static getDebugInfo (IContextSource $context)
 Returns the HTML to add to the page for the toolbar. More...
 
static getHTMLDebugLog ()
 Generate debug log in HTML for displaying at the bottom of the main content area. More...
 
static getLog ()
 Returns internal log array. More...
 
static init ()
 Enabled the debugger and load resource module. More...
 
static log ( $str)
 Adds a line to the log. More...
 
static query ( $sql, $function, $isMaster)
 Begins profiling on a database query. More...
 
static queryTime ( $id)
 Calculates how long a query took. More...
 
static warning ( $msg, $callerOffset=1, $level=E_USER_NOTICE, $log='auto')
 Adds a warning entry to the log. More...
 

Static Protected Member Functions

static getFilesIncluded (IContextSource $context)
 Returns a list of files included, along with their size. More...
 

Static Protected Attributes

static $debug = array()
 Debug messages from wfDebug(). More...
 
static $deprecationWarnings = array()
 Array of functions that have already been warned, formatted function-caller to prevent a buttload of warnings. More...
 
static $enabled = false
 Is the debugger enabled? More...
 
static $log = array()
 Log lines. More...
 
static $query = array()
 SQL statements of the databses queries. More...
 

Static Private Member Functions

static getCallerDescription ( $callerOffset)
 Get an array describing the calling function at a specified offset. More...
 
static sendMessage ( $msg, $caller, $group, $level)
 Send a message to the debug log and optionally also trigger a PHP error, depending on the $level argument. More...
 

Detailed Description

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.

Todo:
Profiler support
Since
1.19

Definition at line 33 of file Debug.php.

Member Function Documentation

◆ addModules()

static MWDebug::addModules ( OutputPage  $out)
static

Add ResourceLoader modules to the OutputPage object if debugging is enabled.

Since
1.19
Parameters
$outOutputPage

Definition at line 87 of file Debug.php.

References $out.

Referenced by OutputPage\output().

◆ appendDebugInfoToApiResult()

static MWDebug::appendDebugInfoToApiResult ( IContextSource  $context,
ApiResult  $result 
)
static

Append the debug info to given ApiResult.

Parameters
$contextIContextSource
$resultApiResult

Definition at line 491 of file Debug.php.

References as, debugMsg(), getDebugInfo(), log(), and Sanitizer\stripAllTags().

Referenced by ApiMain\executeAction().

◆ clearLog()

static MWDebug::clearLog ( )
static

Clears internal log array and deprecation tracking.

Since
1.19

Definition at line 126 of file Debug.php.

References array().

Referenced by MWDebugTest\setUp().

◆ debugMsg()

static MWDebug::debugMsg (   $str)
static

This is a method to pass messages from wfDebug to the pretty debugger.

Do NOT use this method, use MWDebug::log or wfDebug()

Since
1.19
Parameters
$strstring

Definition at line 316 of file Debug.php.

References $debug, UtfNormal\cleanUp(), and global.

Referenced by appendDebugInfoToApiResult().

◆ deprecated()

static MWDebug::deprecated (   $function,
  $version = false,
  $component = false,
  $callerOffset = 2 
)
static

Show a warning that $function is deprecated.

This will send it to the following locations:

  • Debug toolbar, with one item per function and caller, if $wgDebugToolbar is set to true.
  • PHP's error log, with level E_USER_DEPRECATED, if $wgDevelopmentWarnings is set to true.
  • MediaWiki's debug log, if $wgDevelopmentWarnings is set to false.
Since
1.19
Parameters
string$functionFunction that is deprecated.
string | bool$versionVersion in which the function was deprecated.
string | bool$componentComponent to which the function belongs. If false, it is assumbed the function is in MediaWiki core.
$callerOffsetinteger: How far up the callstack is the original caller. 2 = function that called the function that called MWDebug::deprecated() (Added in 1.20).
Returns
mixed

Definition at line 187 of file Debug.php.

References $version, array(), Html\element(), getCallerDescription(), global, Html\rawElement(), sendMessage(), and wfBacktrace().

Referenced by MWDebugTest\testAvoidDuplicateDeprecations(), and MWDebugTest\testAvoidNonConsecutivesDuplicateDeprecations().

◆ getCallerDescription()

static MWDebug::getCallerDescription (   $callerOffset)
staticprivate

Get an array describing the calling function at a specified offset.

Parameters
$callerOffsetinteger: How far up the callstack is the original caller. 0 = function that called getCallerDescription()
Returns
array with two keys: 'file' and 'func'

Definition at line 260 of file Debug.php.

References $file, array(), and wfDebugBacktrace().

Referenced by deprecated(), and warning().

◆ getDebugHTML()

static MWDebug::getDebugHTML ( IContextSource  $context)
static

Returns the HTML to add to the page for the toolbar.

Since
1.19
Parameters
$contextIContextSource
Returns
string

Definition at line 392 of file Debug.php.

References $debug, $html, array(), getDebugInfo(), global, Html\inlineScript(), log(), ResourceLoader\makeConfigSetScript(), and ResourceLoader\makeLoaderConditionalScript().

Referenced by BaseTemplate\printTrail().

◆ getDebugInfo()

static MWDebug::getDebugInfo ( IContextSource  $context)
static

◆ getFilesIncluded()

static MWDebug::getFilesIncluded ( IContextSource  $context)
staticprotected

Returns a list of files included, along with their size.

Parameters
$contextIContextSource
Returns
array

Definition at line 371 of file Debug.php.

References $file, $files, $size, array(), as, and IContextSource\getLanguage().

Referenced by getDebugInfo().

◆ getHTMLDebugLog()

static MWDebug::getHTMLDebugLog ( )
static

Generate debug log in HTML for displaying at the bottom of the main content area.

If $wgShowDebug is false, an empty string is always returned.

Since
1.20
Returns
string HTML fragment

Definition at line 427 of file Debug.php.

References $debug, $line, $matches, $pre, $ret, array(), as, and global.

Referenced by Skin\generateDebugHTML().

◆ getLog()

static MWDebug::getLog ( )
static

Returns internal log array.

Since
1.19
Returns
array

Definition at line 118 of file Debug.php.

References $log.

Referenced by MWDebugTest\testAddLog(), MWDebugTest\testAddWarning(), MWDebugTest\testAvoidDuplicateDeprecations(), and MWDebugTest\testAvoidNonConsecutivesDuplicateDeprecations().

◆ init()

static MWDebug::init ( )
static

Enabled the debugger and load resource module.

This is called by Setup.php when $wgDebugToolbar is true.

Since
1.19

Definition at line 76 of file Debug.php.

Referenced by MWDebugTest\setUp().

◆ log()

static MWDebug::log (   $str)
static

Adds a line to the log.

Todo:
Add support for passing objects
Since
1.19
Parameters
$strstring

Definition at line 101 of file Debug.php.

References array(), and wfGetCaller().

Referenced by appendDebugInfoToApiResult(), getDebugHTML(), MWDebugTest\testAddLog(), and MWDebugTest\testAvoidNonConsecutivesDuplicateDeprecations().

◆ query()

static MWDebug::query (   $sql,
  $function,
  $isMaster 
)
static

Begins profiling on a database query.

Since
1.19
Parameters
$sqlstring
$functionstring
$isMasterbool
Returns
int ID number of the query to pass to queryTime or -1 if the debugger is disabled

Definition at line 334 of file Debug.php.

References $query, and array().

Referenced by DatabaseBase\query().

◆ queryTime()

static MWDebug::queryTime (   $id)
static

Calculates how long a query took.

Since
1.19
Parameters
$idint

Definition at line 356 of file Debug.php.

References $query.

Referenced by DatabaseBase\query().

◆ sendMessage()

static MWDebug::sendMessage (   $msg,
  $caller,
  $group,
  $level 
)
staticprivate

Send a message to the debug log and optionally also trigger a PHP error, depending on the $level argument.

Parameters
$msgstring Message to send
$callerarray caller description get from getCallerDescription()
$groupstring log group on which to send the message
$levelint|bool error level to use; set to false to not trigger an error

Definition at line 299 of file Debug.php.

References wfDebugLog().

Referenced by deprecated(), and warning().

◆ warning()

static MWDebug::warning (   $msg,
  $callerOffset = 1,
  $level = E_USER_NOTICE,
  $log = 'auto' 
)
static

Adds a warning entry to the log.

Since
1.19
Parameters
$msgstring
$callerOffsetint
$levelint A PHP error level. See sendMessage()
$logstring: '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).
Returns
mixed

Definition at line 144 of file Debug.php.

References $log, array(), getCallerDescription(), global, and sendMessage().

Referenced by MWDebugTest\testAddWarning(), and MWDebugTest\testAvoidNonConsecutivesDuplicateDeprecations().

Member Data Documentation

◆ $debug

array MWDebug::$debug = array()
staticprotected

Debug messages from wfDebug().

Definition at line 46 of file Debug.php.

◆ $deprecationWarnings

array MWDebug::$deprecationWarnings = array()
staticprotected

Array of functions that have already been warned, formatted function-caller to prevent a buttload of warnings.

Definition at line 68 of file Debug.php.

◆ $enabled

bool MWDebug::$enabled = false
staticprotected

Is the debugger enabled?

Definition at line 60 of file Debug.php.

◆ $log

array MWDebug::$log = array()
staticprotected

Log lines.

Definition at line 39 of file Debug.php.

Referenced by getLog(), and warning().

◆ $query

array MWDebug::$query = array()
staticprotected

SQL statements of the databses queries.

Definition at line 53 of file Debug.php.


The documentation for this class was generated from the following file: