Merge "Add Priority Hints support"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Feb 2019 20:31:59 +0000 (20:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Feb 2019 20:31:59 +0000 (20:31 +0000)
includes/DefaultSettings.php
includes/media/MediaTransformOutput.php

index dc61382..93113df 100644 (file)
@@ -9045,6 +9045,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'] ) ) {