[MediaWiki-commits] [Gerrit] Redirect users to upload.wikimedia.org for direct links if o... - change (mediawiki...ZeroRatedMobileAccess)

2014-04-30 Thread jenkins-bot (Code Review)
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
+

[MediaWiki-commits] [Gerrit] Redirect users to upload.wikimedia.org for direct links if o... - change (mediawiki...ZeroRatedMobileAccess)

2014-04-24 Thread Dr0ptp4kt (Code Review)
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 ) {