r75877 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75876‎ | r75877 | r75878 >
Date:20:43, 2 November 2010
Author:kaldari
Status:deferred
Tags:
Comment:
Working version of LandingCheck extension
Modified paths:
  • /trunk/extensions/LandingCheck/LandingCheck.php (modified) (history)
  • /trunk/extensions/LandingCheck/SpecialLandingCheck.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LandingCheck/LandingCheck.php
@@ -9,13 +9,11 @@
1010 exit( 1 );
1111 }
1212
13 -$wgLandingPageBase = 'http://wikimediafoundation.org/wiki/';
14 -
1513 // Extension credits that will show up on Special:Version
1614 $wgExtensionCredits['specialpage'][] = array(
1715 'path' => __FILE__,
1816 'name' => 'LandingCheck',
19 - 'version' => '0.1',
 17+ 'version' => '1.0',
2018 'url' => 'http://www.mediawiki.org/wiki/Extension:LandingCheck',
2119 'author' => 'Ryan Kaldari',
2220 'descriptionmsg' => 'landingcheck-desc',
Index: trunk/extensions/LandingCheck/SpecialLandingCheck.php
@@ -4,33 +4,50 @@
55 exit( 1 );
66 }
77
 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+ */
813 class SpecialLandingCheck extends SpecialPage {
914
10 - function __construct() {
 15+ public function __construct() {
1116 // Register special page
1217 parent::__construct( 'LandingCheck' );
1318 }
1419
15 - function execute( $sub ) {
16 - global $wgOut, $wgUser, $wgRequest, $wgLandingPageBase;
 20+ public function execute( $sub ) {
 21+ global $wgOut, $wgUser, $wgRequest, $wgScript;
1722
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' );
2526
26 - $tracking = '?' . wfArrayToCGI( array(
 27+ $tracking = wfArrayToCGI( array(
2728 'utm_source' => $wgRequest->getVal( 'utm_source' ),
2829 'utm_medium' => $wgRequest->getVal( 'utm_medium' ),
2930 'utm_campaign' => $wgRequest->getVal( 'utm_campaign' ),
3031 'referrer' => $wgRequest->getHeader( 'referer' )
3132 ) );
3233
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+ }
3551 }
 52+
3653 }
3754 }

Status & tagging log