r75903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75902‎ | r75903 | r75904 >
Date:02:00, 3 November 2010
Author:kaldari
Status:deferred
Tags:
Comment:
some comments and clean-up
Modified paths:
  • /trunk/extensions/LandingCheck/SpecialLandingCheck.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LandingCheck/SpecialLandingCheck.php
@@ -5,9 +5,9 @@
66 }
77
88 /**
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.
1212 */
1313 class SpecialLandingCheck extends SpecialPage {
1414
@@ -17,12 +17,14 @@
1818 }
1919
2020 public function execute( $sub ) {
21 - global $wgOut, $wgUser, $wgRequest, $wgScript;
 21+ global $wgOut, $wgRequest;
2222
 23+ // Pull in query string parameters
2324 $language = $wgRequest->getVal( 'language', 'en' );
2425 $country = $wgRequest->getVal( 'country', 'US' );
2526 $landingPage = $wgRequest->getVal( 'landing_page', 'Donate' );
2627
 28+ // Construct new query string for tracking
2729 $tracking = wfArrayToCGI( array(
2830 'utm_source' => $wgRequest->getVal( 'utm_source' ),
2931 'utm_medium' => $wgRequest->getVal( 'utm_medium' ),
@@ -30,22 +32,23 @@
3133 'referrer' => $wgRequest->getHeader( 'referer' )
3234 ) );
3335
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
4943 }
5044
 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+
5154 }
5255 }

Status & tagging log