39 protected static $log = [];
73 public static function setup() {
100 public static function init() {
101 self::$enabled =
true;
110 self::$enabled =
false;
121 if ( self::$enabled ) {
132 public static function log( $str ) {
133 if ( !self::$enabled ) {
136 if ( !is_string( $str ) ) {
137 $str = print_r( $str,
true );
140 'msg' => htmlspecialchars( $str ),
161 self::$deprecationWarnings = [];
175 public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE, $log =
'auto' ) {
182 if (
$log ===
'debug' ) {
186 $callerDescription = self::getCallerDescription( $callerOffset );
188 self::sendMessage( $msg, $callerDescription,
'warning', $level );
190 if ( self::$enabled ) {
192 'msg' => htmlspecialchars( $msg ),
194 'caller' => $callerDescription[
'func'],
217 public static function deprecated( $function, $version =
false,
218 $component =
false, $callerOffset = 2
220 $callerDescription = self::getCallerDescription( $callerOffset );
221 $callerFunc = $callerDescription[
'func'];
226 if ( isset( self::$deprecationWarnings[$function][$callerFunc] ) ) {
228 } elseif ( isset( self::$deprecationWarnings[$function] ) ) {
229 if ( self::$enabled ) {
236 self::$deprecationWarnings[$function][$callerFunc] =
true;
241 # Strip -* off the end of $version so that branches can use the
242 # format #.##-branchname to avoid issues if the branch is merged into
243 # a version of MediaWiki later than what it was branched from
244 $comparableVersion = preg_replace(
'/-.*$/',
'', $version );
246 # If the comparableVersion is larger than our release limit then
247 # skip the warning message for the deprecation
253 $component = $component ===
false ?
'MediaWiki' : $component;
254 $msg =
"Use of $function was deprecated in $component $version.";
256 $msg =
"Use of $function is deprecated.";
269 if ( self::$enabled ) {
270 $logMsg = htmlspecialchars( $msg ) .
271 Html::rawElement(
'div', [
'class' =>
'mw-debug-backtrace' ],
272 Html::element(
'span', [],
'Backtrace:' ) .
wfBacktrace()
277 'type' =>
'deprecated',
278 'caller' => $callerFunc,
293 if ( isset( $callers[$callerOffset] ) ) {
294 $callerfile = $callers[$callerOffset];
295 if ( isset( $callerfile[
'file'] ) && isset( $callerfile[
'line'] ) ) {
296 $file = $callerfile[
'file'] .
' at line ' . $callerfile[
'line'];
298 $file =
'(internal function)';
301 $file =
'(unknown location)';
304 if ( isset( $callers[$callerOffset + 1] ) ) {
305 $callerfunc = $callers[$callerOffset + 1];
307 if ( isset( $callerfunc[
'class'] ) ) {
308 $func .= $callerfunc[
'class'] .
'::';
310 if ( isset( $callerfunc[
'function'] ) ) {
311 $func .= $callerfunc[
'function'];
317 return [
'file' =>
$file,
'func' => $func ];
329 private static function sendMessage( $msg, $caller, $group, $level ) {
330 $msg .=
' [Called from ' . $caller[
'func'] .
' in ' . $caller[
'file'] .
']';
332 if ( $level !==
false ) {
333 trigger_error( $msg, $level );
353 if ( isset(
$context[
'prefix'] ) ) {
355 } elseif ( isset(
$context[
'channel'] ) &&
$context[
'channel'] !==
'wfDebug' ) {
356 $prefix =
"[{$context['channel']}] ";
358 if ( isset(
$context[
'seconds_elapsed'] ) && isset(
$context[
'memory_used'] ) ) {
359 $prefix .=
"{$context['seconds_elapsed']} {$context['memory_used']} ";
361 $str = LegacyLogger::interpolate( $str,
$context );
362 $str = $prefix . $str;
364 self::$debug[] = rtrim( UtfNormal\Validator::cleanUp( $str ) );
378 public static function query( $sql, $function, $runTime, $dbhost ) {
379 if ( !self::$enabled ) {
387 [\xC0-\xC1] # Invalid UTF-8 Bytes
388 | [\xF5-\xFF] # Invalid UTF-8 Bytes
389 | \xE0[\x80-\x9F] # Overlong encoding of prior code point
390 | \xF0[\x80-\x8F] # Overlong encoding of prior code point
391 | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start
392 | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start
393 | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start
394 | (?<=[\x0-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle
395 | (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4]
396 | [\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence
397 | (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence
398 | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
399 | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
406 $sql = UtfNormal\Validator::cleanUp( $sql );
409 'sql' =>
"$dbhost: $sql",
410 'function' => $function,
424 $files = get_included_files();
426 foreach ( $files as
$file ) {
427 $size = filesize(
$file );
430 'size' =>
$context->getLanguage()->formatSize( $size ),
449 if ( self::$enabled ) {
450 self::log(
'MWDebug output complete' );
451 $debugInfo = self::getDebugInfo(
$context );
455 $html = ResourceLoader::makeInlineScript(
456 ResourceLoader::makeConfigSetScript( [
'debugInfo' => $debugInfo ] ),
457 $context->getOutput()->getCSPNonce()
462 $html .=
"<!-- Debug output:\n" .
463 htmlspecialchars( implode(
"\n", self::$debug ), ENT_NOQUOTES ) .
485 $ret =
"\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">\n";
487 foreach ( self::$debug as
$line ) {
488 $display = nl2br( htmlspecialchars( trim(
$line ) ) );
490 $ret .=
"<li><code>$display</code></li>\n";
493 $ret .=
'</ul>' .
"\n";
505 if ( !self::$enabled ) {
511 $obContents = ob_get_contents();
513 $obContentArray = explode(
'<br />', $obContents );
514 foreach ( $obContentArray as $obContent ) {
515 if ( trim( $obContent ) ) {
516 self::debugMsg( Sanitizer::stripAllTags( $obContent ) );
521 self::log(
'MWDebug output complete' );
522 $debugInfo = self::getDebugInfo(
$context );
524 ApiResult::setIndexedTagName( $debugInfo,
'debuginfo' );
525 ApiResult::setIndexedTagName( $debugInfo[
'log'],
'line' );
526 ApiResult::setIndexedTagName( $debugInfo[
'debugLog'],
'msg' );
527 ApiResult::setIndexedTagName( $debugInfo[
'queries'],
'query' );
528 ApiResult::setIndexedTagName( $debugInfo[
'includes'],
'queries' );
529 $result->
addValue(
null,
'debuginfo', $debugInfo );
539 if ( !self::$enabled ) {
561 'phpEngine' =>
wfIsHHVM() ?
'HHVM' :
'PHP',
562 'phpVersion' =>
wfIsHHVM() ? HHVM_VERSION : PHP_VERSION,
564 'gitBranch' => $branch,
566 'time' => $request->getElapsedTime(),
569 'queries' => self::$query,
571 'method' => $request->getMethod(),
572 'url' => $request->getRequestURL(),
573 'headers' => $request->getAllHeaders(),
574 'params' => $request->getValues(),
576 'memory' =>
$context->getLanguage()->formatSize( memory_get_usage( $realMemoryUsage ) ),
577 'memoryPeak' =>
$context->getLanguage()->formatSize( memory_get_peak_usage( $realMemoryUsage ) ),
578 '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.
$wgVersion
MediaWiki version number.
$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.
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().
wfIsHHVM()
Check if we are running under HHVM.
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 clearLog()
Clears internal log array and deprecation tracking.
static deinit()
Disable the debugger.
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 getCallerDescription( $callerOffset)
Get an array describing the calling function at a specified offset.
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 sendMessage( $msg, $caller, $group, $level)
Send a message to the debug log and optionally also trigger a PHP error, depending on the $level argu...
static getHTMLDebugLog()
Generate debug log in HTML for displaying at the bottom of the main content area.
static init()
Enabled the debugger and load resource module.
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.
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.