Index: branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly. |
| 5 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 6 | + echo <<<EOT |
| 7 | +To install this extension, put the following line in LocalSettings.php: |
| 8 | +require_once( "\$IP/extensions/LandingCheck/LandingCheck.php" ); |
| 9 | +EOT; |
| 10 | + exit( 1 ); |
| 11 | +} |
| 12 | + |
| 13 | +// Extension credits that will show up on Special:Version |
| 14 | +$wgExtensionCredits['specialpage'][] = array( |
| 15 | + 'path' => __FILE__, |
| 16 | + 'name' => 'LandingCheck', |
| 17 | + 'version' => '1.0', |
| 18 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:LandingCheck', |
| 19 | + 'author' => 'Ryan Kaldari', |
| 20 | + 'descriptionmsg' => 'landingcheck-desc', |
| 21 | +); |
| 22 | + |
| 23 | +$dir = dirname( __FILE__ ) . '/'; |
| 24 | + |
| 25 | +$wgAutoloadClasses['SpecialLandingCheck'] = $dir . 'SpecialLandingCheck.php'; |
| 26 | +$wgExtensionMessagesFiles['LandingCheck'] = $dir . 'LandingCheck.i18n.php'; |
| 27 | +$wgSpecialPages['LandingCheck'] = 'SpecialLandingCheck'; |
| 28 | +$wgSpecialPageGroups['LandingCheck'] = 'contribution'; |
Property changes on: branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: branches/wmf/1.16wmf4/extensions/LandingCheck/SpecialLandingCheck.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + echo "LandingCheck extension\n"; |
| 5 | + exit( 1 ); |
| 6 | +} |
| 7 | + |
| 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. |
| 12 | + */ |
| 13 | +class SpecialLandingCheck extends SpecialPage { |
| 14 | + |
| 15 | + public function __construct() { |
| 16 | + // Register special page |
| 17 | + parent::__construct( 'LandingCheck' ); |
| 18 | + } |
| 19 | + |
| 20 | + public function execute( $sub ) { |
| 21 | + global $wgOut, $wgUser, $wgRequest, $wgScript; |
| 22 | + |
| 23 | + $language = $wgRequest->getText( 'language', 'en' ); |
| 24 | + $country = $wgRequest->getText( 'country', 'US' ); |
| 25 | + $landingPage = $wgRequest->getText( 'landing_page', 'Donate' ); |
| 26 | + |
| 27 | + $tracking = wfArrayToCGI( array( |
| 28 | + 'utm_source' => $wgRequest->getVal( 'utm_source' ), |
| 29 | + 'utm_medium' => $wgRequest->getVal( 'utm_medium' ), |
| 30 | + 'utm_campaign' => $wgRequest->getVal( 'utm_campaign' ), |
| 31 | + 'referrer' => $wgRequest->getHeader( 'referer' ) |
| 32 | + ) ); |
| 33 | + |
| 34 | + if ( $landingPage ) { |
| 35 | + if ( strpos( $landingPage, 'Special:' ) === false ) { // landing page is not a special page |
| 36 | + $target = Title::newFromText( $landingPage . '/' . $language . '/' . $country ); |
| 37 | + if( $target->isKnown() ) { |
| 38 | + $wgOut->redirect( $target->getLocalURL( $tracking ) ); |
| 39 | + } else { |
| 40 | + $target = Title::newFromText( $landingPage . '/' . $language ); |
| 41 | + if( $target->isKnown() ) { |
| 42 | + $wgOut->redirect( $target->getLocalURL( $tracking ) ); |
| 43 | + } elseif ( $language != 'en' ) { |
| 44 | + $target = Title::newFromText( $landingPage . '/en' ); |
| 45 | + if( $target->isKnown() ) { |
| 46 | + $wgOut->redirect( $target->getLocalURL( $tracking ) ); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + } |
| 54 | +} |
Property changes on: branches/wmf/1.16wmf4/extensions/LandingCheck/SpecialLandingCheck.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |
Index: branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.i18n.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for GeoLite extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Ryan Kaldari |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'landingcheck-desc' => 'This extension facilitates the use of geotargeted localized landing pages. It is a replacement for GeoLite.', |
| 17 | + 'landingcheck' => 'LandingCheck', |
| 18 | +); |
Property changes on: branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 19 | + native |