Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.php |
— | — | @@ -13,16 +13,12 @@ |
14 | 14 | $wgExtensionCredits['specialpage'][] = array( |
15 | 15 | 'path' => __FILE__, |
16 | 16 | 'name' => 'LandingCheck', |
17 | | - 'version' => '1.2', |
| 17 | + 'version' => '2.0', |
18 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:LandingCheck', |
19 | | - 'author' => 'Ryan Kaldari', |
| 19 | + 'author' => array( 'Ryan Kaldari', 'Arthur Richards' ), |
20 | 20 | 'descriptionmsg' => 'landingcheck-desc', |
21 | 21 | ); |
22 | 22 | |
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 | | - |
27 | 23 | $dir = dirname( __FILE__ ) . '/'; |
28 | 24 | |
29 | 25 | $wgAutoloadClasses['SpecialLandingCheck'] = $dir . 'SpecialLandingCheck.php'; |
— | — | @@ -30,3 +26,25 @@ |
31 | 27 | $wgExtensionAliasesFiles['LandingCheck'] = $dir . 'LandingCheck.alias.php'; |
32 | 28 | $wgSpecialPages['LandingCheck'] = 'SpecialLandingCheck'; |
33 | 29 | $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 |
34 | 52 | Merged /branches/wmf-deployment/extensions/LandingCheck/LandingCheck.php:r60970 |
35 | 53 | Merged /branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.php:r67177,69199,76243,77266 |
36 | 54 | Merged /trunk/extensions/LandingCheck/LandingCheck.php:r76551,77519-77521,77622-78860,101335-101514 |
37 | 55 | 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 @@ |
11 | 11 | * it looks for the English version. If any of those exist, it then redirects the user. |
12 | 12 | */ |
13 | 13 | class SpecialLandingCheck extends SpecialPage { |
| 14 | + protected $localServerType = null; |
14 | 15 | |
15 | 16 | public function __construct() { |
16 | 17 | // Register special page |
— | — | @@ -17,7 +18,7 @@ |
18 | 19 | } |
19 | 20 | |
20 | 21 | public function execute( $sub ) { |
21 | | - global $wgOut, $wgRequest, $wgPriorityCountries; |
| 22 | + global $wgRequest, $wgPriorityCountries; |
22 | 23 | |
23 | 24 | // Pull in query string parameters |
24 | 25 | $language = $wgRequest->getVal( 'language', 'en' ); |
— | — | @@ -25,7 +26,7 @@ |
26 | 27 | $country = $wgRequest->getVal( 'country' ); |
27 | 28 | // If no country was passed, try to do GeoIP lookup |
28 | 29 | // Requires php5-geoip package |
29 | | - if ( !$country && function_exists( geoip_country_code_by_name ) ) { |
| 30 | + if ( !$country && function_exists( 'geoip_country_code_by_name' ) ) { |
30 | 31 | $ip = wfGetIP(); |
31 | 32 | if ( IP::isValid( $ip ) ) { |
32 | 33 | $country = geoip_country_code_by_name( $ip ); |
— | — | @@ -35,6 +36,102 @@ |
36 | 37 | $country = 'US'; // Default |
37 | 38 | } |
38 | 39 | |
| 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; |
39 | 136 | $landingPage = $wgRequest->getVal( 'landing_page', 'Donate' ); |
40 | 137 | |
41 | 138 | // Construct new query string for tracking |
— | — | @@ -43,11 +140,12 @@ |
44 | 141 | 'utm_medium' => $wgRequest->getVal( 'utm_medium' ), |
45 | 142 | 'utm_campaign' => $wgRequest->getVal( 'utm_campaign' ), |
46 | 143 | 'language' => $wgRequest->getVal( 'language', 'en'), |
| 144 | + 'uselang' => $wgRequest->getVal( 'language', 'en'), // for {{int:xxx}} rendering |
47 | 145 | 'country' => $country, |
48 | 146 | 'referrer' => $wgRequest->getHeader( 'referer' ) |
49 | 147 | ) ); |
50 | 148 | |
51 | | - if ( in_array( $country, $wgPriorityCountries ) ) { |
| 149 | + if ( $priority ) { |
52 | 150 | // Build array of landing pages to check for |
53 | 151 | $targetTexts = array( |
54 | 152 | $landingPage . '/' . $country . '/' . $language, |
— | — | @@ -75,6 +173,27 @@ |
76 | 174 | return; |
77 | 175 | } |
78 | 176 | } |
79 | | - |
80 | 177 | } |
| 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 | + } |
81 | 200 | } |
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/SpecialLandingCheck.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
82 | 201 | Merged /trunk/extensions/LandingCheck/SpecialLandingCheck.php:r100774-101514 |
Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.alias.php |
— | — | @@ -8,13 +8,51 @@ |
9 | 9 | |
10 | 10 | $specialPageAliases = array(); |
11 | 11 | |
12 | | -/** English |
13 | | - * @author Ryan Kaldari |
14 | | - */ |
| 12 | +/** English (English) */ |
15 | 13 | $specialPageAliases['en'] = array( |
16 | 14 | 'LandingCheck' => array( 'LandingCheck' ), |
17 | 15 | ); |
18 | 16 | |
| 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 | + |
19 | 57 | /** |
20 | 58 | * For backwards compatibility with MediaWiki 1.15 and earlier. |
21 | 59 | */ |
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.alias.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
22 | 60 | Merged /branches/wmf/1.16wmf4/extensions/LandingCheck/LandingCheck.alias.php:r67177,69199,76243,77266 |
23 | 61 | Merged /trunk/extensions/LandingCheck/LandingCheck.alias.php:r76551,77519-77521,77622-78860,88029-101514 |
24 | 62 | 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 |
25 | 63 | Merged /branches/wmf-deployment/extensions/LandingCheck/LandingCheck.alias.php:r60970 |
Index: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.i18n.php |
— | — | @@ -16,6 +16,15 @@ |
17 | 17 | 'landingcheck' => 'LandingCheck', |
18 | 18 | ); |
19 | 19 | |
| 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 | + |
20 | 29 | /** Afrikaans (Afrikaans) |
21 | 30 | * @author Naudefj |
22 | 31 | */ |
— | — | @@ -24,6 +33,14 @@ |
25 | 34 | 'landingcheck' => 'Landingskontrole', |
26 | 35 | ); |
27 | 36 | |
| 37 | +/** Arabic (العربية) |
| 38 | + * @author زكريا |
| 39 | + */ |
| 40 | +$messages['ar'] = array( |
| 41 | + 'landingcheck-desc' => 'لتيسير استعمال صفحات تحديد موقع الوصول الجغرافي', |
| 42 | + 'landingcheck' => 'LandingCheck', |
| 43 | +); |
| 44 | + |
28 | 45 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
29 | 46 | * @author EugeneZelenko |
30 | 47 | * @author Jim-by |
— | — | @@ -82,6 +99,36 @@ |
83 | 100 | 'landingcheck-desc' => 'Facilitates the use of geotargeted localised landing pages', |
84 | 101 | ); |
85 | 102 | |
| 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 | + |
86 | 133 | /** French (Français) |
87 | 134 | * @author Peter17 |
88 | 135 | */ |
— | — | @@ -94,6 +141,7 @@ |
95 | 142 | * @author ChrisPtDe |
96 | 143 | */ |
97 | 144 | $messages['frp'] = array( |
| 145 | + 'landingcheck-desc' => 'Facilite l’usâjo de les pâges d’arrevâ g·eolocalisâs.', |
98 | 146 | 'landingcheck' => 'LandingCheck', |
99 | 147 | ); |
100 | 148 | |
— | — | @@ -258,6 +306,13 @@ |
259 | 307 | 'landingcheck' => 'LandingCheck', |
260 | 308 | ); |
261 | 309 | |
| 310 | +/** Romanian (Română) |
| 311 | + * @author Firilacroco |
| 312 | + */ |
| 313 | +$messages['ro'] = array( |
| 314 | + 'landingcheck' => 'LandingCheck', |
| 315 | +); |
| 316 | + |
262 | 317 | /** Tarandíne (Tarandíne) |
263 | 318 | * @author Joetaras |
264 | 319 | */ |
— | — | @@ -273,6 +328,14 @@ |
274 | 329 | 'landingcheck' => 'LandingCheck', |
275 | 330 | ); |
276 | 331 | |
| 332 | +/** Rusyn (Русиньскый) |
| 333 | + * @author Gazeb |
| 334 | + */ |
| 335 | +$messages['rue'] = array( |
| 336 | + 'landingcheck-desc' => 'Злегчує хоснованя ґеоґрафічно цїленых локалізованых вступных сторінок', |
| 337 | + 'landingcheck' => 'LandingCheck', |
| 338 | +); |
| 339 | + |
277 | 340 | /** Sakha (Саха тыла) |
278 | 341 | * @author HalanTul |
279 | 342 | */ |
— | — | @@ -297,6 +360,13 @@ |
298 | 361 | 'landingcheck' => 'PreverjanjePristajališča', |
299 | 362 | ); |
300 | 363 | |
| 364 | +/** Swedish (Svenska) |
| 365 | + * @author WikiPhoenix |
| 366 | + */ |
| 367 | +$messages['sv'] = array( |
| 368 | + 'landingcheck' => 'LandingCheck', |
| 369 | +); |
| 370 | + |
301 | 371 | /** Tagalog (Tagalog) |
302 | 372 | * @author AnakngAraw |
303 | 373 | */ |
— | — | @@ -305,6 +375,14 @@ |
306 | 376 | 'landingcheck' => 'Pagsusuri ng Paglapag', |
307 | 377 | ); |
308 | 378 | |
| 379 | +/** Ukrainian (Українська) |
| 380 | + * @author Dim Grits |
| 381 | + */ |
| 382 | +$messages['uk'] = array( |
| 383 | + 'landingcheck-desc' => 'Полегшує використання геозалежних локалізованих цільових сторінок', |
| 384 | + 'landingcheck' => 'LandingCheck', |
| 385 | +); |
| 386 | + |
309 | 387 | /** Vietnamese (Tiếng Việt) |
310 | 388 | * @author Minh Nguyen |
311 | 389 | */ |
Property changes on: branches/wmf/1.18wmf1/extensions/LandingCheck/LandingCheck.i18n.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
312 | 390 | Merged /trunk/extensions/LandingCheck/LandingCheck.i18n.php:r95543-101514 |