Index: trunk/extensions/GeoLite/GeoLite_body.php |
— | — | @@ -20,27 +20,28 @@ |
21 | 21 | public function execute( $sub ) { |
22 | 22 | global $wgOut, $wgRequest, $wgLandingPageBase, $wgKnownLandingPages; |
23 | 23 | |
24 | | - $lang = ( $wgRequest->getVal( 'lang' ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ; |
| 24 | + $lang = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'lang' ) ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ; |
25 | 25 | $utm_source = $wgRequest->getVal( 'utm_source' ); |
26 | 26 | $utm_medium = $wgRequest->getVal( 'utm_medium' ); |
27 | | - $utm_campaign = $wgRequest->getVal( 'utm_camapaign' ); |
| 27 | + $utm_campaign = $wgRequest->getVal( 'utm_campaign' ); |
28 | 28 | |
29 | | - $tracking = '?' . "utm_source=$utm_source" . "&utm_medium=$utm_medium" . "&utm_campaign=$utm_campaign"; |
| 29 | + $tracking = '?' . wfArrayToCGI( array( |
| 30 | + 'utm_source' => "$utm_source", |
| 31 | + 'utm_medium' => "$utm_medium", |
| 32 | + 'utm_campaign' => "$utm_campaign", |
| 33 | + ) ); |
30 | 34 | |
31 | | - if ( $wgRequest->getVal( 'ip') ) { |
32 | | - $ip = $wgRequest->getVal( 'ip' ); |
33 | | - } else { |
34 | | - $ip = $_SERVER[ 'REMOTE_ADDR' ]; |
35 | | - } |
| 35 | + $ip = ( $wgRequest->getVal( 'ip') ) ? $wgRequest->getVal( 'ip' ) : wfGetIP(); |
36 | 36 | |
37 | 37 | if ( IP::isValid( $ip ) ) { |
38 | 38 | $country = geoip_country_code_by_name( $ip ); |
39 | | - |
40 | 39 | if ( is_string ( $country ) && array_key_exists( $country, $wgKnownLandingPages ) ) { |
41 | 40 | $wgOut->redirect( $wgLandingPageBase . "/" . $wgKnownLandingPages[ $country ] . $tracking ); |
42 | 41 | } |
| 42 | + } else { |
| 43 | + // Either we couldn't get the ip from the client or the geo ip lookup failed. Redirect as best as we can |
| 44 | + $wgOut->redirect( $wgLandingPageBase . "/" . $lang . $tracking ); |
43 | 45 | } |
44 | | - $wgOut->redirect( $wgLandingPageBase . "/" . $lang . $tracking ); |
45 | 46 | } |
46 | 47 | |
47 | 48 | } |
Index: trunk/extensions/GeoLite/GeoLite.php |
— | — | @@ -12,9 +12,9 @@ |
13 | 13 | $wgLandingPageBase = 'http://wikimediafoundation.org/wiki/Support_Wikipedia'; |
14 | 14 | |
15 | 15 | $wgKnownLandingPages = array( 'US' => 'en', |
16 | | - 'DE' => '', |
17 | | - 'PL' => '' |
18 | | - ); # Which Chapters actually have landing pages |
| 16 | + 'DE' => '', |
| 17 | + 'PL' => '', |
| 18 | + ); # Which Chapters actually have landing pages |
19 | 19 | |
20 | 20 | $wgExtensionCredits['specialpage'][] = array( |
21 | 21 | 'path' => __FILE__, |