From e83e1fc1eee3cc49e7a4c148396a7e4416c73f8c Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 19 Mar 2019 11:22:13 +0100 Subject: [PATCH] Add support for Element Timing API https://github.com/WICG/element-timing Bug: T216598 Change-Id: Ieda41f5074784957760c17dc15f7c891e56b6795 --- includes/DefaultSettings.php | 10 ++++++++++ includes/media/MediaTransformOutput.php | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 68d784614a..34b2796242 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index 87b4be7803..48ea4a510f 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -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'] ) ) { -- 2.20.1