split off new function wfBacktrace() from wfDebugDieBacktrace()
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 25 Apr 2005 13:43:21 +0000 (13:43 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 25 Apr 2005 13:43:21 +0000 (13:43 +0000)
includes/GlobalFunctions.php

index 3c3b199..9e334e5 100644 (file)
@@ -467,43 +467,64 @@ function wfErrorExit() {
 function wfDebugDieBacktrace( $msg = '' ) {
        global $wgCommandLineMode;
 
-       if ( function_exists( 'debug_backtrace' ) ) {
+       $backtrace = wfBacktrace();
+       if ( $backtrace !== false ) {
                if ( $wgCommandLineMode ) {
-                       $msg .= "\nBacktrace:\n";
+                       $msg .= "\nBacktrace:\n$backtrace";
                } else {
-                       $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
-               }
-               $backtrace = debug_backtrace();
-               foreach( $backtrace as $call ) {
-                       if( isset( $call['file'] ) ) {
-                               $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
-                               $file = $f[count($f)-1];
-                       } else {
-                               $file = '-';
-                       }
-                       if( isset( $call['line'] ) ) {
-                               $line = $call['line'];
-                       } else {
-                               $line = '-';
-                       }
-                       if ( $wgCommandLineMode ) {
-                               $msg .= "$file line $line calls ";
-                       } else {
-                               $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
-                       }
-                       if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
-                       $msg .= $call['function'] . '()';
-
-                       if ( $wgCommandLineMode ) {
-                               $msg .= "\n";
-                       } else {
-                               $msg .= "</li>\n";
-                       }
+                       $msg .= "\n<p>Backtrace:</p>\n$backtrace";
                }
         }
         die( $msg );
 }
 
+function wfBacktrace() {
+       global $wgCommandLineMode;
+       if ( !function_exists( 'debug_backtrace' ) ) {
+               return false;
+       }
+       
+       if ( $wgCommandLineMode ) {
+               $msg = '';
+       } else {
+               $msg = "<ul>\n";
+       }
+       $backtrace = debug_backtrace();
+       foreach( $backtrace as $call ) {
+               if( isset( $call['file'] ) ) {
+                       $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
+                       $file = $f[count($f)-1];
+               } else {
+                       $file = '-';
+               }
+               if( isset( $call['line'] ) ) {
+                       $line = $call['line'];
+               } else {
+                       $line = '-';
+               }
+               if ( $wgCommandLineMode ) {
+                       $msg .= "$file line $line calls ";
+               } else {
+                       $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
+               }
+               if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
+               $msg .= $call['function'] . '()';
+
+               if ( $wgCommandLineMode ) {
+                       $msg .= "\n";
+               } else {
+                       $msg .= "</li>\n";
+               }
+       }
+       if ( $wgCommandLineMode ) {
+               $msg .= "\n";
+       } else {
+               $msg .= "</ul>\n";
+       }
+
+       return $msg;
+}
+
 
 /* Some generic result counters, pulled out of SearchEngine */