Yurik has uploaded a new change for review.

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

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

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

Lots of issues surfaced from http://*.zero.* to https://... redirection 
(invalid cert).

This reverts commit b2b6d3f2257b9a5983d7eb6471db373e05311c49.

Change-Id: I582bf42a3ba1f7306286e332de16d1933526b53a
---
M includes/PageRenderingHooks.php
M modules/interstitial.js
2 files changed, 27 insertions(+), 39 deletions(-)


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

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index f1bd855..2dd3733 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -792,7 +792,7 @@
                        return array( 'softredirect' => $toUrl );
                }
                $fromUrl = MobileContext::singleton()->getMobileUrl( 
$fromTitle->getFullURL() );
-               $redir = false; // true if silent redirect, false for the 
warning
+               $redir = false;
                $urlBits = wfParseUrl( $toUrl );
                $toHost = is_array( $urlBits ) && array_key_exists( 'host', 
$urlBits ) ? $urlBits['host'] : false;
                $toScheme = is_array( $urlBits ) && array_key_exists( 'scheme', 
$urlBits ) ? $urlBits['scheme'] : false;
@@ -806,21 +806,19 @@
                }
                if ( $toHost ) {
                        // Check http->https switch and match 
(optional-language.)(subdomain.site).org
-                       if ( $toScheme !== 'https' || $config['enableHttps'] ) {
-                               if ( $toHost === 'upload.wikimedia.org' && 
$config['showImages'] ) {
-                                       $redir = true;
-                               } elseif ( preg_match( 
'/^([^.]+\.)?([^.]+\.[^.]+)\.org$/', $toHost, $matches ) ) {
-                                       // Another language in wikipedia
-                                       $lang = $matches[1];
-                                       $site = $matches[2];
-                                       // see if the site is whitelisted, and 
if it is, make sure the language is.
-                                       if ( in_array( $site, $config['sites'] 
) ) {
-                                               if ( $lang ) {
-                                                       $freeLangs = 
$config['whitelistedLangs'];
-                                                       $redir = count( 
$freeLangs ) == 0 || in_array( rtrim( $lang, '.' ), $freeLangs );
-                                               } else {
-                                                       $redir = true; // there 
is no language, but the site is whitelisted, so don't warn
-                                               }
+                       if ( ( $toScheme !== 'https' || $config['enableHttps'] 
) &&
+                               preg_match( 
'/^([^.]+\.)?([^.]+\.[^.]+)\.org$/', $toHost, $matches )
+                       ) {
+                               // Another language in wikipedia
+                               $lang = $matches[1];
+                               $site = $matches[2];
+                               // see if the site is whitelisted, and if it 
is, make sure the language is.
+                               if ( in_array( $site, $config['sites'] ) ) {
+                                       if ( $lang ) {
+                                               $freeLangs = 
$config['whitelistedLangs'];
+                                               $redir = count( $freeLangs ) == 
0 || in_array( rtrim( $lang, '.' ), $freeLangs );
+                                       } else {
+                                               $redir = true; // there is no 
language, but the site is whitelisted, so don't warn
                                        }
                                }
                        }
diff --git a/modules/interstitial.js b/modules/interstitial.js
index a1af435..7c539c5 100644
--- a/modules/interstitial.js
+++ b/modules/interstitial.js
@@ -63,14 +63,11 @@
                 showWarning, // true if a warning page should be shown
                 toUrl, // target URL of the link
                 toAsAnchor, // target URL as a DOM <a> object
-                toHostname, // hostname of of the URL
-                toHostParts, // hostname parts of the URL
+                toHostParts, // hostname part 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
-                isFreeLookingUploadDotLink, // whether the interstitial points 
at upload.wikimedia.org
-                isFreeProtocol; // whether the interstitial points at a 
protocol that's free
+                isHttpsSwitch; // true if the link would switch from http to 
https
 
             if ( $target.attr( 'id' ) === 'mw-mf-last-modified' ) {
                 isSpecialCase = true;
@@ -102,29 +99,24 @@
                 // Use a DOM anchor trick to parse target URL
                 toAsAnchor = $( '<a>', { href: toUrl } )[0];
                 if ( toAsAnchor.hostname ) {
-                    toHostname = toAsAnchor.hostname.toLowerCase();
-                    isLocal = toHostname === hostname;
+                    toHostParts = toAsAnchor.hostname.toLowerCase();
+                    isLocal = toHostParts === hostname;
                 } else {
-                    toHostname = hostname;
+                    toHostParts = hostname;
                     isLocal = true;
                 }
-                toHostParts = toHostname.split( '.', 3 );
+                toHostParts = toHostParts.split( '.', 3 );
                 if ( toHostParts.length >= 3 ) {
                     toLang = toHostParts[0];
                     toSite = toHostParts[1] + '.' + toHostParts[2];
                 }
-
-                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 ) ) {
+                if ( !isLocal && ( !toSite || $.inArray( toSite, knownSites ) 
=== -1 ) ) {
                     showWarning = true; // Navigating to an unknown site
-                } else if ( isLocal && !isImage && isFreeProtocol ) {
-                    showWarning = false; // This is a local link to a 
non-image page
+                } else {
+                    isHttpsSwitch = !isHttps && toAsAnchor.protocol === 
'https:';
+                    if ( isLocal && !isImage && ( !isHttpsSwitch || 
supportsTls ) ) {
+                        showWarning = false; // This is a local link to a 
non-image page
+                    }
                 }
             }
 
@@ -148,8 +140,6 @@
                     var showWarning;
                     if ( !conf.enabled ) {
                         showWarning = false;
-                    } else if ( isFreeLookingUploadDotLink ) {
-                        showWarning = !conf.showImages;
                     } else if ( !isLocal ) {
                         // The logical construct here is "should we navigate 
without asking" and inverting that.
                         showWarning = !(
@@ -162,7 +152,7 @@
                                 ( !isHttpsSwitch || conf.enableHttps )
                             );
                     } else {
-                        // local link to an image
+                        // link to an image
                         showWarning = !conf.showImages;
                     }
                     navigate( showWarning );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I582bf42a3ba1f7306286e332de16d1933526b53a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <yu...@wikimedia.org>

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

Reply via email to