Add Priority Hints support
authorGilles Dubuc <gilles@wikimedia.org>
Wed, 20 Feb 2019 14:06:36 +0000 (15:06 +0100)
committerGilles Dubuc <gilles@wikimedia.org>
Mon, 25 Feb 2019 17:14:59 +0000 (18:14 +0100)
When the option is enabled, the first non-icon
thumbnail encountered has a "high" importance.

Bug: T216499
Change-Id: I8d3c1b3e2d136ba16bd7de4809ee3ca63ab462fe

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

index 1761b00..717b7b6 100644 (file)
@@ -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
index 12048a9..34f7e8c 100644 (file)
@@ -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'] ) ) {