Dr0ptp4kt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/129578

Change subject: Redirect users to upload.wikimedia.org for direct links if okay.
......................................................................

Redirect users to upload.wikimedia.org for direct links if okay.

* Currently, users on File: pages are getting unnecessary warnings.
* But if operator supports interstitial-less mdot, this redirects automatically.
* If operator uses interstitial-based mdot, this still prompts.

Change-Id: I3e84a1012ced1a52a91f11278d9f114bb1aa4754
---
M includes/PageRenderingHooks.php
M modules/interstitial.js
2 files changed, 24 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/78/129578/1

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 2dd3733..f12cfa8 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -820,6 +820,8 @@
                                        } else {
                                                $redir = true; // there is no 
language, but the site is whitelisted, so don't warn
                                        }
+                               } elseif ( $toHost === 'upload.wikimedia.org' 
&& $config['showImages'] ) {
+                                       $redir = true;
                                }
                        }
                        // else - external link, always warn
diff --git a/modules/interstitial.js b/modules/interstitial.js
index 7c539c5..36d6952 100644
--- a/modules/interstitial.js
+++ b/modules/interstitial.js
@@ -63,11 +63,14 @@
                 showWarning, // true if a warning page should be shown
                 toUrl, // target URL of the link
                 toAsAnchor, // target URL as a DOM <a> object
-                toHostParts, // hostname part of the URL
+                toHostParts, // hostname parts of the URL
+                toHostname, // hostname of of the URL
                 toLang = false, // language of the destination site
                 toSite = false, // non-language specific name of the site, 
e.g. "m.wikipedia"
                 isLocal, // true if the target is a link to the current site
-                isHttpsSwitch; // true if the link would switch from http to 
https
+                isHttpsSwitch, // true if the link would switch from http to 
https
+                isFreeLookingUploadDotLink, // whether the interstitial points 
at upload.wikimedia.org
+                isFreeProtocol; // whether the interstitial points at a 
protocol that's free
 
             if ( $target.attr( 'id' ) === 'mw-mf-last-modified' ) {
                 isSpecialCase = true;
@@ -99,7 +102,7 @@
                 // Use a DOM anchor trick to parse target URL
                 toAsAnchor = $( '<a>', { href: toUrl } )[0];
                 if ( toAsAnchor.hostname ) {
-                    toHostParts = toAsAnchor.hostname.toLowerCase();
+                    toHostname = toHostParts = 
toAsAnchor.hostname.toLowerCase();
                     isLocal = toHostParts === hostname;
                 } else {
                     toHostParts = hostname;
@@ -110,13 +113,18 @@
                     toLang = toHostParts[0];
                     toSite = toHostParts[1] + '.' + toHostParts[2];
                 }
-                if ( !isLocal && ( !toSite || $.inArray( toSite, knownSites ) 
=== -1 ) ) {
+
+                isHttpsSwitch = !isHttps && toAsAnchor.protocol === 'https:';
+                isFreeProtocol = !isHttpsSwitch || supportsTls;
+                isFreeLookingUploadDotLink = isFreeProtocol && toHostname === 
'upload.wikimedia.org';
+
+                if ( isFreeLookingUploadDotLink ) {
+                    // This is a link to upload.wikimedia.org, so must be 
handled below.
+                    // Why? Sometimes configs support mdot, but dissuade with 
warnings.
+                } else if ( !isLocal && ( !toSite || $.inArray( toSite, 
knownSites ) === -1 ) ) {
                     showWarning = true; // Navigating to an unknown site
-                } else {
-                    isHttpsSwitch = !isHttps && toAsAnchor.protocol === 
'https:';
-                    if ( isLocal && !isImage && ( !isHttpsSwitch || 
supportsTls ) ) {
-                        showWarning = false; // This is a local link to a 
non-image page
-                    }
+                } else if ( isLocal && !isImage && isFreeProtocol ) {
+                    showWarning = false; // This is a local link to a 
non-image page
                 }
             }
 
@@ -140,7 +148,9 @@
                     var showWarning;
                     if ( !conf.enabled ) {
                         showWarning = false;
-                    } else if ( !isLocal ) {
+                    } else if ( isFreeLookingUploadDotLink ) {
+                        showWarning = !conf.showImages;
+                    }  else if ( !isLocal ) {
                         // The logical construct here is "should we navigate 
without asking" and inverting that.
                         showWarning = !(
                             ( conf.whitelistedLangs &&
@@ -149,10 +159,10 @@
                                 ( conf.sites &&
                                     ( conf.sites.length === 0 ||
                                         $.inArray( toSite, conf.sites ) !== -1 
) ) &&
-                                ( !isHttpsSwitch || conf.enableHttps )
+                                ( isFreeProtocol )
                             );
                     } else {
-                        // link to an image
+                        // local link to an image
                         showWarning = !conf.showImages;
                     }
                     navigate( showWarning );

-- 
To view, visit https://gerrit.wikimedia.org/r/129578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e84a1012ced1a52a91f11278d9f114bb1aa4754
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to