* indent debug output produced when both $wgShowDebug and $wgDebugFunctionEntry are...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 17 Sep 2009 18:55:29 +0000 (18:55 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 17 Sep 2009 18:55:29 +0000 (18:55 +0000)
* added an id to the debug data list
* allow to use $wgShowDebug with $wgDebugComments set to false
* update HTMLFileCache to use full method name in debug output

includes/GlobalFunctions.php
includes/HTMLFileCache.php
includes/Skin.php
includes/SkinTemplate.php

index d635151..fa60b42 100644 (file)
@@ -308,7 +308,7 @@ function wfUrlencode( $s ) {
  */
 function wfDebug( $text, $logonly = false ) {
        global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
-       global $wgDebugLogPrefix;
+       global $wgDebugLogPrefix, $wgShowDebug;
        static $recursion = 0;
 
        static $cache = array(); // Cache of unoutputted messages
@@ -318,7 +318,7 @@ function wfDebug( $text, $logonly = false ) {
                return;
        }
 
-       if ( $wgDebugComments && !$logonly ) {
+       if ( ( $wgDebugComments || $wgShowDebug ) && !$logonly ) {
                $cache[] = $text;
 
                if ( !isset( $wgOut ) ) {
index d205624..4611042 100644 (file)
@@ -55,7 +55,7 @@ class HTMLFileCache {
                        if( $this->useGzip() )
                                $this->mFileCache .= '.gz';
 
-                       wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
+                       wfDebug( __METHOD__ . ": {$this->mFileCache}\n" );
                }
                return $this->mFileCache;
        }
@@ -111,7 +111,7 @@ class HTMLFileCache {
                $cachetime = $this->fileCacheTime();
                $good = $timestamp <= $cachetime && $wgCacheEpoch <= $cachetime;
 
-               wfDebug(" isFileCacheGood() - cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
+               wfDebug( __METHOD__ . ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
                return $good;
        }
 
@@ -137,7 +137,7 @@ class HTMLFileCache {
        /* Working directory to/from output */
        public function loadFromFileCache() {
                global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
-               wfDebug(" loadFromFileCache()\n");
+               wfDebug( __METHOD__ . "()\n");
                $filename = $this->fileCacheName();
                // Raw pages should handle cache control on their own,
                // even when using file cache. This reduces hits from clients.
@@ -176,7 +176,7 @@ class HTMLFileCache {
                        return $text;
                }
 
-               wfDebug(" saveToFileCache()\n", false);
+               wfDebug( __METHOD__ . "()\n", false);
 
                $this->checkCacheDirs();
 
index 42262cd..845d4ac 100644 (file)
@@ -959,13 +959,48 @@ END;
        protected function generateDebugHTML() {
                global $wgShowDebug, $wgOut;
                if ( $wgShowDebug ) {
-                       $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext ) );
-                       return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
-                               $listInternals . "</li></ul>\n";
+                       $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
+                       return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
+                               $listInternals . "</ul>\n";
                }
                return '';
        }
 
+       private function formatDebugHTML( $debugText ) {
+               $lines = explode( "\n", $debugText );
+               $curIdent = 0;
+               $ret = '<li>';
+               foreach( $lines as $line ) {
+                       $m = array();
+                       $display = ltrim( $line );
+                       $ident = strlen( $line ) - strlen( $display );
+                       $diff = $ident - $curIdent;
+
+                       if ( $display == '' )
+                               $display = "\xc2\xa0";
+
+                       if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
+                               $ident = $curIdent;
+                               $diff = 0;
+                               $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
+                       } else {
+                               $display = htmlspecialchars( $display );
+                       }
+
+                       if ( $diff < 0 )
+                               $ret .= str_repeat( "</li></ul>\n", -$diff ) . "<li>\n";
+                       elseif ( $diff == 0 )
+                               $ret .= "</li><li>\n";
+                       else
+                               $ret .= str_repeat( "<ul><li>\n", $diff );
+                       $ret .= $display . "\n";
+                       
+                       $curIdent = $ident;
+               }
+               $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
+               return $ret;
+       }
+
        /**
         * This gets called shortly before the </body> tag.
         * @return String HTML to be put before </body>
index d943c0b..2423c19 100644 (file)
@@ -141,7 +141,7 @@ class SkinTemplate extends Skin {
                global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
                global $wgMaxCredits, $wgShowCreditsIfMax;
                global $wgPageShowWatchingUsers;
-               global $wgUseTrackbacks, $wgUseSiteJs;
+               global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
 
                wfProfileIn( __METHOD__ );
@@ -419,7 +419,12 @@ class SkinTemplate extends Skin {
                $tpl->set( 'privacy', $this->privacyLink() );
                $tpl->set( 'about', $this->aboutLink() );
 
-               $tpl->setRef( 'debug', $out->mDebugtext );
+               if ( $wgDebugComments ) {
+                       $tpl->setRef( 'debug', $out->mDebugtext );
+               } else {
+                       $tpl->set( 'debug', '' );
+               }
+
                $tpl->set( 'reporttime', wfReportTime() );
                $tpl->set( 'sitenotice', wfGetSiteNotice() );
                $tpl->set( 'bottomscripts', $this->bottomScripts() );