Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/118810

Change subject: Convert <!-- timing data --> to <script></script> block
......................................................................

Convert <!-- timing data --> to <script></script> block

This patch replaces:

  <!-- Served by mw1069 in 0.976 secs. -->

With:

  <script>mw.config.set({"wgreqtime":0.976,"wghostname":"mw1069"});</script>

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];
  reqTime = 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 reqTime = mw.config.get( 'wgReqTime' );

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
---
M includes/GlobalFunctions.php
1 file changed, 7 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/10/118810/1

diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index a6f936f..4f953c6 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -1801,19 +1801,19 @@
 }
 
 /**
- * Returns a HTML comment with the elapsed time since request.
- * This method has no side effects.
+ * Returns a script tag that stores the start and end of the request processing
+ * time as the JavaScript configuration variables 'wgReqStart' and 'wgReqEnd'.
  *
  * @return string
  */
 function wfReportTime() {
        global $wgRequestTime, $wgShowHostnames;
 
-       $elapsed = microtime( true ) - $wgRequestTime;
-
-       return $wgShowHostnames
-               ? sprintf( '<!-- Served by %s in %01.3f secs. -->', 
wfHostname(), $elapsed )
-               : sprintf( '<!-- Served in %01.3f secs. -->', $elapsed );
+       $timing = array( 'wgReqTime' => round( microtime( true ) - 
$wgRequestTime, 3 ) );
+       if ( $wgShowHostnames ) {
+               $timing[ 'wgHostname' ] = wfHostname();
+       }
+       return '<script>' . Xml::encodeJsCall( 'mw.config.set', array( $timing 
) ) . '</script>';
 }
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/118810
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I895cd03f0968815484ff8cda4b23cc602ac555f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to