Brion VIBBER has uploaded a new change for review. https://gerrit.wikimedia.org/r/286523
Change subject: Whitelist rasterized SVG images for srcset density-responsive output ...................................................................... Whitelist rasterized SVG images for srcset density-responsive output SVG rasterizations are usually diagrams that compress well, and benefit more from the higher resolution output than photos do. Can add other types in $wgMFResponseImageWhitelist. Bug: T133496 Change-Id: Ib338198315b8c74133eac56be20603012b8f9a3f --- M extension.json M includes/MobileFrontend.hooks.php 2 files changed, 24 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/23/286523/1 diff --git a/extension.json b/extension.json index a21447d..ba96376 100644 --- a/extension.json +++ b/extension.json @@ -2063,7 +2063,11 @@ "@MinervaAlwaysShowLanguageButton": "Whether to show the language switcher button even if no languages are available for the page.", "MinervaAlwaysShowLanguageButton": true, "@MFStripResponsiveImages": "Whether to strip 'srcset' attributes from all images on mobile renderings. This can be used as a sort of brute-force bandwidth optimization at the cost of making images fuzzier on most devices.", - "MFStripResponsiveImages": false + "MFStripResponsiveImages": false, + "@MFResponseImageWhitelist": "Whitelist of thumbnail file extensions to retain srcset attributes on when using $wgMFStripResponsiveImages. Defaults to allow rasterized SVGs since they usually are diagrams that compress well and benefit from the higher resolution.", + "MFResponseImageWhitelist": [ + ".svg.png" + ] }, "manifest_version": 1 } diff --git a/includes/MobileFrontend.hooks.php b/includes/MobileFrontend.hooks.php index e7d342e..e32b55b 100644 --- a/includes/MobileFrontend.hooks.php +++ b/includes/MobileFrontend.hooks.php @@ -1306,13 +1306,26 @@ */ public static function onThumbnailBeforeProduceHTML( $thumbnail, &$attribs, &$linkAttribs ) { if ( MobileContext::singleton()->shouldDisplayMobileView() ) { - global $wgMFStripResponsiveImages; + global $wgMFStripResponsiveImages, $wgMFResponseImageWhitelist; if ( $wgMFStripResponsiveImages ) { - // Remove all responsive image 'srcset' attributes. - // Note that in future, srcset may be used for specifying - // small-screen-friendly image variants as well as density - // variants, so this should be used with caution. - unset( $attribs['srcset'] ); + $whitelisted = false; + $url = $thumbnail->getUrl(); + if ( is_string( $url ) ) { + foreach ( $wgMFResponseImageWhitelist as $ext ) { + $len = strlen( $ext ); + if ( substr_compare( $url, $ext, -$len, $len, /* case-insensitive */ true ) === 0 ) { + $whitelisted = true; + } + } + } + if ( !$whitelisted ) { + // Remove all responsive image 'srcset' attributes, except + // from SVG->PNG renderings which usually aren't too huge. + // Note that in future, srcset may be used for specifying + // small-screen-friendly image variants as well as density + // variants, so this should be used with caution. + unset( $attribs['srcset'] ); + } } } } -- To view, visit https://gerrit.wikimedia.org/r/286523 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib338198315b8c74133eac56be20603012b8f9a3f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits