r83120 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83119‎ | r83120 | r83121 >
Date:21:40, 2 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
failed attempt to fix fails
Modified paths:
  • /branches/Maps0.8/includes/Maps_CoordinateParser.php (modified) (history)
  • /branches/Maps0.8/includes/Maps_Geocoders.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/ext.maps.googlemaps2.js (modified) (history)

Diff [purge]

Index: branches/Maps0.8/includes/Maps_Geocoders.php
@@ -141,6 +141,10 @@
142142 * @return array with coordinates or false
143143 */
144144 public static function geocode( $address, $geoService = '', $mappingService = false ) {
 145+ if ( !is_string( $address ) ) {
 146+ throw new Exception( 'Parameter $address must be a string at ' . __METHOD__ );
 147+ }
 148+
145149 if ( !self::canGeocode() ) {
146150 return false;
147151 }
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php
@@ -222,6 +222,8 @@
223223
224224 $dependencies = array();
225225
 226+ $dependencies[] = Html::linkedScript( "http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl=$langCode" );
 227+
226228 $dependencies[] = Html::inlineScript(
227229 'var googleMapsKey = '. json_encode( $egGoogleMapsKey ) . ';' .
228230 'var googleMapsKeys = '. json_encode( $egGoogleMapsKeys ) . ';' .
Index: branches/Maps0.8/includes/services/GoogleMaps/ext.maps.googlemaps2.js
@@ -10,43 +10,49 @@
1111 * This means that when the API is loaded, not all modules will have yet, so we need to
1212 * wait untill they are available before setting up the maps. Try every 100ms.
1313 */
14 -function loadGoogleMaps() {
15 - if ( typeof GLayer == 'undefined' ) {
16 - setTimeout( function() { loadGoogleMaps(); }, 100 );
17 - }
18 - else {
19 - if ( GBrowserIsCompatible() ) {
20 - window.unload = GUnload;
21 -
22 - window.GOverlays = [
23 - new GLayer("com.panoramio.all"),
24 - new GLayer("com.youtube.all"),
25 - new GLayer("org.wikipedia.en"),
26 - new GLayer("com.google.webcams")
27 - ];
28 -
29 - for ( i in window.maps.googlemaps2 ) {
30 - var map = new GoogleMap( jQuery, window.maps.googlemaps2[i] );
31 - map.initiate( i );
32 - }
33 - }
34 - else {
35 - alert( mediaWiki.msg( 'maps-googlemaps2-incompatbrowser' ) );
36 -
37 - for ( i in window.maps.googlemaps2 ) {
38 - // FIXME: common module with message not getting loaded for some reason
39 - jQuery( '#' + i ).text( mediaWiki.msg( 'maps-load-failed' ) );
40 - }
41 - }
42 - }
 14+function loadGoogleMaps( i ) {
 15+ //if ( typeof GLayer == 'undefined' && i < 30 ) {
 16+ // setTimeout( function() { loadGoogleMaps( i + 1 ); }, 100 );
 17+ //}
 18+ //else {
 19+
 20+ //}
4321 }
4422
4523 // Load the Google Maps v2 API.
 24+/*
4625 jQuery.getScript(
4726 'http://maps.google.com/maps?file=api&v=2&key=' + window.googleMapsKey + '&hl=' + window.googleLangCode,
48 - function () { loadGoogleMaps(); }
 27+ function () { loadGoogleMaps( 0 ); }
4928 );
 29+*/
5030
 31+jQuery(document).ready(function() {
 32+ if ( GBrowserIsCompatible() ) {
 33+ window.unload = GUnload;
 34+
 35+ window.GOverlays = [
 36+ new GLayer("com.panoramio.all"),
 37+ new GLayer("com.youtube.all"),
 38+ new GLayer("org.wikipedia.en"),
 39+ new GLayer("com.google.webcams")
 40+ ];
 41+
 42+ for ( i in window.maps.googlemaps2 ) {
 43+ var map = new GoogleMap( jQuery, window.maps.googlemaps2[i] );
 44+ map.initiate( i );
 45+ }
 46+ }
 47+ else {
 48+ alert( mediaWiki.msg( 'maps-googlemaps2-incompatbrowser' ) );
 49+
 50+ for ( i in window.maps.googlemaps2 ) {
 51+ // FIXME: common module with message not getting loaded for some reason
 52+ jQuery( '#' + i ).text( mediaWiki.msg( 'maps-load-failed' ) );
 53+ }
 54+ }
 55+});
 56+
5157 var GoogleMap = function( $, args ) {
5258 var args = cleanParameters( args );
5359
@@ -55,7 +61,7 @@
5662 }
5763
5864 function cleanParameters( args ) {
59 -
 65+ /*
6066 args.type = eval( args.type );
6167 var ts=[];
6268 var t;
@@ -65,7 +71,7 @@
6672 args.types = ts;
6773
6874 args.types = ensureTypeIsSelectable( args.type, args.types );
69 -
 75+ */
7076 return args;
7177 }
7278
@@ -74,9 +80,10 @@
7581 */
7682 function createGoogleMap( mapName, args ) {
7783 var mapElement = document.getElementById( mapName );
78 - var map = new GMap2( mapElement, { mapTypes: args.types } );
 84+ var map = new GMap2( mapElement/*, { mapTypes: args.types }*/ );
 85+
7986 map.name = mapName;
80 - map.setMapType( args.type );
 87+ //map.setMapType( args.type );
8188
8289 var hasSearchBar = false;
8390
@@ -138,11 +145,10 @@
139146 }
140147 }
141148
142 -/*
143 - var bounds = ((mapOptions.zoom == null || mapOptions.centre == null) && markers.length > 1) ? new GLatLngBounds() : null;
 149+ var bounds = ((args.zoom == null || args.centre == null) && args.locations.length > 1) ? new GLatLngBounds() : null;
144150
145 - for ( i = markers.length - 1; i >= 0; i-- ) {
146 - var marker = markers[i];
 151+ for ( i = args.locations.length - 1; i >= 0; i-- ) {
 152+ var marker = args.locations[i];
147153 marker.point = new GLatLng( marker.lat, marker.lon );
148154 map.addOverlay( createGMarker( marker ) );
149155 if ( bounds != null ) bounds.extend( marker.point );
@@ -152,17 +158,24 @@
153159 map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
154160 }
155161
156 - if (mapOptions.centre != null) map.setCenter(mapOptions.centre);
157 - if (mapOptions.zoom != null) map.setZoom(mapOptions.zoom);
 162+ if ( args.centre !== false ) {
 163+ map.setCenter( args.centre );
 164+ }
158165
159 - if (mapOptions.scrollWheelZoom) map.enableScrollWheelZoom();
 166+ if ( args.zoom !== false ) {
 167+ map.setZoom( args.zoom );
 168+ }
 169+
 170+ if ( args.autozoom ) {
 171+ map.enableScrollWheelZoom();
 172+ }
160173
161174 map.enableContinuousZoom();
162175
163176 // Code to add KML files.
164177 var kmlOverlays = [];
165 - for ( i = mapOptions.kml.length - 1; i >= 0; i-- ) {
166 - kmlOverlays[i] = new GGeoXml( mapOptions.kml[i] );
 178+ for ( i = args.kml.length - 1; i >= 0; i-- ) {
 179+ kmlOverlays[i] = new GGeoXml( args.kml[i] );
167180 map.addOverlay( kmlOverlays[i] );
168181 }
169182
@@ -171,7 +184,6 @@
172185 eval("window.GMaps." + mapName + " = map;");
173186
174187 return map;
175 - */
176188 }
177189
178190 function ensureTypeIsSelectable( type, types ) {
@@ -225,9 +237,9 @@
226238 marker = new GMarker( markerData.point );
227239 }
228240
229 - if ( ( markerData.title + markerData.label ).length != '' ) {
230 - var bothTxtAreSet = markerData.title.length != '' && markerData.label.length != '';
231 - var popupText = bothTxtAreSet ? '<b>' + markerData.title + '</b><hr />' + markerData.label : markerData.title + markerData.label;
 241+ if ( markerData.title + markerData.text != '' ) {
 242+ var bothTxtAreSet = markerData.title != '' && markerData.text != '';
 243+ var popupText = bothTxtAreSet ? '<b>' + markerData.title + '</b><hr />' + markerData.label : markerData.title + markerData.text;
232244 popupText = '<div style="overflow:auto;max-height:130px;">' + popupText + '</div>';
233245
234246 GEvent.addListener(marker, 'click',
Index: branches/Maps0.8/includes/Maps_CoordinateParser.php
@@ -520,6 +520,10 @@
521521 * @return string
522522 */
523523 protected static function parseDMSCoordinate( $coordinate ) {
 524+ if ( !is_string( $coordinate ) ) {
 525+ throw new Exception( 'Parameter $coordinate must be a string at ' . __METHOD__ );
 526+ }
 527+
524528 $isNegative = $coordinate{0} == '-';
525529 if ( $isNegative ) $coordinate = substr( $coordinate, 1 );
526530

Status & tagging log