r56551 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56550‎ | r56551 | r56552 >
Date:18:55, 17 September 2009
Author:ialex
Status:resolved
Tags:
Comment:
* indent debug output produced when both $wgShowDebug and $wgDebugFunctionEntry are enabled for better readability. In this case, unindented comment will be displayed "inline" with a yellow background
* 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
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -308,7 +308,7 @@
309309 */
310310 function wfDebug( $text, $logonly = false ) {
311311 global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
312 - global $wgDebugLogPrefix;
 312+ global $wgDebugLogPrefix, $wgShowDebug;
313313 static $recursion = 0;
314314
315315 static $cache = array(); // Cache of unoutputted messages
@@ -318,7 +318,7 @@
319319 return;
320320 }
321321
322 - if ( $wgDebugComments && !$logonly ) {
 322+ if ( ( $wgDebugComments || $wgShowDebug ) && !$logonly ) {
323323 $cache[] = $text;
324324
325325 if ( !isset( $wgOut ) ) {
Index: trunk/phase3/includes/HTMLFileCache.php
@@ -55,7 +55,7 @@
5656 if( $this->useGzip() )
5757 $this->mFileCache .= '.gz';
5858
59 - wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
 59+ wfDebug( __METHOD__ . ": {$this->mFileCache}\n" );
6060 }
6161 return $this->mFileCache;
6262 }
@@ -111,7 +111,7 @@
112112 $cachetime = $this->fileCacheTime();
113113 $good = $timestamp <= $cachetime && $wgCacheEpoch <= $cachetime;
114114
115 - wfDebug(" isFileCacheGood() - cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
 115+ wfDebug( __METHOD__ . ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
116116 return $good;
117117 }
118118
@@ -137,7 +137,7 @@
138138 /* Working directory to/from output */
139139 public function loadFromFileCache() {
140140 global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
141 - wfDebug(" loadFromFileCache()\n");
 141+ wfDebug( __METHOD__ . "()\n");
142142 $filename = $this->fileCacheName();
143143 // Raw pages should handle cache control on their own,
144144 // even when using file cache. This reduces hits from clients.
@@ -176,7 +176,7 @@
177177 return $text;
178178 }
179179
180 - wfDebug(" saveToFileCache()\n", false);
 180+ wfDebug( __METHOD__ . "()\n", false);
181181
182182 $this->checkCacheDirs();
183183
Index: trunk/phase3/includes/SkinTemplate.php
@@ -141,7 +141,7 @@
142142 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
143143 global $wgMaxCredits, $wgShowCreditsIfMax;
144144 global $wgPageShowWatchingUsers;
145 - global $wgUseTrackbacks, $wgUseSiteJs;
 145+ global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
146146 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
147147
148148 wfProfileIn( __METHOD__ );
@@ -419,7 +419,12 @@
420420 $tpl->set( 'privacy', $this->privacyLink() );
421421 $tpl->set( 'about', $this->aboutLink() );
422422
423 - $tpl->setRef( 'debug', $out->mDebugtext );
 423+ if ( $wgDebugComments ) {
 424+ $tpl->setRef( 'debug', $out->mDebugtext );
 425+ } else {
 426+ $tpl->set( 'debug', '' );
 427+ }
 428+
424429 $tpl->set( 'reporttime', wfReportTime() );
425430 $tpl->set( 'sitenotice', wfGetSiteNotice() );
426431 $tpl->set( 'bottomscripts', $this->bottomScripts() );
Index: trunk/phase3/includes/Skin.php
@@ -959,13 +959,48 @@
960960 protected function generateDebugHTML() {
961961 global $wgShowDebug, $wgOut;
962962 if ( $wgShowDebug ) {
963 - $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext ) );
964 - return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
965 - $listInternals . "</li></ul>\n";
 963+ $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
 964+ return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
 965+ $listInternals . "</ul>\n";
966966 }
967967 return '';
968968 }
969969
 970+ private function formatDebugHTML( $debugText ) {
 971+ $lines = explode( "\n", $debugText );
 972+ $curIdent = 0;
 973+ $ret = '<li>';
 974+ foreach( $lines as $line ) {
 975+ $m = array();
 976+ $display = ltrim( $line );
 977+ $ident = strlen( $line ) - strlen( $display );
 978+ $diff = $ident - $curIdent;
 979+
 980+ if ( $display == '' )
 981+ $display = "\xc2\xa0";
 982+
 983+ if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
 984+ $ident = $curIdent;
 985+ $diff = 0;
 986+ $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
 987+ } else {
 988+ $display = htmlspecialchars( $display );
 989+ }
 990+
 991+ if ( $diff < 0 )
 992+ $ret .= str_repeat( "</li></ul>\n", -$diff ) . "<li>\n";
 993+ elseif ( $diff == 0 )
 994+ $ret .= "</li><li>\n";
 995+ else
 996+ $ret .= str_repeat( "<ul><li>\n", $diff );
 997+ $ret .= $display . "\n";
 998+
 999+ $curIdent = $ident;
 1000+ }
 1001+ $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
 1002+ return $ret;
 1003+ }
 1004+
9701005 /**
9711006 * This gets called shortly before the </body> tag.
9721007 * @return String HTML to be put before </body>

Follow-up revisions

RevisionCommit summaryAuthorDate
r56733Fix for r56551: Added missing "</li>" when reducing indentation, passed valid...ialex20:31, 21 September 2009

Status & tagging log