wfDebug( $s );
}
}
+
+ /**
+ * Get the content type sent out to the client.
+ * Used for profilers that output instead of store data.
+ * @return string
+ */
+ protected function getContentType() {
+ foreach ( headers_list() as $header ) {
+ if ( preg_match( '#^content-type: (\w+/\w+);?#i', $header, $m ) ) {
+ return $m[1];
+ }
+ }
+ return null;
+ }
}
: 0; // profiling mismatch error?
uasort( $this->mCollated, array('self','sort') );
array_walk( $this->mCollated, array('self','format'), $totalReal );
- if ( $this->visible ) {
- print '<pre>'.self::$out.'</pre>';
- } else {
+ if ( php_sapi_name() === 'cli' ) {
print "<!--\n".self::$out."\n-->\n";
+ } elseif ( $this->getContentType() === 'text/html' ) {
+ if ( $this->visible ) {
+ print '<pre>'.self::$out.'</pre>';
+ } else {
+ print "<!--\n".self::$out."\n-->\n";
+ }
+ } elseif ( $this->getContentType() === 'text/javascript' ) {
+ print "\n/*\n".self::$out."*/\n";
+ } elseif ( $this->getContentType() === 'text/css' ) {
+ print "\n/*\n".self::$out."*/\n";
}
}
}
}
function logData() {
- print "<!-- \n {$this->trace} \n -->";
+ if ( php_sapi_name() === 'cli' ) {
+ print "<!-- \n {$this->trace} \n -->";
+ } elseif ( $this->getContentType() === 'text/html' ) {
+ print "<!-- \n {$this->trace} \n -->";
+ } elseif ( $this->getContentType() === 'text/javascript' ) {
+ print "\n/*\n {$this->trace}\n*/";
+ } elseif ( $this->getContentType() === 'text/css' ) {
+ print "\n/*\n {$this->trace}\n*/";
+ }
}
}