39 protected static $log = [];
78 public static function setup() {
105 public static function init() {
106 self::$enabled =
true;
115 self::$enabled =
false;
126 if ( self::$enabled ) {
137 public static function log( $str ) {
138 if ( !self::$enabled ) {
141 if ( !is_string( $str ) ) {
142 $str = print_r( $str,
true );
145 'msg' => htmlspecialchars( $str ),
166 self::$deprecationWarnings = [];
180 public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE, $log =
'auto' ) {
187 if (
$log ===
'debug' ) {
191 $callerDescription = self::getCallerDescription( $callerOffset );
194 self::formatCallerDescription( $msg, $callerDescription ),
198 if ( self::$enabled ) {
200 'msg' => htmlspecialchars( $msg ),
202 'caller' => $callerDescription[
'func'],
225 public static function deprecated( $function, $version =
false,
226 $component =
false, $callerOffset = 2
229 $component = $component ?:
'MediaWiki';
230 $msg =
"Use of $function was deprecated in $component $version.";
232 $msg =
"Use of $function is deprecated.";
234 self::deprecatedMsg( $msg, $version, $component, $callerOffset + 1 );
258 $component =
false, $callerOffset = 2
260 if ( $callerOffset ===
false ) {
264 $callerDescription = self::getCallerDescription( $callerOffset );
265 $callerFunc = $callerDescription[
'func'];
266 $rawMsg = self::formatCallerDescription( $msg, $callerDescription );
272 if ( isset( self::$deprecationWarnings[$msg][$callerFunc] ) ) {
274 } elseif ( isset( self::$deprecationWarnings[$msg] ) ) {
275 if ( self::$enabled ) {
282 self::$deprecationWarnings[$msg][$callerFunc] =
true;
287 $component = $component ?:
'MediaWiki';
289 # Strip -* off the end of $version so that branches can use the
290 # format #.##-branchname to avoid issues if the branch is merged into
291 # a version of MediaWiki later than what it was branched from
292 $comparableVersion = preg_replace(
'/-.*$/',
'', $version );
294 # If the comparableVersion is larger than our release limit then
295 # skip the warning message for the deprecation
302 self::sendRawDeprecated(
323 foreach ( self::$deprecationFilters as $filter ) {
324 if ( preg_match( $filter, $msg ) ) {
338 if ( self::$enabled ) {
339 $logMsg = htmlspecialchars( $msg ) .
340 Html::rawElement(
'div', [
'class' =>
'mw-debug-backtrace' ],
341 Html::element(
'span', [],
'Backtrace:' ) .
wfBacktrace()
346 'type' =>
'deprecated',
347 'caller' => $callerFunc,
359 if ( !defined(
'MW_PHPUNIT_TEST' ) && !defined(
'MW_PARSER_TEST' ) ) {
360 throw new RuntimeException( __METHOD__ .
' can only be used in tests' );
362 self::$deprecationFilters[] = $regex;
369 self::$deprecationFilters = [];
382 if ( isset( $callers[$callerOffset] ) ) {
383 $callerfile = $callers[$callerOffset];
384 if ( isset( $callerfile[
'file'] ) && isset( $callerfile[
'line'] ) ) {
385 $file = $callerfile[
'file'] .
' at line ' . $callerfile[
'line'];
387 $file =
'(internal function)';
390 $file =
'(unknown location)';
393 if ( isset( $callers[$callerOffset + 1] ) ) {
394 $callerfunc = $callers[$callerOffset + 1];
396 if ( isset( $callerfunc[
'class'] ) ) {
397 $func .= $callerfunc[
'class'] .
'::';
399 if ( isset( $callerfunc[
'function'] ) ) {
400 $func .= $callerfunc[
'function'];
406 return [
'file' =>
$file,
'func' => $func ];
417 return $msg .
' [Called from ' . $caller[
'func'] .
' in ' . $caller[
'file'] .
']';
429 if ( $level !==
false ) {
430 trigger_error( $msg, $level );
444 public static function debugMsg( $str, $context = [] ) {
450 if ( isset( $context[
'prefix'] ) ) {
451 $prefix = $context[
'prefix'];
452 } elseif ( isset( $context[
'channel'] ) && $context[
'channel'] !==
'wfDebug' ) {
453 $prefix =
"[{$context['channel']}] ";
455 if ( isset( $context[
'seconds_elapsed'] ) && isset( $context[
'memory_used'] ) ) {
456 $prefix .=
"{$context['seconds_elapsed']} {$context['memory_used']} ";
458 $str = LegacyLogger::interpolate( $str, $context );
459 $str = $prefix . $str;
461 self::$debug[] = rtrim( UtfNormal\Validator::cleanUp( $str ) );
475 public static function query( $sql, $function, $runTime, $dbhost ) {
476 if ( !self::$enabled ) {
484 [\xC0-\xC1] # Invalid UTF-8 Bytes
485 | [\xF5-\xFF] # Invalid UTF-8 Bytes
486 | \xE0[\x80-\x9F] # Overlong encoding of prior code point
487 | \xF0[\x80-\x8F] # Overlong encoding of prior code point
488 | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start
489 | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start
490 | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start
491 | (?<=[\x0-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle
492 | (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4]
493 | [\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence
494 | (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence
495 | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
496 | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
503 $sql = UtfNormal\Validator::cleanUp( $sql );
506 'sql' =>
"$dbhost: $sql",
507 'function' => $function,
521 $files = get_included_files();
523 foreach ( $files as
$file ) {
524 $size = filesize(
$file );
527 'size' => $context->
getLanguage()->formatSize( $size ),
546 if ( self::$enabled ) {
547 self::log(
'MWDebug output complete' );
548 $debugInfo = self::getDebugInfo( $context );
554 $context->
getOutput()->getCSP()->getNonce()
559 $html .=
"<!-- Debug output:\n" .
560 htmlspecialchars( implode(
"\n", self::$debug ), ENT_NOQUOTES ) .
582 $ret =
"\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">\n";
584 foreach ( self::$debug as
$line ) {
585 $display = nl2br( htmlspecialchars( trim(
$line ) ) );
587 $ret .=
"<li><code>$display</code></li>\n";
590 $ret .=
'</ul>' .
"\n";
602 if ( !self::$enabled ) {
608 $obContents = ob_get_contents();
610 $obContentArray = explode(
'<br />', $obContents );
611 foreach ( $obContentArray as $obContent ) {
612 if ( trim( $obContent ) ) {
613 self::debugMsg( Sanitizer::stripAllTags( $obContent ) );
618 self::log(
'MWDebug output complete' );
619 $debugInfo = self::getDebugInfo( $context );
621 ApiResult::setIndexedTagName( $debugInfo,
'debuginfo' );
622 ApiResult::setIndexedTagName( $debugInfo[
'log'],
'line' );
623 ApiResult::setIndexedTagName( $debugInfo[
'debugLog'],
'msg' );
624 ApiResult::setIndexedTagName( $debugInfo[
'queries'],
'query' );
625 ApiResult::setIndexedTagName( $debugInfo[
'includes'],
'queries' );
626 $result->
addValue(
null,
'debuginfo', $debugInfo );
636 if ( !self::$enabled ) {
651 'phpEngine' =>
'PHP',
652 'phpVersion' => PHP_VERSION,
654 'gitBranch' => $branch,
656 'time' => $request->getElapsedTime(),
659 'queries' => self::$query,
661 'method' => $request->getMethod(),
662 'url' => $request->getRequestURL(),
663 'headers' => $request->getAllHeaders(),
664 'params' => $request->getValues(),
666 'memory' => $context->
getLanguage()->formatSize( memory_get_usage() ),
667 'memoryPeak' => $context->
getLanguage()->formatSize( memory_get_peak_usage() ),
668 'includes' => self::getFilesIncluded( $context ),
$wgUseCdn
Enable/disable CDN.
$wgDeprecationReleaseLimit
Release limitation to wfDeprecated warnings, if set to a release number development warnings will not...
$wgDebugComments
Send debug data to an HTML comment in the output.
$wgShowDebug
Display debug data at the bottom of the main content area.
$wgDebugToolbar
Display the new debugging toolbar.
$wgDevelopmentWarnings
If set to true MediaWiki will throw notices for some possible error conditions and for deprecated fun...
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
const MW_VERSION
The running version of MediaWiki.
global $wgCommandLineMode
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDebugBacktrace( $limit=0)
Safety wrapper for debug_backtrace().
This class represents the result of the API operations.
addValue( $path, $name, $value, $flags=0)
Add value to the output data at the given path.
static isSHA1( $str)
Check if a string looks like a hex encoded SHA1 hash.
New debugger system that outputs a toolbar on page view.
static warning( $msg, $callerOffset=1, $level=E_USER_NOTICE, $log='auto')
Adds a warning entry to the log.
static getFilesIncluded(IContextSource $context)
Returns a list of files included, along with their size.
static $enabled
Is the debugger enabled?
static addModules(OutputPage $out)
Add ResourceLoader modules to the OutputPage object if debugging is enabled.
static appendDebugInfoToApiResult(IContextSource $context, ApiResult $result)
Append the debug info to given ApiResult.
static $deprecationWarnings
Array of functions that have already been warned, formatted function-caller to prevent a buttload of ...
static string[] $deprecationFilters
Deprecation filter regexes.
static clearLog()
Clears internal log array and deprecation tracking.
static sendRawDeprecated( $msg, $sendToLog=true, $callerFunc='')
Send a raw deprecation message to the log and the debug toolbar, without filtering of duplicate messa...
static deinit()
Disable the debugger.
static sendMessage( $msg, $group, $level)
Send a message to the debug log and optionally also trigger a PHP error, depending on the $level argu...
static query( $sql, $function, $runTime, $dbhost)
Begins profiling on a database query.
static getLog()
Returns internal log array.
static log( $str)
Adds a line to the log.
static getDebugInfo(IContextSource $context)
Returns the HTML to add to the page for the toolbar.
static debugMsg( $str, $context=[])
This is a method to pass messages from wfDebug to the pretty debugger.
static clearDeprecationFilters()
Clear all deprecation filters.
static getCallerDescription( $callerOffset)
Get an array describing the calling function at a specified offset.
static formatCallerDescription( $msg, $caller)
Append a caller description to an error message.
static deprecated( $function, $version=false, $component=false, $callerOffset=2)
Show a warning that $function is deprecated.
static $query
SQL statements of the database queries.
static getHTMLDebugLog()
Generate debug log in HTML for displaying at the bottom of the main content area.
static filterDeprecationForTest( $regex)
Deprecation messages matching the supplied regex will be suppressed.
static init()
Enabled the debugger and load resource module.
static deprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
static getDebugHTML(IContextSource $context)
Returns the HTML to add to the page for the toolbar.
This is one of the Core classes and should be read at least once by any new developers.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
static makeInlineScript( $script, $nonce=null)
Make an HTML script that runs given JS code after startup and base modules.
static makeConfigSetScript(array $configuration)
Return JS code which will set the MediaWiki configuration array to the given value.
Interface for objects which can provide a MediaWiki context on request.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.