From: Ori Livneh Date: Sat, 15 Mar 2014 08:05:44 +0000 (-0700) Subject: Convert to a block X-Git-Tag: 1.31.0-rc.0~16334^2 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=b20f740e381d53da5a9d61f5df78b2949a82a383;p=lhc%2Fweb%2Fwiklou.git Convert to a block This patch replaces: With: In the default HTML output of MediaWiki. While the latter is a nearly twice as long, it is almost as readable for human beings, while being substantially easy to get via JavaScript. To get the values from the comment, you have to do something like: var comments, comment, hostname, duration; comments = $.grep( document.body.childNodes, function ( el ) { return el.nodeType === 8 } ); comment = comments.length ? comments.pop().nodeValue.match( /(\S+) in ([\d.]+)/ ).slice( 1 ) : [ null, null ]; hostname = comment[0]; respTime = parseFloat( comment[1] ); On the other hand, to get the values from the JavaScript code, you can simply: var hostname = mw.config.get( 'wgHostname' ); var respTime = mw.config.get( 'wgBackendResponseTime' ); I believe that the ability to parse the number easily via JavaScript will make it easier to include with other client-side measurements as part of reports on site performance as experienced by users. Change-Id: I895cd03f0968815484ff8cda4b23cc602ac555f0 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5174b321ec..cef19e12bb 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1817,19 +1817,23 @@ function wfHostname() { } /** - * Returns a HTML comment with the elapsed time since request. - * This method has no side effects. + * Returns a script tag that stores the amount of time it took MediaWiki to + * handle the request in milliseconds as 'wgBackendResponseTime'. + * + * If $wgShowHostnames is true, the script will also set 'wgHostname' to the + * hostname of the server handling the request. * * @return string */ function wfReportTime() { global $wgRequestTime, $wgShowHostnames; - $elapsed = microtime( true ) - $wgRequestTime; - - return $wgShowHostnames - ? sprintf( '', wfHostname(), $elapsed ) - : sprintf( '', $elapsed ); + $responseTime = round( ( microtime( true ) - $wgRequestTime ) * 1000 ); + $reportVars = array( 'wgBackendResponseTime' => $responseTime ); + if ( $wgShowHostnames ) { + $reportVars[ 'wgHostname' ] = wfHostname(); + } + return Skin::makeVariablesScript( $reportVars ); } /**