From: Aaron Schulz Date: Tue, 11 Dec 2012 21:18:57 +0000 (-0800) Subject: Made the profilers that output text not break js. X-Git-Tag: 1.31.0-rc.0~21140^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=0458ce38be9425e399eae2f8af81041630e9230f;p=lhc%2Fweb%2Fwiklou.git Made the profilers that output text not break js. Change-Id: I12377e7ac08203113e8d6650f57091a63ad1af27 --- diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index e3d22f8127..baffcd8121 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -589,4 +589,18 @@ class Profiler { 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; + } } diff --git a/includes/profiler/ProfilerSimpleText.php b/includes/profiler/ProfilerSimpleText.php index 3e7d6fa4d7..e62622f603 100644 --- a/includes/profiler/ProfilerSimpleText.php +++ b/includes/profiler/ProfilerSimpleText.php @@ -50,10 +50,18 @@ class ProfilerSimpleText extends ProfilerSimple { : 0; // profiling mismatch error? uasort( $this->mCollated, array('self','sort') ); array_walk( $this->mCollated, array('self','format'), $totalReal ); - if ( $this->visible ) { - print '
'.self::$out.'
'; - } else { + if ( php_sapi_name() === 'cli' ) { print "\n"; + } elseif ( $this->getContentType() === 'text/html' ) { + if ( $this->visible ) { + print '
'.self::$out.'
'; + } else { + print "\n"; + } + } elseif ( $this->getContentType() === 'text/javascript' ) { + print "\n/*\n".self::$out."*/\n"; + } elseif ( $this->getContentType() === 'text/css' ) { + print "\n/*\n".self::$out."*/\n"; } } } diff --git a/includes/profiler/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php index 822e9fe4fd..017e135248 100644 --- a/includes/profiler/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -69,6 +69,14 @@ class ProfilerSimpleTrace extends ProfilerSimple { } function logData() { - print ""; + if ( php_sapi_name() === 'cli' ) { + print ""; + } elseif ( $this->getContentType() === 'text/html' ) { + print ""; + } elseif ( $this->getContentType() === 'text/javascript' ) { + print "\n/*\n {$this->trace}\n*/"; + } elseif ( $this->getContentType() === 'text/css' ) { + print "\n/*\n {$this->trace}\n*/"; + } } }