Add support for Element Timing API
authorGilles Dubuc <gilles@wikimedia.org>
Tue, 19 Mar 2019 10:22:13 +0000 (11:22 +0100)
committerGilles Dubuc <gilles@wikimedia.org>
Wed, 20 Mar 2019 08:54:02 +0000 (09:54 +0100)
https://github.com/WICG/element-timing

Bug: T216598
Change-Id: Ieda41f5074784957760c17dc15f7c891e56b6795

includes/DefaultSettings.php
includes/media/MediaTransformOutput.php

index 68d7846..34b2796 100644 (file)
@@ -9041,6 +9041,16 @@ $wgOriginTrials = [];
  */
 $wgPriorityHints = false;
 
+/**
+ * Enable Element Timing.
+ *
+ * @warning EXPERIMENTAL!
+ *
+ * @since 1.34
+ * @var bool
+ */
+$wgElementTiming = false;
+
 /**
  * For really cool vim folding this needs to be at the end:
  * vim: foldmarker=@{,@} foldmethod=marker
index 87b4be7..48ea4a5 100644 (file)
@@ -358,7 +358,7 @@ class ThumbnailImage extends MediaTransformOutput {
         * @return string
         */
        function toHtml( $options = [] ) {
-               global $wgPriorityHints;
+               global $wgPriorityHints, $wgElementTiming;
 
                if ( count( func_get_args() ) == 2 ) {
                        throw new MWException( __METHOD__ . ' called in the old style' );
@@ -374,12 +374,19 @@ class ThumbnailImage extends MediaTransformOutput {
                        'decoding' => 'async',
                ];
 
+               $elementTimingName = 'thumbnail';
+
                if ( $wgPriorityHints
                        && !self::$firstNonIconImageRendered
                        && $this->width * $this->height > 100 * 100 ) {
                        self::$firstNonIconImageRendered = true;
 
                        $attribs['importance'] = 'high';
+                       $elementTimingName = 'thumbnail-high';
+               }
+
+               if ( $wgElementTiming ) {
+                       $attribs['elementtiming'] = $elementTimingName;
                }
 
                if ( !empty( $options['custom-url-link'] ) ) {