r101515 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101514‎ | r101515 | r101516 >
Date:19:25, 1 November 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.alias.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.i18n.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/LandingCheck/SpecialLandingCheck.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.php
@@ -13,16 +13,12 @@
1414 $wgExtensionCredits['specialpage'][] = array(
1515 'path' => __FILE__,
1616 'name' => 'LandingCheck',
17 - 'version' => '1.2',
 17+ 'version' => '2.0',
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:LandingCheck',
19 - 'author' => 'Ryan Kaldari',
 19+ 'author' => array( 'Ryan Kaldari', 'Arthur Richards' ),
2020 'descriptionmsg' => 'landingcheck-desc',
2121 );
2222
23 -// If there are any countries for which the country page should be the fallback rather than a
24 -// language page, add its country code to this array.
25 -$wgPriorityCountries = array();
26 -
2723 $dir = dirname( __FILE__ ) . '/';
2824
2925 $wgAutoloadClasses['SpecialLandingCheck'] = $dir . 'SpecialLandingCheck.php';
@@ -30,3 +26,25 @@
3127 $wgExtensionAliasesFiles['LandingCheck'] = $dir . 'LandingCheck.alias.php';
3228 $wgSpecialPages['LandingCheck'] = 'SpecialLandingCheck';
3329 $wgSpecialPageGroups['LandingCheck'] = 'contribution';
 30+
 31+// If there are any countries for which the country page should be the fallback rather than a
 32+// language page, add its country code to this array.
 33+$wgPriorityCountries = array();
 34+
 35+/**
 36+ * It is possible to configure a separate server running LandingCheck to handle
 37+ * requests for priority countries and another for non-priority countries. By
 38+ * default, the local instance of LandingCheck will handle both unless the following
 39+ * variables are configured.
 40+ *
 41+ * The URLs contained in these variables should be the full URL to the location
 42+ * of LandingCheck - the query string will be appended. For example:
 43+ * $wgLandingCheckPriorityURLBase = '//wikimediafoundation.org/wiki/Special:LandingCheck';
 44+ *
 45+ * LandingCheck will compare the host portion of these URLs to what is
 46+ * configured for $wgServer. If the hosts match, the LandingCheck will just
 47+ * handle the request locally. If these are not set, LandingCheck will default to
 48+ * handling the request locally.
 49+ */
 50+$wgLandingCheckPriorityURLBase = null;
 51+$wgLandingCheckNormalURLBase = null;
\ No newline at end of file
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.php
___________________________________________________________________
Added: svn:mergeinfo
3452 Merged /branches/wmf-deployment/extensions/LandingCheck/LandingCheck.php:r60970
3553 Merged /branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.php:r67177,69199,76243,77266
3654 Merged /trunk/extensions/LandingCheck/LandingCheck.php:r76551,77519-77521,77622-78860,101335-101514
3755 Merged /trunk/phase3/extensions/LandingCheck/LandingCheck.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,70559,71970,75332,75481,77555,77558-77560,77563-77565,77573
Index: branches/wmf/1.18wmf1/extensions/LandingCheck/SpecialLandingCheck.php
@@ -10,6 +10,7 @@
1111 * it looks for the English version. If any of those exist, it then redirects the user.
1212 */
1313 class SpecialLandingCheck extends SpecialPage {
 14+ protected $localServerType = null;
1415
1516 public function __construct() {
1617 // Register special page
@@ -17,7 +18,7 @@
1819 }
1920
2021 public function execute( $sub ) {
21 - global $wgOut, $wgRequest, $wgPriorityCountries;
 22+ global $wgRequest, $wgPriorityCountries;
2223
2324 // Pull in query string parameters
2425 $language = $wgRequest->getVal( 'language', 'en' );
@@ -25,7 +26,7 @@
2627 $country = $wgRequest->getVal( 'country' );
2728 // If no country was passed, try to do GeoIP lookup
2829 // Requires php5-geoip package
29 - if ( !$country && function_exists( geoip_country_code_by_name ) ) {
 30+ if ( !$country && function_exists( 'geoip_country_code_by_name' ) ) {
3031 $ip = wfGetIP();
3132 if ( IP::isValid( $ip ) ) {
3233 $country = geoip_country_code_by_name( $ip );
@@ -35,6 +36,102 @@
3637 $country = 'US'; // Default
3738 }
3839
 40+ // determine if we are fulfilling a request for a priority country
 41+ $priority = in_array( $country, $wgPriorityCountries );
 42+
 43+ // handle the actual redirect
 44+ $this->routeRedirect( $country, $language, $priority );
 45+ }
 46+
 47+ /**
 48+ * Determine whether this server is configured as the priority or normal server
 49+ *
 50+ * If this is neither the priority nor normal server, assumes 'local' - meaning
 51+ * this server should be handling the request.
 52+ */
 53+ public function determineLocalServerType() {
 54+ global $wgServer, $wgLandingCheckPriorityURLBase, $wgLandingCheckNormalURLBase;
 55+
 56+ $localServerDetails = wfParseUrl( $wgServer );
 57+
 58+ // The following checks are necessary due to a bug in wfParseUrl that was fixed in r94352.
 59+ if ( $wgLandingCheckPriorityURLBase ) {
 60+ $priorityServerDetails = wfParseUrl( $wgLandingCheckPriorityURLBase );
 61+ } else {
 62+ $priorityServerDetails = false;
 63+ }
 64+ if ( $wgLandingCheckNormalURLBase ) {
 65+ $normalServerDetails = wfParseUrl( $wgLandingCheckNormalURLBase );
 66+ } else {
 67+ $normalServerDetails = false;
 68+ }
 69+ //$priorityServerDetails = wfParseUrl( $wgLandingCheckPriorityURLBase );
 70+ //$normalServerDetails = wfParseUrl( $wgLandingCheckNormalURLBase );
 71+
 72+ if ( $localServerDetails[ 'host' ] == $priorityServerDetails[ 'host' ] ) {
 73+ return 'priority';
 74+ } elseif ( $localServerDetails[ 'host' ] == $normalServerDetails[ 'host' ] ) {
 75+ return 'normal';
 76+ } else {
 77+ return 'local';
 78+ }
 79+ }
 80+
 81+ /**
 82+ * Route the request to the appropriate redirect method
 83+ * @param string $country
 84+ * @param string $language
 85+ * @param bool $priority Whether or not we handle this request on behalf of a priority country
 86+ */
 87+ public function routeRedirect( $country, $language, $priority ) {
 88+ $localServerType = $this->getLocalServerType();
 89+
 90+ if ( $localServerType == 'local' ) {
 91+ $this->localRedirect( $country, $language, $priority );
 92+
 93+ } elseif ( $priority && $localServerType == 'priority' ) {
 94+ $this->localRedirect( $country, $language, $priority );
 95+
 96+ } elseif ( !$priority && $localServerType == 'normal' ) {
 97+ $this->localRedirect( $country, $language, $priority );
 98+
 99+ } else {
 100+ $this->externalRedirect( $priority );
 101+
 102+ }
 103+ }
 104+
 105+ /**
 106+ * Handle an external redirect
 107+ *
 108+ * The external redirect should point to another instance of LandingCheck
 109+ * which will ultimately handle the request.
 110+ * @param bool $priority
 111+ */
 112+ public function externalRedirect( $priority ) {
 113+ global $wgRequest, $wgOut, $wgLandingCheckPriorityURLBase, $wgLandingCheckNormalURLBase;
 114+
 115+ if ( $priority ) {
 116+ $urlBase = $wgLandingCheckPriorityURLBase;
 117+
 118+ } else {
 119+ $urlBase = $wgLandingCheckNormalURLBase;
 120+
 121+ }
 122+
 123+ $query = $wgRequest->getValues();
 124+ unset( $query[ 'title' ] );
 125+
 126+ $url = wfAppendQuery( $urlBase, $query );
 127+ $wgOut->redirect( $url );
 128+ }
 129+
 130+ /**
 131+ * Handle local redirect
 132+ * @param bool $priority Whether or not we handle this request on behalf of a priority country
 133+ */
 134+ public function localRedirect( $country, $language, $priority=false ) {
 135+ global $wgOut, $wgRequest;
39136 $landingPage = $wgRequest->getVal( 'landing_page', 'Donate' );
40137
41138 // Construct new query string for tracking
@@ -43,11 +140,12 @@
44141 'utm_medium' => $wgRequest->getVal( 'utm_medium' ),
45142 'utm_campaign' => $wgRequest->getVal( 'utm_campaign' ),
46143 'language' => $wgRequest->getVal( 'language', 'en'),
 144+ 'uselang' => $wgRequest->getVal( 'language', 'en'), // for {{int:xxx}} rendering
47145 'country' => $country,
48146 'referrer' => $wgRequest->getHeader( 'referer' )
49147 ) );
50148
51 - if ( in_array( $country, $wgPriorityCountries ) ) {
 149+ if ( $priority ) {
52150 // Build array of landing pages to check for
53151 $targetTexts = array(
54152 $landingPage . '/' . $country . '/' . $language,
@@ -75,6 +173,27 @@
76174 return;
77175 }
78176 }
79 -
80177 }
 178+
 179+ /**
 180+ * Setter for $this->localServerType
 181+ * @param string $type
 182+ */
 183+ public function setLocalServerType( $type = null ) {
 184+ if ( !$type ) {
 185+ $this->localServerType = $this->determineLocalServerType();
 186+ } else {
 187+ $this->localServerType = $type;
 188+ }
 189+ }
 190+
 191+ /**
 192+ * Getter for $this->localServerType
 193+ */
 194+ public function getLocalServerType() {
 195+ if ( !$this->localServerType ) {
 196+ $this->setLocalServerType();
 197+ }
 198+ return $this->localServerType;
 199+ }
81200 }
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/SpecialLandingCheck.php
___________________________________________________________________
Modified: svn:mergeinfo
82201 Merged /trunk/extensions/LandingCheck/SpecialLandingCheck.php:r100774-101514
Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.alias.php
@@ -8,13 +8,51 @@
99
1010 $specialPageAliases = array();
1111
12 -/** English
13 - * @author Ryan Kaldari
14 - */
 12+/** English (English) */
1513 $specialPageAliases['en'] = array(
1614 'LandingCheck' => array( 'LandingCheck' ),
1715 );
1816
 17+/** Arabic (العربية) */
 18+$specialPageAliases['ar'] = array(
 19+ 'LandingCheck' => array( 'تحقق_الهدف' ),
 20+);
 21+
 22+/** Haitian (Kreyòl ayisyen) */
 23+$specialPageAliases['ht'] = array(
 24+ 'LandingCheck' => array( 'VerifikasyonAteri' ),
 25+);
 26+
 27+/** Macedonian (Македонски) */
 28+$specialPageAliases['mk'] = array(
 29+ 'LandingCheck' => array( 'ПроверкаНаОдредница' ),
 30+);
 31+
 32+/** Nedersaksisch (Nedersaksisch) */
 33+$specialPageAliases['nds-nl'] = array(
 34+ 'LandingCheck' => array( 'Laandingspaginakontrole' ),
 35+);
 36+
 37+/** Dutch (Nederlands) */
 38+$specialPageAliases['nl'] = array(
 39+ 'LandingCheck' => array( 'Landingspaginacontrole' ),
 40+);
 41+
 42+/** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬) */
 43+$specialPageAliases['no'] = array(
 44+ 'LandingCheck' => array( 'Landingssjekk' ),
 45+);
 46+
 47+/** Cantonese (粵語) */
 48+$specialPageAliases['yue'] = array(
 49+ 'LandingCheck' => array( '登陸檢查' ),
 50+);
 51+
 52+/** Traditional Chinese (‪中文(繁體)‬) */
 53+$specialPageAliases['zh-hant'] = array(
 54+ 'LandingCheck' => array( '登陸檢查' ),
 55+);
 56+
1957 /**
2058 * For backwards compatibility with MediaWiki 1.15 and earlier.
2159 */
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.alias.php
___________________________________________________________________
Added: svn:mergeinfo
2260 Merged /branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.alias.php:r67177,69199,76243,77266
2361 Merged /trunk/extensions/LandingCheck/LandingCheck.alias.php:r76551,77519-77521,77622-78860,88029-101514
2462 Merged /trunk/phase3/extensions/LandingCheck/LandingCheck.alias.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,70559,71970,75332,75481,77555,77558-77560,77563-77565,77573
2563 Merged /branches/wmf-deployment/extensions/LandingCheck/LandingCheck.alias.php:r60970
Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.i18n.php
@@ -16,6 +16,15 @@
1717 'landingcheck' => 'LandingCheck',
1818 );
1919
 20+/** Message documentation (Message documentation)
 21+ * @author Yekrats
 22+ */
 23+$messages['qqq'] = array(
 24+ 'landingcheck-desc' => '{{desc}}
 25+See http://www.mediawiki.org/wiki/Extension:LandingCheck',
 26+ 'landingcheck' => 'The name of the extension LandingCheck. See: http://www.mediawiki.org/wiki/Extension:LandingCheck',
 27+);
 28+
2029 /** Afrikaans (Afrikaans)
2130 * @author Naudefj
2231 */
@@ -24,6 +33,14 @@
2534 'landingcheck' => 'Landingskontrole',
2635 );
2736
 37+/** Arabic (العربية)
 38+ * @author زكريا
 39+ */
 40+$messages['ar'] = array(
 41+ 'landingcheck-desc' => 'لتيسير استعمال صفحات تحديد موقع الوصول الجغرافي',
 42+ 'landingcheck' => 'LandingCheck',
 43+);
 44+
2845 /** Belarusian (Taraškievica orthography) (‪Беларуская (тарашкевіца)‬)
2946 * @author EugeneZelenko
3047 * @author Jim-by
@@ -82,6 +99,36 @@
83100 'landingcheck-desc' => 'Facilitates the use of geotargeted localised landing pages',
84101 );
85102
 103+/** Esperanto (Esperanto)
 104+ * @author Yekrats
 105+ */
 106+$messages['eo'] = array(
 107+ 'landingcheck-desc' => 'Faciligos la uzon de geografie asimilitaj celpaĝoj',
 108+ 'landingcheck' => 'LandingCheck',
 109+);
 110+
 111+/** Spanish (Español)
 112+ * @author MetalBrasil
 113+ */
 114+$messages['es'] = array(
 115+ 'landingcheck-desc' => 'Facilita el uso de páginas de aterrizaje localizada localización geográfica',
 116+);
 117+
 118+/** Persian (فارسی)
 119+ * @author Mjbmr
 120+ */
 121+$messages['fa'] = array(
 122+ 'landingcheck-desc' => 'تسهیل استفاده از صفحات فرود هدف جغرافیایی محلی',
 123+ 'landingcheck' => 'بررسی فرود',
 124+);
 125+
 126+/** Finnish (Suomi)
 127+ * @author Olli
 128+ */
 129+$messages['fi'] = array(
 130+ 'landingcheck' => 'Saapumisen tarkistus',
 131+);
 132+
86133 /** French (Français)
87134 * @author Peter17
88135 */
@@ -94,6 +141,7 @@
95142 * @author ChrisPtDe
96143 */
97144 $messages['frp'] = array(
 145+ 'landingcheck-desc' => 'Facilite l’usâjo de les pâges d’arrevâ g·eolocalisâs.',
98146 'landingcheck' => 'LandingCheck',
99147 );
100148
@@ -258,6 +306,13 @@
259307 'landingcheck' => 'LandingCheck',
260308 );
261309
 310+/** Romanian (Română)
 311+ * @author Firilacroco
 312+ */
 313+$messages['ro'] = array(
 314+ 'landingcheck' => 'LandingCheck',
 315+);
 316+
262317 /** Tarandíne (Tarandíne)
263318 * @author Joetaras
264319 */
@@ -273,6 +328,14 @@
274329 'landingcheck' => 'LandingCheck',
275330 );
276331
 332+/** Rusyn (Русиньскый)
 333+ * @author Gazeb
 334+ */
 335+$messages['rue'] = array(
 336+ 'landingcheck-desc' => 'Злегчує хоснованя ґеоґрафічно цїленых локалізованых вступных сторінок',
 337+ 'landingcheck' => 'LandingCheck',
 338+);
 339+
277340 /** Sakha (Саха тыла)
278341 * @author HalanTul
279342 */
@@ -297,6 +360,13 @@
298361 'landingcheck' => 'PreverjanjePristajališča',
299362 );
300363
 364+/** Swedish (Svenska)
 365+ * @author WikiPhoenix
 366+ */
 367+$messages['sv'] = array(
 368+ 'landingcheck' => 'LandingCheck',
 369+);
 370+
301371 /** Tagalog (Tagalog)
302372 * @author AnakngAraw
303373 */
@@ -305,6 +375,14 @@
306376 'landingcheck' => 'Pagsusuri ng Paglapag',
307377 );
308378
 379+/** Ukrainian (Українська)
 380+ * @author Dim Grits
 381+ */
 382+$messages['uk'] = array(
 383+ 'landingcheck-desc' => 'Полегшує використання геозалежних локалізованих цільових сторінок',
 384+ 'landingcheck' => 'LandingCheck',
 385+);
 386+
309387 /** Vietnamese (Tiếng Việt)
310388 * @author Minh Nguyen
311389 */
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.i18n.php
___________________________________________________________________
Modified: svn:mergeinfo
312390 Merged /trunk/extensions/LandingCheck/LandingCheck.i18n.php:r95543-101514

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88028Localisation updates for special page aliases for extensions from http://tran...siebrand00:11, 14 May 2011
r96108Localisation updates for core and extension messages from translatewiki.net...raymond15:48, 2 September 2011
r96184Localisation updates for core and extension messages from translatewiki.net...raymond13:52, 3 September 2011
r96248Localisation updates for core and extension messages from translatewiki.netraymond19:01, 4 September 2011
r96366Localisation updates for core and extension messages from translatewiki.netraymond20:24, 6 September 2011
r96961Update for magic words and special pages localisation for extensions from htt...siebrand13:33, 13 September 2011
r100773Spaces -> tabs for one poorly formatted lineawjrichards02:46, 26 October 2011
r101334Changes for LandingCheck 2.0 which adds the ability to have multiple servers ...awjrichards01:56, 31 October 2011
r101418follow-up to r101334, fixing minor issueskaldari22:19, 31 October 2011
r101419follow-up to r101418, fixing typokaldari22:19, 31 October 2011
r101426adding uselang to LandingCheckkaldari23:03, 31 October 2011

Status & tagging log