Dr0ptp4kt has uploaded a new change for review.

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


Change subject: Don't show banners unless proxy is known to be zero-rated.
......................................................................

Don't show banners unless proxy is known to be zero-rated.

* The canonical X-Forwarded-By header will be used to determine any proxy.
* If the proxy is known to be zero-rated for a carrier, the banner will be 
shown.
* If the proxy isn't known to be zero-rated for a carrier, the banner will not 
be shown.
* If there is no X-Forwarded-By header, normal banner display rules will be 
used.

Change-Id: I7f4d02f7c3f054079c8f4a9f683f42a18c83b0a9
---
M includes/CarrierConfig.php
M includes/PageRenderingHooks.php
M includes/ZeroConfig.i18n.php
M includes/ZeroConfigContentHandler.php
4 files changed, 46 insertions(+), 1 deletion(-)


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

diff --git a/includes/CarrierConfig.php b/includes/CarrierConfig.php
index d107553..37a0462 100644
--- a/includes/CarrierConfig.php
+++ b/includes/CarrierConfig.php
@@ -285,6 +285,27 @@
                                        ? CarrierConfig::sortArray( $v ) : 
wfMessage( 'zeroconfig-lang_name_overrides' );
                        } );
 
+               //'proxies' => null,        // List of proxies where 
zero-rating established
+               $this->check( 'proxies', array(),
+                       function( $v ) {
+                               if ( CarrierConfig::isArray( $v, false )
+                                       && CarrierConfig::isArrayOfProxies( $v )
+                               ) {
+
+                                       if ( count( $v ) === 0 ) {
+                                               // This means no proxy support
+                                               return $v;
+                                       }
+
+                                       // Remove duplicates while preserving 
original order
+                                       $v = array_unique( $v );
+                                       ksort( $v );
+                                       return $v;
+                               }
+                               return wfMessage( 'zeroconfig-proxies' );
+                       } );
+
+
                // Background banner color
                $this->check( 'background', '#E31230', $validateStr );
 
@@ -307,6 +328,7 @@
 
                // If carrier supports zero-rating HTTPS traffic
                $this->check( 'enableHttps', false, $validateBool );
+
 
                // List of IP CIDR blocks for this provider
                if ( $this->thorough ) {
@@ -432,6 +454,11 @@
                return count( $arr ) === count( array_filter( $arr, $filter ) );
        }
 
+       // let's not be too fancy here. but let's also keep in mind this list 
and rules will grow
+       static function isArrayOfProxies( $arr ) {
+               return count( $arr ) === count( array_intersect( $arr, array( 
'-OPERA', '-TEST' ) ) );
+       }
+
        static function sortArray( $arr ) {
                // Sort so that the values are sorted alphabetically except 
'en' which will go as first
                uksort( $arr,
diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 5d4f0a6..1ccc4f3 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -685,6 +685,13 @@
                        // unless the configuration was specified with the X-CS 
request parameter
                        return false;
                }
+
+               // Check if proxy was used, and bail out if that proxy isn't 
free
+               $xfb = $this->request->getHeader( 'X-Forwarded-By' );
+               if ( $xfb && !in_array( $xfb, $config['proxies'] ) ) {
+                       return false;
+               }
+
                // Check if the wiki is in the allowed list
                // @FIXME: expand to allow non-wikipedia sites
                $site = $this->isZeroSubdomain ? 'zero.wikipedia' : 
'm.wikipedia';
diff --git a/includes/ZeroConfig.i18n.php b/includes/ZeroConfig.i18n.php
index c39900c..e28a709 100644
--- a/includes/ZeroConfig.i18n.php
+++ b/includes/ZeroConfig.i18n.php
@@ -31,6 +31,7 @@
        'zeroconfig-sites' => 'must be missing or be a list with one or more of 
these values: $1',
        'zeroconfig-ips' => 'must be an array of valid non-restricted (no 
private networks) CIDR IP blocks',
        'zeroconfig-admins' => 'must be a list of user accounts (optional)',
+       'zeroconfig-proxies' => 'must be a non-empty list of valid proxies 
(optional)',
 );
 
 /** Message documentation (Message documentation)
@@ -58,7 +59,8 @@
 ** {{msg-mw|Zeroconfig-banner url}}
 ** {{msg-mw|Zeroconfig-sites}}
 ** {{msg-mw|Zeroconfig-ips}}
-** {{msg-mw|Zeroconfig-admins}}',
+** {{msg-mw|Zeroconfig-admins}}
+** {{msg-mw|Zeroconfig-proxies}}',
        'zeroconfig-duplicate_field' => 'Field (<code>$1</code>) is present 
more than once in the JSON.
 
 Parameters:
@@ -108,6 +110,9 @@
        'zeroconfig-admins' => 'Admins parameter validation error.
 
 Used as <code>$2</code> in the message {{msg-mw|Zeroconfig-field error}}.',
+       'zeroconfig-proxies' => '"proxies" parameter is invalid.
+
+Used as <code>$2</code> in the message {{msg-mw|Zeroconfig-field error}}.',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/includes/ZeroConfigContentHandler.php 
b/includes/ZeroConfigContentHandler.php
index 3535927..66fb09a 100644
--- a/includes/ZeroConfigContentHandler.php
+++ b/includes/ZeroConfigContentHandler.php
@@ -78,6 +78,12 @@
         // Neither of these two private CIDR ranges are legal
         "192.168.0.0/16",
         "10.0.0.0/8",
+    ],
+    "proxies": [
+        "-OPERA"
+        // Optional. If not defined: no proxy zero-rating.
+        // Otherwise, must be defined as array with elements
+        // matching proxies with NS_ZERO configurations.
     ]
 }
 EOD;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f4d02f7c3f054079c8f4a9f683f42a18c83b0a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to