Index: trunk/extensions/GeoLite/GeoLite_body.php |
— | — | @@ -12,37 +12,40 @@ |
13 | 13 | public function __construct() { |
14 | 14 | parent::__construct( 'GeoLite' ); |
15 | 15 | } |
16 | | - |
| 16 | + |
17 | 17 | public function execute( $sub ) { |
18 | | - global $wgOut, $wgRequest, $wgLandingPageBase, $wgChaptersPageBase, $wgChapterLandingPages; |
19 | | - |
| 18 | + global $wgOut, $wgRequest; |
| 19 | + global $wgLandingPageBase, $wgChaptersPageBase, $wgChapterLandingPages, $wgLandingPageDefaultTarget; |
| 20 | + |
20 | 21 | $lang = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'lang' ) ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ; |
21 | 22 | $utm_source = $wgRequest->getVal( 'utm_source' ); |
22 | 23 | $utm_medium = $wgRequest->getVal( 'utm_medium' ); |
23 | 24 | $utm_campaign = $wgRequest->getVal( 'utm_campaign' ); |
24 | 25 | $referrer = $wgRequest->getHeader( 'referer' ); |
25 | | - |
| 26 | + $target = $wgRequest->getVal( 'target', null ); |
| 27 | + if ( !$target ) { |
| 28 | + $target = $wgLandingPageDefaultTarget; |
| 29 | + } |
| 30 | + |
26 | 31 | $tracking = '?' . wfArrayToCGI( array( |
27 | 32 | 'utm_source' => "$utm_source", |
28 | 33 | 'utm_medium' => "$utm_medium", |
29 | 34 | 'utm_campaign' => "$utm_campaign", |
30 | 35 | 'referrer' => "$referrer", |
| 36 | + 'target' => "$target", |
31 | 37 | ) ); |
32 | | - |
| 38 | + |
33 | 39 | $ip = ( $wgRequest->getVal( 'ip') ) ? $wgRequest->getVal( 'ip' ) : wfGetIP(); |
34 | | - |
| 40 | + |
35 | 41 | if ( IP::isValid( $ip ) ) { |
36 | 42 | $country = geoip_country_code_by_name( $ip ); |
37 | | - if ( is_string ( $country ) && |
38 | | - array_key_exists( $country, $wgChapterLandingPages ) |
39 | | - ) { |
| 43 | + if ( is_string ( $country ) && array_key_exists( $country, $wgChapterLandingPages ) ) { |
40 | 44 | $wgOut->redirect( $wgChaptersPageBase . '/' . $wgChapterLandingPages[$country] . $tracking ); |
41 | | - } else { // Valid IP but no chapter page |
42 | | - $wgOut->redirect( $wgLandingPageBase . '/' . $lang . $tracking ); |
| 45 | + return; |
43 | 46 | } |
44 | | - } else { // No IP found so do the best we can |
45 | | - $wgOut->redirect( $wgLandingPageBase . '/' . $lang . $tracking ); |
46 | 47 | } |
| 48 | + // No valid IP or chapter page - let's just go for the general one |
| 49 | + $wgOut->redirect( $wgLandingPageBase . $target . '/' . $lang . $tracking ); |
47 | 50 | } |
48 | 51 | |
49 | 52 | } |
\ No newline at end of file |
Index: trunk/extensions/GeoLite/GeoLite.php |
— | — | @@ -9,7 +9,9 @@ |
10 | 10 | exit( 1 ); |
11 | 11 | } |
12 | 12 | |
13 | | -$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/Support_Wikipedia'; |
| 13 | +$wgChapterLandingPages = array(); |
| 14 | +$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/'; |
| 15 | +$wgLandingPageDefaultTarget = 'Support_Wikipedia'; |
14 | 16 | $wgChaptersPageBase = 'http://wikimediafoundation.org/wiki/Global_Support'; |
15 | 17 | |
16 | 18 | //wgChapterLandingPages set which landing pages we know about |