--- /dev/null
+<?php
+/**
+ * Internationalisation for GeoLite extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+/** English
+ * @author Tomasz Finc
+ */
+$messages['en'] = array(
+ 'geolite-desc' => 'Lightweight GeoIp Redirection',
+ 'geolite' => 'GeoLite',
+);
--- /dev/null
+<?php
+
+# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
+if ( !defined( 'MEDIAWIKI' ) ) {
+ echo <<<EOT
+To install my extension, put the following line in LocalSettings.php:
+require_once( "\$IP/extensions/ContributionReporting/ContributionReporting.php" );
+EOT;
+ exit( 1 );
+}
+
+$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/Support_Wikipedia';
+
+$wgKnownLandingPages = array( 'US' => 'en',
+ 'DE' => '',
+ 'PL' => ''
+ ); # Which Chapters actually have landing pages
+
+$wgExtensionCredits['specialpage'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'GeoLite',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:GeoLite',
+ 'author' => array( 'Tomasz Finc' ),
+ 'descriptionmsg' => 'geolite-desc',
+);
+
+$dir = dirname( __FILE__ ) . '/';
+
+$wgAutoloadClasses['SpecialGeoLite'] = $dir . 'GeoLite_body.php';
+$wgExtensionMessagesFiles['GeoLite'] = $dir . 'GeoLite.i18n.php';
+$wgSpecialPages['GeoLite'] = 'SpecialGeoLite';
+$wgSpecialPageGroups['GeoLite'] = 'contribution';
+
+?>
--- /dev/null
+<?php
+/**
+ * Special Page for GeoLite
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+// Special page GeoLite
+
+class SpecialGeoLite extends SpecialPage {
+
+ /* Functions */
+
+ public function __construct() {
+ // Initialize special page
+ parent::__construct( 'GeoLite' );
+ }
+
+ public function execute( $sub ) {
+ global $wgOut, $wgRequest, $wgLandingPageBase, $wgKnownLandingPages;
+
+ $lang = ( $wgRequest->getVal( 'lang' ) ) ? $wgRequest->getVal( 'lang' ) : 'en' ;
+ $utm_source = $wgRequest->getVal( 'utm_source' );
+ $utm_medium = $wgRequest->getVal( 'utm_medium' );
+ $utm_campaign = $wgRequest->getVal( 'utm_camapaign' );
+
+ $tracking = '?' . "utm_source=$utm_source" . "&utm_medium=$utm_medium" . "&utm_campaign=$utm_campaign";
+
+ if ( $wgRequest->getVal( 'ip') ) {
+ $ip = $wgRequest->getVal( 'ip' );
+ } else {
+ $ip = $_SERVER[ 'REMOTE_ADDR' ];
+ }
+
+ if ( IP::isValid( $ip ) ) {
+ $country = geoip_country_code_by_name( $ip );
+
+ if ( is_string ( $country ) && array_key_exists( $country, $wgKnownLandingPages ) ) {
+ $wgOut->redirect( $wgLandingPageBase . "/" . $wgKnownLandingPages[ $country ] . $tracking );
+ }
+ }
+ $wgOut->redirect( $wgLandingPageBase . "/" . $lang . $tracking );
+ }
+
+}