jenkins-bot has submitted this change and it was merged.

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, 39 insertions(+), 27 deletions(-)

Approvals:
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 2dd3733..f1bd855 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;
+               $redir = false; // true if silent redirect, false for the 
warning
                $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,19 +806,21 @@
                }
                if ( $toHost ) {
                        // Check http->https switch and match 
(optional-language.)(subdomain.site).org
-                       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
+                       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
+                                               }
                                        }
                                }
                        }
diff --git a/modules/interstitial.js b/modules/interstitial.js
index 7c539c5..a1af435 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
+                toHostname, // hostname of of the URL
+                toHostParts, // hostname parts 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,24 +102,29 @@
                 // Use a DOM anchor trick to parse target URL
                 toAsAnchor = $( '<a>', { href: toUrl } )[0];
                 if ( toAsAnchor.hostname ) {
-                    toHostParts = toAsAnchor.hostname.toLowerCase();
-                    isLocal = toHostParts === hostname;
+                    toHostname = toAsAnchor.hostname.toLowerCase();
+                    isLocal = toHostname === hostname;
                 } else {
-                    toHostParts = hostname;
+                    toHostname = hostname;
                     isLocal = true;
                 }
-                toHostParts = toHostParts.split( '.', 3 );
+                toHostParts = toHostname.split( '.', 3 );
                 if ( toHostParts.length >= 3 ) {
                     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,6 +148,8 @@
                     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 = !(
@@ -152,7 +162,7 @@
                                 ( !isHttpsSwitch || conf.enableHttps )
                             );
                     } 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: merged
Gerrit-Change-Id: I3e84a1012ced1a52a91f11278d9f114bb1aa4754
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org>
Gerrit-Reviewer: Dfoy <d...@wikimedia.org>
Gerrit-Reviewer: Dr0ptp4kt <ab...@wikimedia.org>
Gerrit-Reviewer: Yurik <yu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to