r58800 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58799‎ | r58800 | r58801 >
Date:02:41, 9 November 2009
Author:tomasz
Status:ok
Tags:
Comment:
Adding Tim's suggestions. Use wfGetIP instead of REMOTE_ADDR. Use wfArrayToCGI as well.
Modified paths:
  • /trunk/extensions/GeoLite/GeoLite.php (modified) (history)
  • /trunk/extensions/GeoLite/GeoLite_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeoLite/GeoLite_body.php
@@ -20,27 +20,28 @@
2121 public function execute( $sub ) {
2222 global $wgOut, $wgRequest, $wgLandingPageBase, $wgKnownLandingPages;
2323
24 - $lang = ( $wgRequest->getVal( 'lang' ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ;
 24+ $lang = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'lang' ) ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ;
2525 $utm_source = $wgRequest->getVal( 'utm_source' );
2626 $utm_medium = $wgRequest->getVal( 'utm_medium' );
27 - $utm_campaign = $wgRequest->getVal( 'utm_camapaign' );
 27+ $utm_campaign = $wgRequest->getVal( 'utm_campaign' );
2828
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+ ) );
3034
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();
3636
3737 if ( IP::isValid( $ip ) ) {
3838 $country = geoip_country_code_by_name( $ip );
39 -
4039 if ( is_string ( $country ) && array_key_exists( $country, $wgKnownLandingPages ) ) {
4140 $wgOut->redirect( $wgLandingPageBase . "/" . $wgKnownLandingPages[ $country ] . $tracking );
4241 }
 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 );
4345 }
44 - $wgOut->redirect( $wgLandingPageBase . "/" . $lang . $tracking );
4546 }
4647
4748 }
Index: trunk/extensions/GeoLite/GeoLite.php
@@ -12,9 +12,9 @@
1313 $wgLandingPageBase = 'http://wikimediafoundation.org/wiki/Support_Wikipedia';
1414
1515 $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
1919
2020 $wgExtensionCredits['specialpage'][] = array(
2121 'path' => __FILE__,

Status & tagging log