From 8e11c5dabc56f5bc0127054ae65735cbfcc62258 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Wed, 20 Feb 2019 15:06:36 +0100 Subject: [PATCH] Add Priority Hints support When the option is enabled, the first non-icon thumbnail encountered has a "high" importance. Bug: T216499 Change-Id: I8d3c1b3e2d136ba16bd7de4809ee3ca63ab462fe --- includes/DefaultSettings.php | 10 ++++++++++ includes/media/MediaTransformOutput.php | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1761b00778..717b7b67a5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -9027,6 +9027,16 @@ $wgEnableBlockNoticeStats = false; */ $wgOriginTrials = []; +/** + * Enable client-side Priority Hints. + * + * @warning EXPERIMENTAL! + * + * @since 1.34 + * @var bool + */ +$wgPriorityHints = 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 12048a9012..34f7e8cb76 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -275,6 +275,8 @@ abstract class MediaTransformOutput { * @ingroup Media */ class ThumbnailImage extends MediaTransformOutput { + private static $firstNonIconImageRendered = false; + /** * Get a thumbnail object from a file and parameters. * If $path is set to null, the output file is treated as a source copy. @@ -356,6 +358,8 @@ class ThumbnailImage extends MediaTransformOutput { * @return string */ function toHtml( $options = [] ) { + global $wgPriorityHints; + if ( count( func_get_args() ) == 2 ) { throw new MWException( __METHOD__ . ' called in the old style' ); } @@ -370,6 +374,14 @@ class ThumbnailImage extends MediaTransformOutput { 'decoding' => 'async', ]; + if ( $wgPriorityHints + && !self::$firstNonIconImageRendered + && $this->width * $this->height > 100 * 100 ) { + self::$firstBigImageRendered = true; + + $attribs['importance'] = 'high'; + } + if ( !empty( $options['custom-url-link'] ) ) { $linkAttribs = [ 'href' => $options['custom-url-link'] ]; if ( !empty( $options['title'] ) ) { -- 2.20.1