r65019 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65018‎ | r65019 | r65020 >
Date:12:41, 14 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - Added language code mappings for Google Maps.
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3.php
@@ -61,36 +61,36 @@
6262 $allowedTypes = self::getTypeNames();
6363
6464 $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
65 - 'type' => array(
66 - 'aliases' => array( 'map-type', 'map type' ),
67 - 'criteria' => array(
68 - 'in_array' => $allowedTypes
69 - ),
70 - 'default' => $egMapsGMaps3Type, // FIXME: default value should not be used when not present in types parameter.
71 - 'output-type' => 'gmap3type'
72 - ),
73 - /*
74 - 'types' => array(
75 - 'type' => array('string', 'list'),
76 - 'aliases' => array('map-types', 'map types'),
77 - 'criteria' => array(
78 - 'in_array' => $allowedTypes
79 - ),
80 - 'default' => $egMapsGMaps3Types,
81 - 'output-types' => array('gmap3types', 'list')
82 - ),
83 - */
84 - );
 65+ 'type' => array(
 66+ 'aliases' => array( 'map-type', 'map type' ),
 67+ 'criteria' => array(
 68+ 'in_array' => $allowedTypes
 69+ ),
 70+ 'default' => $egMapsGMaps3Type, // FIXME: default value should not be used when not present in types parameter.
 71+ 'output-type' => 'gmap3type'
 72+ ),
 73+ /*
 74+ 'types' => array(
 75+ 'type' => array('string', 'list'),
 76+ 'aliases' => array('map-types', 'map types'),
 77+ 'criteria' => array(
 78+ 'in_array' => $allowedTypes
 79+ ),
 80+ 'default' => $egMapsGMaps3Types,
 81+ 'output-types' => array('gmap3types', 'list')
 82+ ),
 83+ */
 84+ );
8585 }
8686
8787 private static $mapTypes = array(
88 - 'normal' => 'ROADMAP',
89 - 'roadmap' => 'ROADMAP',
90 - 'satellite' => 'SATELLITE',
91 - 'hybrid' => 'HYBRID',
92 - 'terrain' => 'TERRAIN',
93 - 'physical' => 'TERRAIN'
94 - );
 88+ 'normal' => 'ROADMAP',
 89+ 'roadmap' => 'ROADMAP',
 90+ 'satellite' => 'SATELLITE',
 91+ 'hybrid' => 'HYBRID',
 92+ 'terrain' => 'TERRAIN',
 93+ 'physical' => 'TERRAIN'
 94+ );
9595
9696 /**
9797 * Returns the names of all supported map types.
@@ -137,9 +137,29 @@
138138 if ( empty( $egGMaps3OnThisPage ) ) {
139139 $egGMaps3OnThisPage = 0;
140140
141 - $output .= "<script type='$wgJsMimeType' src='http://maps.google.com/maps/api/js?sensor=false&amp;language={$wgLang->getCode()}'></script><script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps3/GoogleMap3Functions{$egMapsJsExt}?$egMapsStyleVersion'></script>";
 141+ $languageCode = self::getMappedLanguageCode( $wgLang->getCode() );
 142+ $output .= "<script type='$wgJsMimeType' src='http://maps.google.com/maps/api/js?sensor=false&amp;language={$languageCode}'></script><script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps3/GoogleMap3Functions{$egMapsJsExt}?$egMapsStyleVersion'></script>";
142143 }
143144 }
144145
 146+ /**
 147+ * Maps language codes to Google Maps API v3 compatible values.
 148+ *
 149+ * @param string $code
 150+ *
 151+ * @return string The mapped code
 152+ */
 153+ private static function getMappedLanguageCode( $code ) {
 154+ $mappings = array(
 155+ 'en_gb' => 'en-gb',// v3 supports en_gb - but wants us to call it en-gb
 156+ 'he' => 'iw', // iw is googlish for hebrew
 157+ 'fj' => 'fil', // google does not support Fijian - use Filipino as close(?) supported relative
 158+ );
 159+ if ( array_key_exists( $code, $mappings ) ) {
 160+ $code = $mappings[$code];
 161+ }
 162+ return $code;
 163+ }
 164+
145165 }
146166
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -207,11 +207,32 @@
208208
209209 MapsGoogleMaps::validateGoogleMapsKey();
210210
211 - $output .= "<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=$egGoogleMapsKey&amp;hl={$wgLang->getCode()}' type='$wgJsMimeType'></script><script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions{$egMapsJsExt}?$egMapsStyleVersion'></script><script type='$wgJsMimeType'>window.unload = GUnload;</script>";
 211+ $langCode = self::getMappedLanguageCode( $wgLang->getCode() );
 212+ $output .= "<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=$egGoogleMapsKey&amp;hl={$langCode}' type='$wgJsMimeType'></script><script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions{$egMapsJsExt}?$egMapsStyleVersion'></script><script type='$wgJsMimeType'>window.unload = GUnload;</script>";
212213 }
213214 }
214215
215216 /**
 217+ * Maps language codes to Google Maps API v2 compatible values.
 218+ *
 219+ * @param string $code
 220+ *
 221+ * @return string The mapped code
 222+ */
 223+ private static function getMappedLanguageCode( $code ) {
 224+ $mappings = array(
 225+ 'en_gb' => 'en',// v2 does not support en_gb - use english :(
 226+ 'he' => 'iw', // iw is googlish for hebrew
 227+ 'fj' => 'fil', // google does not support Fijian - use Filipino as close(?) supported relative
 228+ 'or' => 'en' // v2 does not support Oriya.
 229+ );
 230+ if ( array_key_exists( $code, $mappings ) ) {
 231+ $code = $mappings[$code];
 232+ }
 233+ return $code;
 234+ }
 235+
 236+ /**
216237 * This function ensures backward compatibility with Semantic Google Maps and other extensions
217238 * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
218239 *
@@ -295,10 +316,9 @@
296317 }
297318
298319 /**
 320+ * Add CSS for the overlays.
299321 *
300 - *
301322 * @param $output
302 - * @return unknown_type
303323 */
304324 private static function addOverlayCss( &$output ) {
305325 $css = <<<END

Status & tagging log