r59030 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59029‎ | r59030 | r59031 >
Date:21:37, 13 November 2009
Author:tparscal
Status:ok
Tags:
Comment:
Added support for target parameter.
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
@@ -12,37 +12,40 @@
1313 public function __construct() {
1414 parent::__construct( 'GeoLite' );
1515 }
16 -
 16+
1717 public function execute( $sub ) {
18 - global $wgOut, $wgRequest, $wgLandingPageBase, $wgChaptersPageBase, $wgChapterLandingPages;
19 -
 18+ global $wgOut, $wgRequest;
 19+ global $wgLandingPageBase, $wgChaptersPageBase, $wgChapterLandingPages, $wgLandingPageDefaultTarget;
 20+
2021 $lang = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'lang' ) ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ;
2122 $utm_source = $wgRequest->getVal( 'utm_source' );
2223 $utm_medium = $wgRequest->getVal( 'utm_medium' );
2324 $utm_campaign = $wgRequest->getVal( 'utm_campaign' );
2425 $referrer = $wgRequest->getHeader( 'referer' );
25 -
 26+ $target = $wgRequest->getVal( 'target', null );
 27+ if ( !$target ) {
 28+ $target = $wgLandingPageDefaultTarget;
 29+ }
 30+
2631 $tracking = '?' . wfArrayToCGI( array(
2732 'utm_source' => "$utm_source",
2833 'utm_medium' => "$utm_medium",
2934 'utm_campaign' => "$utm_campaign",
3035 'referrer' => "$referrer",
 36+ 'target' => "$target",
3137 ) );
32 -
 38+
3339 $ip = ( $wgRequest->getVal( 'ip') ) ? $wgRequest->getVal( 'ip' ) : wfGetIP();
34 -
 40+
3541 if ( IP::isValid( $ip ) ) {
3642 $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 ) ) {
4044 $wgOut->redirect( $wgChaptersPageBase . '/' . $wgChapterLandingPages[$country] . $tracking );
41 - } else { // Valid IP but no chapter page
42 - $wgOut->redirect( $wgLandingPageBase . '/' . $lang . $tracking );
 45+ return;
4346 }
44 - } else { // No IP found so do the best we can
45 - $wgOut->redirect( $wgLandingPageBase . '/' . $lang . $tracking );
4647 }
 48+ // No valid IP or chapter page - let's just go for the general one
 49+ $wgOut->redirect( $wgLandingPageBase . $target . '/' . $lang . $tracking );
4750 }
4851
4952 }
\ No newline at end of file
Index: trunk/extensions/GeoLite/GeoLite.php
@@ -9,7 +9,9 @@
1010 exit( 1 );
1111 }
1212
13 -$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/Support_Wikipedia';
 13+$wgChapterLandingPages = array();
 14+$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/';
 15+$wgLandingPageDefaultTarget = 'Support_Wikipedia';
1416 $wgChaptersPageBase = 'http://wikimediafoundation.org/wiki/Global_Support';
1517
1618 //wgChapterLandingPages set which landing pages we know about

Follow-up revisions

RevisionCommit summaryAuthorDate
r59034picking up r59030tomasz22:01, 13 November 2009

Status & tagging log