Index: trunk/extensions/LandingCheck/SpecialLandingCheck.php |
— | — | @@ -5,9 +5,9 @@ |
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
9 | | - * This page checks to see if a version of a landing page exists for the user's language and |
10 | | - * country. If not, it looks for a version localized for the user's language. If that doesn't exist |
11 | | - * either, it looks for the English version. If any of those exist, it then redirects the user. |
| 9 | + * This checks to see if a version of a landing page exists for the user's language and country. |
| 10 | + * If not, it looks for a version localized for the user's language. If that doesn't exist either, |
| 11 | + * it looks for the English version. If any of those exist, it then redirects the user. |
12 | 12 | */ |
13 | 13 | class SpecialLandingCheck extends SpecialPage { |
14 | 14 | |
— | — | @@ -17,12 +17,14 @@ |
18 | 18 | } |
19 | 19 | |
20 | 20 | public function execute( $sub ) { |
21 | | - global $wgOut, $wgUser, $wgRequest, $wgScript; |
| 21 | + global $wgOut, $wgRequest; |
22 | 22 | |
| 23 | + // Pull in query string parameters |
23 | 24 | $language = $wgRequest->getVal( 'language', 'en' ); |
24 | 25 | $country = $wgRequest->getVal( 'country', 'US' ); |
25 | 26 | $landingPage = $wgRequest->getVal( 'landing_page', 'Donate' ); |
26 | 27 | |
| 28 | + // Construct new query string for tracking |
27 | 29 | $tracking = wfArrayToCGI( array( |
28 | 30 | 'utm_source' => $wgRequest->getVal( 'utm_source' ), |
29 | 31 | 'utm_medium' => $wgRequest->getVal( 'utm_medium' ), |
— | — | @@ -30,22 +32,23 @@ |
31 | 33 | 'referrer' => $wgRequest->getHeader( 'referer' ) |
32 | 34 | ) ); |
33 | 35 | |
34 | | - if ( strval( $landingPage ) !== '' ) { |
35 | | - $targetTexts = array( |
36 | | - $landingPage . '/' . $language . '/' . $country, |
37 | | - $landingPage . '/' . $language |
38 | | - ); |
39 | | - if ( $language != 'en' ) { |
40 | | - $targetTexts[] = $landingPage . '/en'; |
41 | | - } |
42 | | - foreach ( $targetTexts as $targetText ) { |
43 | | - $target = Title::newFromText( $targetText ); |
44 | | - if ( $target && $target->isKnown() && $target->getNamespace() == NS_MAIN ) { |
45 | | - $wgOut->redirect( $target->getLocalURL( $tracking ) ); |
46 | | - return; |
47 | | - } |
48 | | - } |
| 36 | + // Build array of landing pages to check for |
| 37 | + $targetTexts = array( |
| 38 | + $landingPage . '/' . $language . '/' . $country, |
| 39 | + $landingPage . '/' . $language |
| 40 | + ); |
| 41 | + if ( $language != 'en' ) { |
| 42 | + $targetTexts[] = $landingPage . '/en'; // English fallback |
49 | 43 | } |
50 | 44 | |
| 45 | + // Go through the possible landing pages and redirect the user as soon as one is found to exist |
| 46 | + foreach ( $targetTexts as $targetText ) { |
| 47 | + $target = Title::newFromText( $targetText ); |
| 48 | + if ( $target && $target->isKnown() && $target->getNamespace() == NS_MAIN ) { |
| 49 | + $wgOut->redirect( $target->getLocalURL( $tracking ) ); |
| 50 | + return; |
| 51 | + } |
| 52 | + } |
| 53 | + |
51 | 54 | } |
52 | 55 | } |