Gilles has uploaded a new change for review.

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

Change subject: Parse older format of Geo cookies
......................................................................

Parse older format of Geo cookies

As they are likely to stay cached in people's sessions for a while

Bug: T103720
Change-Id: I6ffdc977e87176b55ecdf8bf87992805184a29ad
---
M modules/ext.centralNotice.bannerController/bannerController.js
1 file changed, 20 insertions(+), 2 deletions(-)


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

diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index 99e6367..fca9925 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -55,7 +55,7 @@
                $.cookie( 'GeoIP', parts.join( ':' ), { path: '/' } );
        }
 
-       window.Geo = ( function ( match, country, region, city, lat, lon, af ) {
+       function sanitizeGeoCookie( match, country, region, city, lat, lon, af 
) {
                if ( typeof country !== 'string' || ( country.length !== 0 && 
country.length !== 2 ) ) {
                    // 'country' is neither empty nor a country code (string of
                    // length 2), so something is wrong with the cookie, and we
@@ -68,6 +68,7 @@
                    lon = '';
                    af = 'vx';
                }
+
                return {
                        country: country,
                        region: region,
@@ -76,7 +77,24 @@
                        lon: lon && parseFloat( lon ),
                        af: af
                };
-       } ).apply( null, ( $.cookie( 'GeoIP' ) || '' ).match( 
/([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^;]*)/ ) || [] );
+       }
+
+       function parseGeoCookie() {
+               var geoCookie = $.cookie( 'GeoIP' ) || '',
+                       geoCookieMatches = geoCookie.match( 
/([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^;]*)/ )
+                               || geoCookie.match( 
/([^:]*):([^:]*):([^:]*):([^:]*):([^;]*)/ )
+                               || [];
+
+               // When encountering the old cookie format, convert it to the 
new one with an empty region
+               if ( geoCookieMatches.length === 6 ) {
+                       // Region field is missing, insert an empty one
+                       geoCookieMatches = geoCookieMatches.slice( 0, 2 
).concat( [ '' ] ).concat( geoCookieMatches.slice( 2 ) );
+               }
+
+               window.Geo = sanitizeGeoCookie.apply( null, geoCookieMatches );
+       }
+
+       parseGeoCookie();
 
        // FIXME Following the switch to client-side banner selection, it would
        // make more sense for this to be defined in bannerController.lib. 
Before

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ffdc977e87176b55ecdf8bf87992805184a29ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>

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

Reply via email to