// Check to see if there was already a deprecation notice, so not to
// get a duplicate warning
$logCount = count( self::$log );
+ $caller = wfGetCaller( $callerOffset + 1 );
if ( $logCount ) {
$lastLog = self::$log[ $logCount - 1 ];
- if ( $lastLog['type'] == 'deprecated' && $lastLog['caller'] == wfGetCaller( $callerOffset + 1 ) ) {
+ if ( $lastLog['type'] == 'deprecated' && $lastLog['caller'] == $caller ) {
return;
}
}
self::$log[] = array(
'msg' => htmlspecialchars( $msg ),
'type' => 'warn',
- 'caller' => wfGetCaller( $callerOffset ),
+ 'caller' => $caller,
);
}
* @param $str string
*/
public static function debugMsg( $str ) {
- if ( !self::$enabled ) {
- return;
- }
+ global $wgDebugComments, $wgShowDebug;
- self::$debug[] = trim( $str );
+ if ( self::$enabled || $wgDebugComments || $wgShowDebug ) {
+ self::$debug[] = rtrim( $str );
+ }
}
/**
* @return string
*/
public static function getDebugHTML( IContextSource $context ) {
- if ( !self::$enabled ) {
+ global $wgDebugComments;
+
+ $html = '';
+
+ if ( self::$enabled ) {
+ MWDebug::log( 'MWDebug output complete' );
+ $debugInfo = self::getDebugInfo( $context );
+
+ // Cannot use OutputPage::addJsConfigVars because those are already outputted
+ // by the time this method is called.
+ $html = Html::inlineScript(
+ ResourceLoader::makeLoaderConditionalScript(
+ ResourceLoader::makeConfigSetScript( array( 'debugInfo' => $debugInfo ) )
+ )
+ );
+ }
+
+ if ( $wgDebugComments ) {
+ $html .= "<!-- Debug output:\n" .
+ htmlspecialchars( implode( "\n", self::$debug ) ) .
+ "\n\n-->";
+ }
+
+ return $html;
+ }
+
+ /**
+ * 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
+ * @return string HTML fragment
+ */
+ public static function getHTMLDebugLog() {
+ global $wgDebugTimestamps, $wgShowDebug;
+
+ if ( !$wgShowDebug ) {
return '';
}
- MWDebug::log( 'MWDebug output complete' );
- $debugInfo = self::getDebugInfo( $context );
+ $curIdent = 0;
+ $ret = "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">\n<li>";
+
+ foreach ( self::$debug as $line ) {
+ $pre = '';
+ if ( $wgDebugTimestamps ) {
+ $matches = array();
+ if ( preg_match( '/^(\d+\.\d+ {1,3}\d+.\dM\s{2})/', $line, $matches ) ) {
+ $pre = $matches[1];
+ $line = substr( $line, strlen( $pre ) );
+ }
+ }
+ $display = ltrim( $line );
+ $ident = strlen( $line ) - strlen( $display );
+ $diff = $ident - $curIdent;
- // Cannot use OutputPage::addJsConfigVars because those are already outputted
- // by the time this method is called.
- $html = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- ResourceLoader::makeConfigSetScript( array( 'debugInfo' => $debugInfo ) )
- )
- );
+ $display = $pre . $display;
+ if ( $display == '' ) {
+ $display = "\xc2\xa0";
+ }
- return $html;
+ if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
+ $ident = $curIdent;
+ $diff = 0;
+ $display = '<span style="background:yellow;">' . nl2br( htmlspecialchars( $display ) ) . '</span>';
+ } else {
+ $display = nl2br( htmlspecialchars( $display ) );
+ }
+
+ if ( $diff < 0 ) {
+ $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
+ } elseif ( $diff == 0 ) {
+ $ret .= "</li><li>\n";
+ } else {
+ $ret .= str_repeat( "<ul><li>\n", $diff );
+ }
+ $ret .= "<tt>$display</tt>\n";
+
+ $curIdent = $ident;
+ }
+
+ $ret .= str_repeat( '</li></ul>', $curIdent ) . "</li>\n</ul>\n";
+
+ return $ret;
}
/**
return;
}
+ // output errors as debug info, when display_errors is on
+ // this is necessary for all non html output of the api, because that clears all errors first
+ $obContents = ob_get_contents();
+ if( $obContents ) {
+ $obContentArray = explode( '<br />', $obContents );
+ foreach( $obContentArray as $obContent ) {
+ if( trim( $obContent ) ) {
+ self::debugMsg( Sanitizer::stripAllTags( $obContent ) );
+ }
+ }
+ }
+
MWDebug::log( 'MWDebug output complete' );
$debugInfo = self::getDebugInfo( $context );
'debugLog' => self::$debug,
'queries' => self::$query,
'request' => array(
- 'method' => $_SERVER['REQUEST_METHOD'],
+ 'method' => $request->getMethod(),
'url' => $request->getRequestURL(),
'headers' => $request->getAllHeaders(),
'params' => $request->getValues(),