Yurik has uploaded a new change for review.

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


Change subject: Unified default language redirect from m. & zero.
......................................................................

Unified default language redirect from m. & zero.

DO NOT MERGE just yet

* Default language for the carrier is now set in one location

There might be some issues with the new logic, need dfoy & brion's review:

* Old code redirected m.wiki to en.m.wiki + req.url for m.wiki instead of 
Special:ZeroRatedMobileAccess
* Old code did NOT redirect unknown zero.wiki to en.zero.wiki
* Are there any issues with using canonical word "Special" instead of the 
localized one?
* Can it/should it redirect to "//" instead of "http://"; (keep schema)
* What should be redirect behavior for mobile.wikipedia.org

Change-Id: Ifda2dcabaa08f5df7b22b3b1d726f21882bbca36
---
M templates/varnish/mobile-frontend.inc.vcl.erb
1 file changed, 35 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/02/55302/1

diff --git a/templates/varnish/mobile-frontend.inc.vcl.erb 
b/templates/varnish/mobile-frontend.inc.vcl.erb
index 0d0e2d0..82f6675 100644
--- a/templates/varnish/mobile-frontend.inc.vcl.erb
+++ b/templates/varnish/mobile-frontend.inc.vcl.erb
@@ -265,6 +265,9 @@
                set req.http.X-Subdomain = "M";
        }
 
+       // go to english by default
+       set req.http.X-DfltLang = "en";
+
        /* Please keep this list alphabetized by the ACL variable */
        if (client.ip ~ carrier_celcom_malaysia) {
                if (req.http.X-Subdomain == "ZERO") {
@@ -284,11 +287,13 @@
                        }
                }
        } else if (client.ip ~ carrier_dtac) {
+               set req.http.X-DfltLang = "th";
                if (req.http.X-Subdomain == "ZERO") {
                        set req.http.X-Carrier = "DTAC";
                        set req.http.X-CS = "520-18";
                }
        } else if (client.ip ~ carrier_grameenphone_bangladesh) {
+               set req.http.X-DfltLang = "bn";
                if (req.http.X-Subdomain == "ZERO") {
                        if (req.http.host ~ 
"(^(bn)\.zero|^zero)\.([a-zA-Z0-9-]+)\.org") {
                                set req.http.X-Carrier = "Grameenphone 
Bangladesh";
@@ -306,6 +311,7 @@
                        set req.http.X-CS = "652-02";
                }
        } else if (client.ip ~ carrier_orange_cameroon) {
+               set req.http.X-DfltLang = "fr";
                if (req.http.X-Subdomain == "M") {
                        if (req.http.host ~ 
"(^(fr|en|es|de|zh|ar|ha|ln|yo|eo)\.m|^m)\.([a-zA-Z0-9-]+)\.org") {
                                set req.http.X-Carrier = "Orange Cameroon";
@@ -313,11 +319,13 @@
                        }
                }
        } else if (client.ip ~ carrier_orange_congo) {
+               set req.http.X-DfltLang = "fr";
                if (req.http.X-Subdomain == "M") {
                        set req.http.X-Carrier = "Orange Congo";
                        set req.http.X-CS = "630-86";
                }
        } else if (client.ip ~ carrier_orange_ivory_coast) {
+               set req.http.X-DfltLang = "fr";
                if (req.http.X-Subdomain == "M") {
                        set req.http.X-Carrier = "Orange Ivory Coast";
                        set req.http.X-CS = "612-03";
@@ -328,11 +336,13 @@
                        set req.http.X-CS = "639-07";
                }
        } else if (client.ip ~ carrier_orange_niger) {
+               set req.http.X-DfltLang = "fr";
                if (req.http.X-Subdomain == "M") {
                        set req.http.X-Carrier = "Orange Niger";
                        set req.http.X-CS = "614-04";
                }
        } else if (client.ip ~ carrier_orange_tunisia) {
+               set req.http.X-DfltLang = "fr";
                if (req.http.X-Subdomain == "M") {
                        if (req.http.host ~ 
"(^(ar|en|fr|es|de|it|ru|ja|zh)\.m|^m)\.([a-zA-Z0-9-]+)\.org") {
                                set req.http.X-Carrier = "Orange Tunisia";
@@ -347,6 +357,7 @@
                        }
                }
        } else if (client.ip ~ carrier_saudi_telecom) {
+               set req.http.X-DfltLang = "ar";
                if (req.http.host ~ 
"(^(ar|bn|en|tl|ur)\.(zero|m)|^(zero|m))\.([a-zA-Z0-9-]+)\.org") {
                        set req.http.X-Carrier = "Saudi Telecom";
                        set req.http.X-CS = "420-01";
@@ -361,6 +372,7 @@
                set req.http.X-Carrier = "Telenor Montenegro";
                set req.http.X-CS = "297-01";
        } else if (client.ip ~ carrier_vimpelcom_beeline) {
+               set req.http.X-DfltLang = "ru";
                if (req.http.host ~ 
"(^(en|ru)\.(zero|m)|^(zero|m))\.([a-zA-Z0-9-]+)\.org") {
                        set req.http.X-Carrier = "Vimpelcom Beeline";
                        set req.http.X-CS = "250-99";
@@ -497,7 +509,7 @@
                char *last;
 
                char *xff_ip = strtok(VRT_GetHdr(sp, HDR_REQ, 
"\020X-Forwarded-For:"), ",");
-               
+
                if (xff_ip == NULL) {
                        xff_ip = VRT_GetHdr(sp, HDR_REQ, 
"\020X-Forwarded-For:");
                }
@@ -512,6 +524,11 @@
                set req.http.X-ORIG-CLIENT-IP = req.http.rlnclientipaddr;
        }
 
+       /* This call will set the following req.http values:
+               X-Subdomain = M or ZERO
+               X-DfltLang = en|fr|ru|...
+               X-Carrier = "Celcom Malaysia"
+               X-CS = "502-13" */
        call tag_carrier;
        /* Replace <language>.m.<project>.org by <language>.<project>.org */
        if ( req.http.host ~ "^([a-zA-Z0-9-]+)\.m\.([a-zA-Z0-9-]+)\.org" ) {
@@ -552,59 +569,24 @@
                unset req.http.Cookie;
        }
 
+       // TODO / FIXME:
+       // * Old code redirected m.wiki to en.m.wiki + req.url for m.wiki 
instead of Special:ZeroRatedMobileAccess
+       // * Old code did NOT redirect unknown zero.wiki to en.zero.wiki
+       // * Are there any issues with using canonical word "Special" instead 
of the localized one?
+       // * Can it/should it redirect to "//" instead of "http://"; (keep 
schema)
+       // * What should be redirect behavior for mobile.wikipedia.org
        if ( req.http.host == "m.wikipedia.org" ) {
-               if ( req.http.X-Carrier == "Orange Congo" ) {
-                       error 666 
"http://fr.m.wikipedia.org/wiki/Sp%C3%A9cial:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Botswana" ) {
-                       error 666 
"http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Ivory Coast" ) {
-                       error 666 
"http://fr.m.wikipedia.org/wiki/Sp%C3%A9cial:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Niger" ) {
-                       error 666 
"http://fr.m.wikipedia.org/wiki/Sp%C3%A9cial:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "wikimedia" ) {
-                       error 666 
"http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Uganda" ) {
-                       error 666 
"http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Tunisia" ) {
-                       error 666 
"http://fr.m.wikipedia.org/wiki/Sp%C3%A9cial:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Kenya" ) {
-                       error 666 
"http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Orange Cameroon" ) {
-                       error 666 
"http://fr.m.wikipedia.org/wiki/Sp%C3%A9cial:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Telenor Montenegro" ) {
-                       error 666 
"http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Grameenphone Bangladesh" ) {
-                       error 666 "http://bn.zero.wikipedia.org";;
-               } else if ( req.http.X-Carrier == "Saudi Telecom" ) {
-                       error 666 
"http://ar.m.wikipedia.org/wiki/%D8%AE%D8%A7%D8%B5:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Vimpelcom Beeline" ) {
-                       error 666 
"http://ru.m.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:ZeroRatedMobileAccess";;
-               } else {
-                       error 666 "http://en.m.wikipedia.org"; + req.url;
-               }
+               error 666 "http://"; + req.http.X-DfltLang + 
".m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";
+       } else if ( req.http.host == "zero.wikipedia.org" ) {
+               error 666 "http://"; + req.http.X-DfltLang + 
".zero.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";
        } else if ( req.http.host == "mobile.wikipedia.org" ) {
                error 666 "http://en.mobile.wikipedia.org"; + req.url;
-       } else if ( req.http.host == "zero.wikipedia.org" ) {
-               if ( req.http.X-Carrier == "Hello Cambodia" ) {
-                       error 666 "http://en.zero.wikipedia.org";;
-               } else if ( req.http.X-Carrier == "Celcom Malaysia" ) {
-                       error 666 "http://en.zero.wikipedia.org";;
-               } else if ( req.http.X-Carrier == "Grameenphone Bangladesh" ) {
-                       error 666 "http://bn.zero.wikipedia.org";;
-               } else if ( req.http.X-Carrier == "Saudi Telecom" ) {
-                       error 666 
"http://ar.zero.wikipedia.org/wiki/%D8%AE%D8%A7%D8%B5:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "TATA" ) {
-                       error 666 
"http://en.zero.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if( req.http.X-Carrier == "DTAC" ) {
-                       error 666 
"http://th.zero.wikipedia.org/wiki/%E0%B8%9E%E0%B8%B4%E0%B9%80%E0%B8%A8%E0%B8%A9:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Dialog Sri Lanka" ) {
-                       error 666 
"http://en.zero.wikipedia.org/wiki/Special:ZeroRatedMobileAccess";;
-               } else if ( req.http.X-Carrier == "Vimpelcom Beeline" ) {
-                       error 666 
"http://ru.zero.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:ZeroRatedMobileAccess";;
-               }
        }
 
-       if ( req.url == "/" ) { 
+       // Don't need to redirect, unset default language
+       unset req.http.X-DfltLang;
+
+       if ( req.url == "/" ) {
                set req.url = "/?useformat=mobile";
        }
 
@@ -630,6 +612,10 @@
 }
 
 sub vcl_error {
+       // At this point we no longer need the default language.
+       // Hope it doesn't barf if the header is not set.
+       unset req.http.X-DfltLang;
+
        /* Support mobile redirects */
        if (obj.status == 666) {
                set obj.http.Location = obj.response;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifda2dcabaa08f5df7b22b3b1d726f21882bbca36
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yurik <[email protected]>

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

Reply via email to