MediaWiki  master
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 clearDeprecationFilters ()
 Clear all deprecation filters. 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 deprecatedMsg ( $msg, $version=false, $component=false, $callerOffset=2)
 Log a deprecation warning with arbitrary message text. More...
 
static detectDeprecatedOverride ( $instance, $class, $method, $version=false, $component=false, $callerOffset=2)
 Show a warning if $method declared in $class is overridden in $instance. More...
 
static filterDeprecationForTest ( $regex)
 Deprecation messages matching the supplied regex will be suppressed. 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 parseCallerDescription ( $msg)
 Append a caller description to an error message. More...
 
static query ( $sql, $function, $runTime, $dbhost)
 Begins profiling on a database query. More...
 
static sendRawDeprecated ( $msg, $sendToLog=true, $callerFunc='')
 Send a raw deprecation message to the log and the debug toolbar, without filtering of duplicate messages. More...
 
static setup ()
 
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 array $debug = []
 Debug messages from wfDebug(). More...
 
static string[] $deprecationFilters = []
 Deprecation filter regexes. More...
 
static array $deprecationWarnings = []
 Array of functions that have already been warned, formatted function-caller to prevent a buttload of warnings. More...
 
static bool $enabled = false
 Is the debugger enabled? More...
 
static array $log = []
 Log lines. More...
 
static array $query = []
 SQL statements of the database queries. More...
 

Static Private Member Functions

static formatCallerDescription ( $msg, $caller)
 Append a caller description to an error message. More...
 
static getCallerDescription ( $callerOffset)
 Get an array describing the calling function at a specified offset. More...
 
static sendMessage ( $msg, $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 125 of file MWDebug.php.

References OutputPage\addModules().

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

References ApiResult\addValue(), debugMsg(), getDebugInfo(), log(), ApiResult\setIndexedTagName(), and Sanitizer\stripAllTags().

Referenced by ApiMain\executeAction().

◆ clearDeprecationFilters()

static MWDebug::clearDeprecationFilters ( )
static

Clear all deprecation filters.

Definition at line 409 of file MWDebug.php.

◆ clearLog()

static MWDebug::clearLog ( )
static

Clears internal log array and deprecation tracking.

Since
1.19

Definition at line 164 of file MWDebug.php.

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

References $debug, $wgDebugComments, and $wgShowDebug.

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

◆ deinit()

static MWDebug::deinit ( )
static

Disable the debugger.

Since
1.28

Definition at line 114 of file MWDebug.php.

Referenced by RebuildFileCache\finalSetup().

◆ deprecated()

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

Show a warning that $function is deprecated.

See also
deprecatedMsg()
Since
1.19
Parameters
string$functionFunction that is deprecated.
string | false$versionVersion in which the function was deprecated.
string | bool$componentComponent to which the function belongs. If false, it is assumed 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 221 of file MWDebug.php.

References deprecatedMsg().

Referenced by wfDeprecated().

◆ deprecatedMsg()

static MWDebug::deprecatedMsg (   $msg,
  $version = false,
  $component = false,
  $callerOffset = 2 
)
static

Log a deprecation warning with arbitrary message text.

A caller description will be appended. If the message has already been sent for this caller, it won't be sent again.

Although there are component and version parameters, they are not automatically appended to the message. The message text should include information about when the thing was deprecated.

The warning will be sent 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. This is the case in phpunit tests per default, and will cause tests to fail.
  • MediaWiki's debug log, if $wgDevelopmentWarnings is set to false.
Since
1.35
Parameters
string$msgThe message
string | false$versionVersion of MediaWiki that the function was deprecated in.
string | bool$componentComponent to which the function belongs. If false, it is assumed the function is in MediaWiki core.
int | false$callerOffsetHow far up the call stack is the original caller. 2 = function that called the function that called us. If false, the caller description will not be appended.

Definition at line 304 of file MWDebug.php.

References $wgDeprecationReleaseLimit, formatCallerDescription(), getCallerDescription(), and sendRawDeprecated().

Referenced by deprecated(), detectDeprecatedOverride(), and wfDeprecatedMsg().

◆ detectDeprecatedOverride()

static MWDebug::detectDeprecatedOverride (   $instance,
  $class,
  $method,
  $version = false,
  $component = false,
  $callerOffset = 2 
)
static

Show a warning if $method declared in $class is overridden in $instance.

Since
1.36
See also
deprecatedMsg()

phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam

Parameters
object$instanceObject on which to detect deprecated overrides (typically $this).
string$classClass declaring the deprecated method (typically CLASS )
string$methodThe name of the deprecated method.
string | false$versionVersion in which the method was deprecated.
string | bool$componentComponent to which the class belongs. If false, it is assumed the class is in MediaWiki core.
int$callerOffsetHow far up the callstack is the original caller. 2 = function that called the function that called MWDebug::detectDeprecatedOverride()
Returns
bool True if the method was overridden, false otherwise. If the method was overridden, it should be called. The deprecated method's default implementation should call MWDebug::deprecated().

Definition at line 254 of file MWDebug.php.

References deprecatedMsg().

Referenced by ContentHandler\preSaveTransform().

◆ filterDeprecationForTest()

static MWDebug::filterDeprecationForTest (   $regex)
static

Deprecation messages matching the supplied regex will be suppressed.

Use this to filter deprecation warnings when testing deprecated code.

Parameters
string$regex

Definition at line 399 of file MWDebug.php.

◆ formatCallerDescription()

static MWDebug::formatCallerDescription (   $msg,
  $caller 
)
staticprivate

Append a caller description to an error message.

Parameters
string$msg
array$callerCaller description from getCallerDescription()
Returns
string

Definition at line 457 of file MWDebug.php.

Referenced by deprecatedMsg().

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

References $file, and wfDebugBacktrace().

Referenced by deprecatedMsg(), 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 610 of file MWDebug.php.

References $debug, $wgDebugComments, getDebugInfo(), IContextSource\getOutput(), log(), ResourceLoader\makeConfigSetScript(), and ResourceLoader\makeInlineScript().

Referenced by BaseTemplate\getTrail(), and SkinMustache\tailElement().

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

References $debug, $log, $query, GitInfo\currentBranch(), getFilesIncluded(), IContextSource\getLanguage(), IContextSource\getRequest(), GitInfo\headSHA1(), GitInfo\headViewUrl(), GitInfo\isSHA1(), and MW_VERSION.

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

References $file, 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 644 of file MWDebug.php.

References $debug, $line, $wgShowDebug, and Html\rawElement().

Referenced by SkinTemplate\prepareQuickTemplate(), and SkinMustache\tailElement().

◆ getLog()

static MWDebug::getLog ( )
static

Returns internal log array.

Since
1.19
Returns
array

Definition at line 156 of file MWDebug.php.

References $log.

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

Referenced by setup().

◆ log()

static MWDebug::log (   $str)
static

Adds a line to the log.

Since
1.19
Parameters
mixed$str

Definition at line 137 of file MWDebug.php.

References wfGetCaller().

Referenced by appendDebugInfoToApiResult(), and getDebugHTML().

◆ parseCallerDescription()

static MWDebug::parseCallerDescription (   $msg)
static

Append a caller description to an error message.

Access: internal
For use by MWExceptionHandler to override 'exception.file' in error logs.
Parameters
string$msgFormatted message from formatCallerDescription() and getCallerDescription()
Returns
null|array<string,string> Null if unable to recognise all parts, or array with:
  • 'file': string of file path
  • 'line': string of line number
  • 'func': string of function or method name
  • 'message': Re-formatted version of $msg for use with ErrorException, so as to not include file/line twice.

Definition at line 474 of file MWDebug.php.

Referenced by MWExceptionHandler\handleError().

◆ query()

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

Begins profiling on a database query.

Since
1.19
Parameters
string$sql
string$function
float$runTimeQuery run time
string$dbhost
Returns
bool True if debugger is enabled, false otherwise

Definition at line 544 of file MWDebug.php.

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

◆ sendMessage()

static MWDebug::sendMessage (   $msg,
  $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
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 497 of file MWDebug.php.

References wfDebugLog().

Referenced by warning().

◆ sendRawDeprecated()

static MWDebug::sendRawDeprecated (   $msg,
  $sendToLog = true,
  $callerFunc = '' 
)
static

Send a raw deprecation message to the log and the debug toolbar, without filtering of duplicate messages.

A caller description will not be appended.

Parameters
string$msgThe complete message including relevant caller information.
bool$sendToLogIf true, the message will be sent to the debug toolbar, the debug log, and raised as a warning to PHP. If false, the message will only be sent to the debug toolbar.
string$callerFuncThe caller, for display in the debug toolbar's caller column.

Definition at line 368 of file MWDebug.php.

References Html\element(), Html\rawElement(), and wfBacktrace().

Referenced by deprecatedMsg(), MediaWiki\HookContainer\HookContainer\emitDeprecationWarnings(), and MWLBFactory\logDeprecation().

◆ setup()

static MWDebug::setup ( )
static
Access: internal
For use by Setup.php only.

Definition at line 78 of file MWDebug.php.

References $wgCommandLineMode, $wgDebugToolbar, $wgUseCdn, $wgUseFileCache, and init().

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

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

Referenced by XmlDumpWriter\invokeLenient(), WikiExporter\outputPageStreamBatch(), MediaWiki\HeaderCallback\warnIfHeadersSent(), wfLogWarning(), wfWarn(), and XmlDumpWriter\writeSlot().

Member Data Documentation

◆ $debug

array MWDebug::$debug = []
staticprotected

Debug messages from wfDebug().

Definition at line 46 of file MWDebug.php.

Referenced by getDebugInfo().

◆ $deprecationFilters

string [] MWDebug::$deprecationFilters = []
staticprotected

Deprecation filter regexes.

Definition at line 73 of file MWDebug.php.

◆ $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: