From: Gilles Dubuc Date: Wed, 20 Feb 2019 14:06:36 +0000 (+0100) Subject: Add Priority Hints support X-Git-Tag: 1.34.0-rc.0~2723^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=8e11c5dabc56f5bc0127054ae65735cbfcc62258;p=lhc%2Fweb%2Fwiklou.git Add Priority Hints support When the option is enabled, the first non-icon thumbnail encountered has a "high" importance. Bug: T216499 Change-Id: I8d3c1b3e2d136ba16bd7de4809ee3ca63ab462fe --- 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'] ) ) {