Ori.livneh has uploaded a new change for review.

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

Change subject: Decode geolocation data from GeoIP cookie, if present
......................................................................

Decode geolocation data from GeoIP cookie, if present

* Remove 'Geo' global configuration variable. It was never a configuration
  variable, but rather a way of injecting a blank object into global scope so
  property lookups on window.Geo don't throw ReferenceErrors.
* Instead, if window.Geo is unset at the top of bannerController.js, attempt to
  parse geolocation data from GeoIP cookie.
* If the cookie is not present, a blank GeoIP object is created.
* While we're waiting for the cookie to roll out to production, the
  <script src="//bits.wikimedia.org/geoiplookup"></script> tag will continue to
  override the blank object with actual GeoIP data.
* Once the GeoIP is rolled out to production, we'll remove the <script> tag.
* The GeoIP cookie is currently being set on the beta cluster.

Change-Id: I1a08c81da7a6ad7e92ab501d4e2ee908fed7be38
(cherry picked from commit 8f948c937b3fcccb371673eae6362d3d4ffcaa98)
---
M CentralNotice.hooks.php
M modules/ext.centralNotice.bannerController/bannerController.js
2 files changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/80/116880/1

diff --git a/CentralNotice.hooks.php b/CentralNotice.hooks.php
index 66ccbbd..b795de9 100644
--- a/CentralNotice.hooks.php
+++ b/CentralNotice.hooks.php
@@ -205,10 +205,6 @@
        // Using global $wgUser for compatibility with 1.18
        global $wgNoticeProject, $wgUser, $wgMemc;
 
-       // Initialize global Javascript variables. We initialize Geo with empty 
values so if the geo
-       // IP lookup fails we don't have any surprises.
-       $geo = array( 'city' => '', 'country' => '' );
-       $vars[ 'Geo' ] = $geo; // change this to wgGeo if Ops updates the 
variable name on their end
        $vars[ 'wgNoticeProject' ] = $wgNoticeProject;
 
        // Output the user's registration date, total edit count, and past 
year's edit count.
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index 9d0a0ae..a86dd93 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -36,6 +36,12 @@
                }
        }
 
+       if ( typeof window.Geo !== 'object' ) {
+               window.Geo = ( function ( match, country, city, lat, lon, af ) {
+                       return { country: country, city: city, lat: lat, lon: 
lon, af: af };
+               } ).apply( null, document.cookie.match( 
/(?:\bGeoIP=)([^:]*):([^:]*):([^:]*):([^:]*):([^;]*)/ ) );
+       }
+
        mw.centralNotice = {
                /**
                 * Central Notice Required Data

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a08c81da7a6ad7e92ab501d4e2ee908fed7be38
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: wmf_deploy
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>

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

Reply via email to