* (bug 29140) FirePHP debugging assist extension
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 25 May 2011 22:01:08 +0000 (22:01 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 25 May 2011 22:01:08 +0000 (22:01 +0000)
FirePHP is an extension to Firebug, an awesome debugging extension to Firefox.
It allows pulling debug log data in from your PHP script via HTTP headers, which then get displayed in Firebug's console along with errors, warnings, and AJAX hits from the web page.

Added 'Debug' hook which gets called from wfDebug() and wfDebugLog() to take this; note that a few lines of output won't make it to FirePHP as they are output either before we've done all plugin initialization, or after we've flushed output and can no longer add HTTP headers.

BSD-licensed FirePHPCore library from firephp-libs commit aff25803a3ff460b2797:
https://github.com/cadorn/firephp-libs/blob/aff25803a3ff460b2797/packages/core/lib/FirePHPCore/FirePHP.class.php

There's not a lot of fancy integration; everything's just output as a 'log' line.
You can use $wgFirePHP global (or call FirePHP::getInstance() yourself) to get direct access to FirePHP's fancier features in test code.

docs/hooks.txt
includes/GlobalFunctions.php

index 4690036..0c8cf92 100644 (file)
@@ -648,6 +648,10 @@ etc.
 'DatabaseOraclePostInit': Called after initialising an Oracle database
 &$db: the DatabaseOracle object
 
+'Debug': called when outputting a debug log line via wfDebug() or wfDebugLog()
+$text: plaintext string to be output
+$group: null or a string naming a logging group (as defined in $wgDebugLogGroups)
+
 'NewDifferenceEngine': Called when a new DifferenceEngine object is made
 $title: the diff page title (nullable)
 &$oldId: the actual old Id to use in the diff
index ceda004..0bff1d6 100644 (file)
@@ -339,12 +339,14 @@ function wfDebug( $text, $logonly = false ) {
                        $cache = array();
                }
        }
-       if ( $wgDebugLogFile != '' && !$wgProfileOnly ) {
-               # Strip unprintables; they can switch terminal modes when binary data
-               # gets dumped, which is pretty annoying.
-               $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', ' ', $text );
-               $text = $wgDebugLogPrefix . $text;
-               wfErrorLog( $text, $wgDebugLogFile );
+       if ( wfRunHooks( 'Debug', array( $text, null /* no log group */ ) ) ) {
+               if ( $wgDebugLogFile != '' && !$wgProfileOnly ) {
+                       # Strip unprintables; they can switch terminal modes when binary data
+                       # gets dumped, which is pretty annoying.
+                       $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', ' ', $text );
+                       $text = $wgDebugLogPrefix . $text;
+                       wfErrorLog( $text, $wgDebugLogFile );
+               }
        }
 }
 
@@ -405,7 +407,9 @@ function wfDebugLog( $logGroup, $text, $public = true ) {
                } else {
                        $host = '';
                }
-               wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
+               if ( wfRunHooks( 'Debug', array( $text, $logGroup ) ) ) {
+                       wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
+               }
        } elseif ( $public === true ) {
                wfDebug( $text, true );
        }