MediaWiki  1.30.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, $context=[])
 This is a method to pass messages from wfDebug to the pretty debugger. More...
 
static deinit ()
 Disable the 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, $runTime)
 Begins profiling on a database query. 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 = []
 Debug messages from wfDebug(). More...
 
static $deprecationWarnings = []
 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 = []
 Log lines. More...
 
static $query = []
 SQL statements of the database 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.

Since
1.19

Definition at line 33 of file MWDebug.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
OutputPage$out

Definition at line 96 of file MWDebug.php.

References $out.

Referenced by OutputPage\output().

◆ appendDebugInfoToApiResult()

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

Append the debug info to given ApiResult.

Parameters
IContextSource$context
ApiResult$result

Definition at line 481 of file MWDebug.php.

References $context, as, debugMsg(), getDebugInfo(), log(), and ApiResult\setIndexedTagName().

Referenced by ApiMain\executeAction(), and MWDebugTest\testAppendDebugInfoToApiResultXmlFormat().

◆ clearLog()

static MWDebug::clearLog ( )
static

Clears internal log array and deprecation tracking.

Since
1.19

Definition at line 135 of file MWDebug.php.

Referenced by MWDebugTest\setUp().

◆ debugMsg()

static MWDebug::debugMsg (   $str,
  $context = [] 
)
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
string$str
array$context

Definition at line 323 of file MWDebug.php.

References $context, $debug, $wgDebugComments, $wgShowDebug, and global.

Referenced by appendDebugInfoToApiResult(), and MediaWiki\Logger\LegacyLogger\log().

◆ deinit()

static MWDebug::deinit ( )
static

Disable the debugger.

Since
1.28

Definition at line 85 of file MWDebug.php.

Referenced by MWDebugTest\tearDownAfterClass().

◆ 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.
int$callerOffsetHow far up the callstack is the original caller. 2 = function that called the function that called MWDebug::deprecated() (Added in 1.20).

Definition at line 193 of file MWDebug.php.

References $wgDeprecationReleaseLimit, $wgDevelopmentWarnings, 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
int$callerOffsetHow far up the callstack is the original caller. 0 = function that called getCallerDescription()
Returns
array Array with two keys: 'file' and 'func'

Definition at line 266 of file MWDebug.php.

References 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
IContextSource$context
Returns
string

Definition at line 422 of file MWDebug.php.

References $context, $debug, $html, $wgDebugComments, getDebugInfo(), global, and log().

Referenced by BaseTemplate\getTrail().

◆ getDebugInfo()

static MWDebug::getDebugInfo ( IContextSource  $context)
static

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

Parameters
IContextSource$context
Returns
array

Definition at line 515 of file MWDebug.php.

References $context, $debug, $log, $query, $request, $wgRequestTime, $wgVersion, GitInfo\currentBranch(), getFilesIncluded(), global, GitInfo\headSHA1(), GitInfo\headViewUrl(), GitInfo\isSHA1(), and wfIsHHVM().

Referenced by appendDebugInfoToApiResult(), and getDebugHTML().

◆ getFilesIncluded()

static MWDebug::getFilesIncluded ( IContextSource  $context)
staticprotected

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

Parameters
IContextSource$context
Returns
array

Definition at line 401 of file MWDebug.php.

References $context, and as.

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 455 of file MWDebug.php.

References $debug, $line, $ret, $wgShowDebug, as, and global.

Referenced by Skin\generateDebugHTML().

◆ getLog()

static MWDebug::getLog ( )
static

Returns internal log array.

Since
1.19
Returns
array

Definition at line 127 of file MWDebug.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 MWDebug.php.

Referenced by MWDebugTest\setUpBeforeClass().

◆ log()

static MWDebug::log (   $str)
static

Adds a line to the log.

Since
1.19
Parameters
mixed$str

Definition at line 108 of file MWDebug.php.

References wfGetCaller().

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

◆ query()

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

Begins profiling on a database query.

Since
1.19
Parameters
string$sql
string$function
bool$isMaster
float$runTimeQuery run time
Returns
int ID number of the query to pass to queryTime or -1 if the debugger is disabled

Definition at line 355 of file MWDebug.php.

References $query, and captcha-old\count.

Referenced by MediaWiki\Logger\LegacyLogger\log().

◆ 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
string$msgMessage to send
array$callerCaller description get from getCallerDescription()
string$groupLog group on which to send the message
int | bool$levelError level to use; set to false to not trigger an error

Definition at line 305 of file MWDebug.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
string$msg
int$callerOffset
int$levelA PHP error level. See sendMessage()
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).

Definition at line 151 of file MWDebug.php.

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

Referenced by MWDebugTest\testAddWarning(), MWDebugTest\testAvoidNonConsecutivesDuplicateDeprecations(), and MediaWiki\HeaderCallback\warnIfHeadersSent().

Member Data Documentation

◆ $debug

array MWDebug::$debug = []
staticprotected

Debug messages from wfDebug().

Definition at line 46 of file MWDebug.php.

Referenced by getDebugInfo().

◆ $deprecationWarnings

array MWDebug::$deprecationWarnings = []
staticprotected

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

Definition at line 68 of file MWDebug.php.

◆ $enabled

bool MWDebug::$enabled = false
staticprotected

Is the debugger enabled?

Definition at line 60 of file MWDebug.php.

◆ $log

array MWDebug::$log = []
staticprotected

Log lines.

Definition at line 39 of file MWDebug.php.

Referenced by getDebugInfo(), getLog(), and warning().

◆ $query

array MWDebug::$query = []
staticprotected

SQL statements of the database queries.

Definition at line 53 of file MWDebug.php.

Referenced by getDebugInfo().


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