Add support for native image lazy loading
authorGilles Dubuc <gilles@wikimedia.org>
Wed, 21 Aug 2019 09:04:45 +0000 (11:04 +0200)
committerGilles Dubuc <gilles@wikimedia.org>
Wed, 21 Aug 2019 09:07:42 +0000 (11:07 +0200)
Bug: T230897
Depends-On: I6c0b01fafe2c4498852e9c9b81151aba759dc5eb
Change-Id: I0307563b8f433dab062effe4dbfd7d4a9bbb8764

includes/DefaultSettings.php
includes/media/ThumbnailImage.php

index 98ffe71..0b14e56 100644 (file)
@@ -9108,6 +9108,16 @@ $wgFeaturePolicyReportOnly = [];
  */
 $wgSpecialSearchFormOptions = [];
 
+/**
+ * Toggles native image lazy loading, via the "loading" attribute.
+ *
+ * @warning EXPERIMENTAL!
+ *
+ * @since 1.34
+ * @var array
+ */
+$wgNativeImageLazyLoading = false;
+
 /**
  * For really cool vim folding this needs to be at the end:
  * vim: foldmarker=@{,@} foldmethod=marker
index 7ee6dcb..6e4412c 100644 (file)
@@ -110,7 +110,7 @@ class ThumbnailImage extends MediaTransformOutput {
         * @return string
         */
        function toHtml( $options = [] ) {
-               global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming;
+               global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming, $wgNativeImageLazyLoading;
 
                if ( func_num_args() == 2 ) {
                        throw new MWException( __METHOD__ . ' called in the old style' );
@@ -126,6 +126,10 @@ class ThumbnailImage extends MediaTransformOutput {
                        'decoding' => 'async',
                ];
 
+               if ( $wgNativeImageLazyLoading ) {
+                       $attribs['loading'] = 'lazy';
+               }
+
                $elementTimingName = 'thumbnail';
 
                if ( $wgPriorityHints