Index: trunk/extensions/LandingCheck/LandingCheck.php |
— | — | @@ -9,13 +9,11 @@ |
10 | 10 | exit( 1 ); |
11 | 11 | } |
12 | 12 | |
13 | | -$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/'; |
14 | | - |
15 | 13 | // Extension credits that will show up on Special:Version |
16 | 14 | $wgExtensionCredits['specialpage'][] = array( |
17 | 15 | 'path' => __FILE__, |
18 | 16 | 'name' => 'LandingCheck', |
19 | | - 'version' => '0.1', |
| 17 | + 'version' => '1.0', |
20 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:LandingCheck', |
21 | 19 | 'author' => 'Ryan Kaldari', |
22 | 20 | 'descriptionmsg' => 'landingcheck-desc', |
Index: trunk/extensions/LandingCheck/SpecialLandingCheck.php |
— | — | @@ -4,33 +4,50 @@ |
5 | 5 | exit( 1 ); |
6 | 6 | } |
7 | 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 redirects the user. |
| 12 | + */ |
8 | 13 | class SpecialLandingCheck extends SpecialPage { |
9 | 14 | |
10 | | - function __construct() { |
| 15 | + public function __construct() { |
11 | 16 | // Register special page |
12 | 17 | parent::__construct( 'LandingCheck' ); |
13 | 18 | } |
14 | 19 | |
15 | | - function execute( $sub ) { |
16 | | - global $wgOut, $wgUser, $wgRequest, $wgLandingPageBase; |
| 20 | + public function execute( $sub ) { |
| 21 | + global $wgOut, $wgUser, $wgRequest, $wgScript; |
17 | 22 | |
18 | | - if ( $wgRequest->getVal( 'language' ) ) { |
19 | | - $language = ( preg_match( '/^[A-Za-z-]+$/', $wgRequest->getVal( 'language' ) ) ); |
20 | | - } else { |
21 | | - $language = 'en'; |
22 | | - } |
23 | | - $country = $wgRequest->getVal( 'country' ); |
24 | | - $landingPage = $wgRequest->getVal( 'landing_page' ); |
| 23 | + $language = $wgRequest->getText( 'language', 'en' ); |
| 24 | + $country = $wgRequest->getText( 'country' ); |
| 25 | + $landingPage = $wgRequest->getText( 'landing_page' ); |
25 | 26 | |
26 | | - $tracking = '?' . wfArrayToCGI( array( |
| 27 | + $tracking = wfArrayToCGI( array( |
27 | 28 | 'utm_source' => $wgRequest->getVal( 'utm_source' ), |
28 | 29 | 'utm_medium' => $wgRequest->getVal( 'utm_medium' ), |
29 | 30 | 'utm_campaign' => $wgRequest->getVal( 'utm_campaign' ), |
30 | 31 | 'referrer' => $wgRequest->getHeader( 'referer' ) |
31 | 32 | ) ); |
32 | 33 | |
33 | | - if ( 1 ) { |
34 | | - $wgOut->redirect( $wgLandingPageBase . '/' . $language . '/' . $country . $tracking ); |
| 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 | + } |
35 | 51 | } |
| 52 | + |
36 | 53 | } |
37 | 54 | } |