skins: Remove redundant mediawiki.hidpi script
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 23 Jun 2018 23:30:18 +0000 (00:30 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 25 Jun 2018 17:17:16 +0000 (17:17 +0000)
This is an internal script automatically loaded by Skin.php to
activate the 'jquery.hidpi' polyfill for all images on the current
page in browsers that don't natively support the 'srcset' attribute
on the HTML img element.

This script is loaded via ResourceLoader for which Grade A currently
requires:
> IE11+/Edge, Chr 65+, Ff 52+, Saf 5+, Op 15+, iOS 6+, Android 4+.

According to MDN and CanIUse, the basic 'x' syntax of srcset is supported, and
enabled by default, in:
> Edge, Chr 34+, Ff 38+, Saf 7+, Op 21+, iOS 8+, Android 5+.

This means in the following browsers, MediaWiki will no longer attempt to
replace images in articles with their hidpi versions.

| Browser                | analytics.wikimedia.org (22 May - 22 June)
| ---------------------- | -----------------------
| IE 11 on Windows <= 7  | 3.4% (OS does not support HiDPI)
| IE 11 on Windows 8+    | 1.1%
| Safari 5 & 6 (desktop) | <0.1%
| Opera 15-20 (desktop)  | <0.1%
| iOS 6 & 7 (mobile)     | 0.1%
| Android 4 (mobile)     | 0.5%

While the total of 1.7% is higher than our usual point where we decide
to remove support, I think we should consider dropping the hidpi polyfill
still for several reasons:

* MobileFrontend no longer uses 'srcset' attributes. As such, these browsers
  don't actually change their behaviour based on the polyfill.

* For IE 11/Win8 in particular, most users don't have an HiDPI monitor,
  but we still download the polyfill. HiDPI on Win8 is primarily tablets.

* In all cases where the polyfill activates, we download the HiDPI images
  in addition to the standard resolution (which downloads and renders first).
  This is because client-side JavaScript is not able to replace it sooner.
  This could be considered a waste of bandwidth, as it can double or tripple
  the bandwidth cost for end users.
  This also means pages complete their loading much later because the browser
  first renders the page nearly to completion with standard resolution images,
  and only at the end our polyfill activates to restarts all image loading.

The experience gracefully falls back to normal web rendering, where the standard
resolution of the image is used. This would match what users of these devices
see on other websites, given client-side emulation of srcset is fairly rare.

== Modules

The 'mediawiki.hidpi' module was removed, and considered internal to Skin.php.
It contained no public methods. I confirmed there were no matches in Codesearch,
and no matches in mwgrep on Wikimedia wikis.

I did not remove 'jquery.hidpi', which is what contains the actual polyfill
and the jQuery.fn.hidpi() public method. (Codesearch shows 2 extenisons using
it, and mwgrep returned 1 unused gadget on Meta-Wiki referencing it).
It has been kept, but marked as deprecated. To be removed in a future release.

Bug: T127328
Change-Id: I42ce0feea1fbfe534f00e05a7cd8d81df0c33d8f

Gruntfile.js
RELEASE-NOTES-1.32
includes/DefaultSettings.php
includes/skins/Skin.php
resources/Resources.php
resources/src/mediawiki.hidpi/hidpi.js [deleted file]
resources/src/mediawiki.hidpi/skip.js [deleted file]

index 8018212..6be908e 100644 (file)
@@ -33,9 +33,7 @@ module.exports = function ( grunt ) {
                                '!vendor/**',
                                // Explicitly say "**/*.js" here in case of symlinks
                                '!extensions/**/*.js',
-                               '!skins/**/*.js',
-                               // Skip functions aren't even parseable
-                               '!resources/src/mediawiki.hidpi/skip.js'
+                               '!skins/**/*.js'
                        ]
                },
                jsonlint: {
index c4a8fef..3c60124 100644 (file)
@@ -218,6 +218,7 @@ because of Phabricator reports.
 * (T176526) EditPage::getContextTitle() falling back to $wgTitle when the
   context title is unset is now deprecated; anything creating an EditPage
   instance should set the context title via ::setContextTitle().
+* The 'jquery.hidpi' module (polyfill for IMG srcset) is deprecated.
 
 === Other changes in 1.32 ===
 * …
index 2c98283..8b25672 100644 (file)
@@ -1500,10 +1500,6 @@ $wgDirectoryMode = 0777;
  *
  * This means a 320x240 use of an image on the wiki will also generate 480x360 and 640x480
  * thumbnails, output via the srcset attribute.
- *
- * On older browsers, a JavaScript polyfill switches the appropriate images in after loading
- * the original low-resolution versions depending on the reported window.devicePixelRatio.
- * The polyfill can be found in the jquery.hidpi module.
  */
 $wgResponsiveImages = true;
 
index 8384ca0..51be3b6 100644 (file)
@@ -212,11 +212,6 @@ abstract class Skin extends ContextSource {
                        'syndicate' => [],
                ];
 
-               // Support for high-density display images if enabled
-               if ( $config->get( 'ResponsiveImages' ) ) {
-                       $modules['core'][] = 'mediawiki.hidpi';
-               }
-
                // Preload jquery.tablesorter for mediawiki.page.ready
                if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
                        $modules['content'][] = 'jquery.tablesorter';
index 1b6eed3..44b028d 100644 (file)
@@ -228,6 +228,7 @@ return [
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'jquery.hidpi' => [
+               'deprecated' => 'Use of the srcset polyfill is deprecated since MediaWiki 1.32.0',
                'scripts' => 'resources/src/jquery/jquery.hidpi.js',
                'targets' => [ 'desktop', 'mobile' ],
        ],
@@ -1051,12 +1052,6 @@ return [
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
-       'mediawiki.hidpi' => [
-               'scripts' => 'resources/src/mediawiki.hidpi/hidpi.js',
-               'dependencies' => 'jquery.hidpi',
-               'skipFunction' => 'resources/src/mediawiki.hidpi/skip.js',
-               'targets' => [ 'desktop', 'mobile' ],
-       ],
        'mediawiki.hlist' => [
                'targets' => [ 'desktop', 'mobile' ],
                'styles' => [
diff --git a/resources/src/mediawiki.hidpi/hidpi.js b/resources/src/mediawiki.hidpi/hidpi.js
deleted file mode 100644 (file)
index ecee450..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-jQuery( function ( $ ) {
-       // Apply hidpi images on DOM-ready
-       // Some may have already partly preloaded at low resolution.
-       $( 'body' ).hidpi();
-} );
diff --git a/resources/src/mediawiki.hidpi/skip.js b/resources/src/mediawiki.hidpi/skip.js
deleted file mode 100644 (file)
index 26b63c7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/*!
- * Skip function for mediawiki.hdpi.js.
- */
-return 'srcset' in new Image();