r76228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76227‎ | r76228 | r76229 >
Date:00:58, 7 November 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Fixed incorrect loading of bc class
Modified paths:
  • /trunk/extensions/Maps/Maps.hooks.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_MappingService.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_MappingServices.php (modified) (history)
  • /trunk/extensions/Maps/includes/features/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/parserHooks/Maps_DisplayMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OSM/Maps_OSMDispMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayers.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/OpenLayerFunctions.js (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/ext.maps.openlayers.js (added) (history)
  • /trunk/extensions/Maps/includes/services/YahooMaps/Maps_YahooMapsDispMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.php
@@ -36,7 +36,7 @@
3737 echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
3838 }
3939 else {
40 - define( 'Maps_VERSION', '0.7.2' );
 40+ define( 'Maps_VERSION', '0.7.3 alpha' );
4141
4242 // The different coordinate notations.
4343 define( 'Maps_COORDS_FLOAT', 'float' );
@@ -113,7 +113,7 @@
114114 $wgAutoloadClasses['MapsGeodistance'] = $phDir . 'Maps_Geodistance.php';
115115
116116 // To ensure Maps remains compatible with pre 1.16.
117 - if ( !array_key_exists( 'Html', $wgAutoloadClasses ) ) {
 117+ if ( !class_exists( 'Html' ) ) {
118118 $wgAutoloadClasses['Html'] = $egMapsDir . 'compat/Html.php';
119119 }
120120
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -406,8 +406,11 @@
407407 'yahoo' => "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>",
408408 'bing' => "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>",
409409 'ol-wms' => "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>",
410 - 'osm' => "<script type='$wgJsMimeType' src='$egMapsScriptPath/includes/services/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>",
411410 );
 411+
 412+ if ( !method_exists( 'OutputPage', 'addModules' ) ) {
 413+ $egMapsOLLayerDependencies['osm'] = "<script type='$wgJsMimeType' src='$egMapsScriptPath/includes/services/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>";
 414+ }
412415
413416
414417
Index: trunk/extensions/Maps/includes/Maps_MappingService.php
@@ -108,14 +108,24 @@
109109 $dependencies = $this->getDependencyHtml();
110110
111111 // Only add a head item when there are dependencies.
112 - if ( $dependencies ) {
113 - if ( $parserOrOut instanceof Parser ) {
 112+ if ( $parserOrOut instanceof Parser ) {
 113+ if ( $dependencies ) {
114114 $parserOrOut->getOutput()->addHeadItem( $dependencies );
115 - }
116 - else if ( $parserOrOut instanceof OutputPage ) {
 115+ }
 116+
 117+ if ( method_exists( $parserOrOut->getOutput(), 'addModules' ) ) {
 118+ $parserOrOut->getOutput()->addModules( $this->getResourceModules() );
 119+ }
 120+ }
 121+ else if ( $parserOrOut instanceof OutputPage ) {
 122+ if ( $dependencies ) {
117123 $parserOrOut->addHeadItem( md5( $dependencies ), $dependencies );
118 - }
119 - }
 124+ }
 125+
 126+ if ( method_exists( $parserOrOut, 'addModules' ) ) {
 127+ $parserOrOut->addModules( $this->getResourceModules() );
 128+ }
 129+ }
120130 }
121131
122132 /**
@@ -210,4 +220,26 @@
211221 return array();
212222 }
213223
 224+ /**
 225+ * Returns the resource modules that need to be loaded to use this mapping service.
 226+ *
 227+ * @since 0.7.3
 228+ *
 229+ * @return array of string
 230+ */
 231+ protected function getResourceModules() {
 232+ return array();
 233+ }
 234+
 235+ /**
 236+ * Returns the modules definitions for the resources of this mapping service.
 237+ *
 238+ * @since 0.7.3
 239+ *
 240+ * @return array of arrays
 241+ */
 242+ public function getResourceModuleDefinitions() {
 243+ return array();
 244+ }
 245+
214246 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php
@@ -1,31 +1,18 @@
22 <?php
33
44 /**
5 - * Class for handling the display_map parser function with Google Maps v3.
 5+ * Class for handling the display_map parser hook with Google Maps v3.
66 *
7 - * @file Maps_GoogleMaps3DispMap.php
87 * @ingroup MapsGoogleMaps3
98 *
109 * @author Jeroen De Dauw
1110 */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -/**
18 - * Class for handling the display_map parser functions with Google Maps v3.
19 - *
20 - * @ingroup MapsGoogleMaps3
21 - *
22 - * @author Jeroen De Dauw
23 - */
2411 final class MapsGoogleMaps3DispMap extends MapsBaseMap {
2512
2613 /**
27 - * @see MapsBaseMap::addSpecificMapHTML()
 14+ * @see MapsBaseMap::getMapHTML()
2815 */
29 - public function addSpecificMapHTML( Parser $parser ) {
 16+ public function getMapHTML( array $params, Parser $parser ) {
3017 $mapName = $this->service->getMapId();
3118
3219 $this->output .= Html::element(
Index: trunk/extensions/Maps/includes/services/YahooMaps/Maps_YahooMapsDispMap.php
@@ -1,24 +1,19 @@
22 <?php
33
44 /**
5 - * Class for handling the display_map parser function with Yahoo! Maps
 5+ * Class for handling the display_map parser hook with Yahoo! Maps
66 *
77 * @file Maps_YahooMapsDispMap.php
88 * @ingroup MapsYahooMaps
99 *
1010 * @author Jeroen De Dauw
1111 */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
1712 class MapsYahooMapsDispMap extends MapsBaseMap {
1813
1914 /**
20 - * @see MapsBaseMap::addSpecificMapHTML()
 15+ * @see MapsBaseMap::getMapHTML()
2116 */
22 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function getMapHTML( array $params, Parser $parser ) {
2318 $mapName = $this->service->getMapId();
2419
2520 $this->output .= Html::element(
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php
@@ -87,11 +87,10 @@
8888 }
8989 }
9090 }
91 -
92 - $parameter->setValue( array(
93 - '[' . implode( ',', $layerDefs ) . ']',
94 - $this->getDependencies( $layerNames )
95 - ) );
 91+
 92+ $parameter->setValue( method_exists( 'OutputPage', 'addModules' ) ? $layerDefs : '[' . implode( ',', $layerDefs ) . ']' );
 93+
 94+ MapsOpenLayers::addLayerDependencies( $this->getDependencies( $layerNames ) );
9695 }
9796
9897 /**
Index: trunk/extensions/Maps/includes/services/OpenLayers/OpenLayerFunctions.js
@@ -1,5 +1,7 @@
22 /**
3 - * Javascript functions for Open Layers functionality in Maps and its extensions
 3+ * Javascript functions for Open Layers functionality in Maps and its extensions.
 4+ *
 5+ * Note: This file is for backward compatibility with MediaWiki <=1.16.
46 *
57 * @file OpenLayerFunctions.js
68 * @ingroup MapsOpenLayers
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayersDispMap.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_map parser function with OpenLayers.
 5+ * Class for handling the display_map parser hook with OpenLayers.
66 *
77 * @file Maps_OpenLayersDispMap.php
88 * @ingroup MapsOpenLayers
@@ -11,39 +11,60 @@
1212 class MapsOpenLayersDispMap extends MapsBaseMap {
1313
1414 /**
15 - * @see MapsBaseMap::addSpecificMapHTML()
 15+ * @see MapsBaseMap::getJSONObject
 16+ *
 17+ * @since 0.7.3
 18+ *
 19+ * @param array $params
 20+ * @param Parser $parser
 21+ *
 22+ * @return mixed
 23+ */
 24+ protected function getJSONObject( array $params, Parser $parser ) {
 25+ global $wgLang;
 26+ $params['langCode'] = $wgLang->getCode();
 27+ return $params;
 28+ }
 29+
 30+ /**
 31+ * @see MapsBaseMap::getMapHTML
 32+ *
 33+ * @since 0.7.3
1634 */
17 - public function addSpecificMapHTML( Parser $parser ) {
 35+ public function getMapHTML( array $params, Parser $parser ) {
1836 global $wgLang;
1937
20 - $this->service->addLayerDependencies( $this->layers[1] );
21 -
2238 $mapName = $this->service->getMapId();
2339
24 - $this->output .= Html::element(
 40+ if ( !method_exists( 'OutputPage', 'addModules' ) ) {
 41+ $langCode = $wgLang->getCode();
 42+ $centreLat = MapsMapper::encodeJsVar( $params['centre']['lat'] );
 43+ $centreLon = MapsMapper::encodeJsVar( $params['centre']['lon'] );
 44+ $zoom = MapsMapper::encodeJsVar( $params['zoom'] );
 45+
 46+ MapsMapper::addInlineScript( $this->service, <<<EOT
 47+ initOpenLayer(
 48+ "$mapName",
 49+ $centreLon,
 50+ $centreLat,
 51+ $zoom,
 52+ {$params['layers'][0]},
 53+ [{$params['controls']}],
 54+ [],
 55+ "$langCode"
 56+ );
 57+EOT
 58+ );
 59+ }
 60+
 61+ return Html::element(
2562 'div',
2663 array(
2764 'id' => $mapName,
28 - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;",
 65+ 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;",
2966 ),
3067 wfMsg( 'maps-loading-map' )
31 - );
32 -
33 - $langCode = $wgLang->getCode();
34 -
35 - MapsMapper::addInlineScript( $this->service, <<<EOT
36 - initOpenLayer(
37 - "$mapName",
38 - $this->centreLon,
39 - $this->centreLat,
40 - $this->zoom,
41 - {$this->layers[0]},
42 - [$this->controls],
43 - [],
44 - "$langCode"
45 - );
46 -EOT
47 - );
 68+ );
4869 }
4970
5071 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_OpenLayers.php
@@ -40,10 +40,15 @@
4141 $params['controls']->setDefault( $egMapsOLControls );
4242 $params['controls']->addCriteria( new CriterionInArray( self::getControlNames() ) );
4343 $params['controls']->addManipulations(
44 - new ParamManipulationFunctions( 'strtolower' ),
45 - new ParamManipulationImplode( ',', "'" )
 44+ new ParamManipulationFunctions( 'strtolower' )
4645 );
4746
 47+ if ( !method_exists( 'OutputPage', 'addModules' ) ) {
 48+ $params['controls']->addManipulations(
 49+ new ParamManipulationImplode( ',', "'" )
 50+ );
 51+ }
 52+
4853 $params['layers'] = new ListParameter( 'layers' );
4954 $params['layers']->addManipulations( new MapsParamOLLayers() );
5055 $params['layers']->setDoManipulationOfDefault( true );
@@ -86,7 +91,7 @@
8792 public function createMarkersJs( array $markers ) {
8893 $markerItems = array();
8994 $defaultGroup = wfMsg( 'maps-markers' );
90 - //.// TODO
 95+
9196 foreach ( $markers as $marker ) {
9297 $markerItems[] = MapsMapper::encodeJsVar( (object)array(
9398 'lat' => $marker[0],
@@ -109,12 +114,17 @@
110115 protected function getDependencies() {
111116 global $egMapsStyleVersion, $egMapsScriptPath;
112117
113 - return array(
114 - Html::linkedStyle( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/theme/default/style.css" ),
115 - Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/OpenLayers.js?$egMapsStyleVersion" ),
116 - Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayerFunctions.js?$egMapsStyleVersion" ),
117 - Html::inlineScript( 'initOLSettings(200, 100); var msgMarkers = ' . Xml::encodeJsVar( wfMsg( 'maps-markers' ) ) . ';' )
118 - );
 118+ if ( method_exists( 'OutputPage', 'addModules' ) ) {
 119+ return array();
 120+ }
 121+ else {
 122+ return array(
 123+ Html::linkedStyle( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/theme/default/style.css" ),
 124+ Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayers/OpenLayers.js?$egMapsStyleVersion" ),
 125+ Html::linkedScript( "$egMapsScriptPath/includes/services/OpenLayers/OpenLayerFunctions.js?$egMapsStyleVersion" ),
 126+ Html::inlineScript( 'initOLSettings(200, 100); var msgMarkers = ' . Xml::encodeJsVar( wfMsg( 'maps-markers' ) ) . ';' )
 127+ );
 128+ }
119129 }
120130
121131 /**
@@ -167,4 +177,43 @@
168178 }
169179 }
170180
 181+ /**
 182+ * @see MapsMappingService::getResourceModules
 183+ *
 184+ * @since 0.7.3
 185+ *
 186+ * @return array of string
 187+ */
 188+ protected function getResourceModules() {
 189+ return array( 'ext.maps.openlayers', 'ext.maps.osm' );
 190+ }
 191+
 192+ /**
 193+ * @see MapsMappingService::getResourceModuleDefinitions
 194+ *
 195+ * @since 0.7.3
 196+ *
 197+ * @return array of arrays
 198+ */
 199+ public function getResourceModuleDefinitions() {
 200+ return array(
 201+ 'ext.maps.openlayers' => array(
 202+ 'scripts' => array(
 203+ 'OpenLayers/OpenLayers.js',
 204+ 'ext.maps.openlayers.js'
 205+ ),
 206+ 'styles' => array(
 207+ 'OpenLayers/theme/default/style.css'
 208+ ),
 209+ 'dependencies' => 'ext.maps.common'
 210+ ),
 211+ 'ext.maps.osm' => array(
 212+ 'scripts' => array(
 213+ 'OSM/OpenStreetMap.js',
 214+ ),
 215+ 'dependencies' => 'ext.maps.openlayers'
 216+ )
 217+ );
 218+ }
 219+
171220 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/services/OpenLayers/ext.maps.openlayers.js
@@ -0,0 +1,203 @@
 2+/**
 3+ * JavasSript for OpenLayers maps in the Maps extension.
 4+ * @see http://www.mediawiki.org/wiki/Extension:Maps
 5+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 6+ */
 7+
 8+$( document ).ready( function() {
 9+
 10+ OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
 11+ OpenLayers.Util.onImageLoadErrorColor = 'transparent';
 12+ OpenLayers.Feature.prototype.popupClass = OpenLayers.Class(
 13+ OpenLayers.Popup.FramedCloud,
 14+ {
 15+ 'autoSize': true,
 16+ 'minSize': new OpenLayers.Size( 200, 100 )
 17+ }
 18+ );
 19+
 20+ for ( i = 0, n = window.maps['openlayers'].length; i < n; i++ ) {
 21+ initiateMap( window.maps['openlayers'][i] );
 22+ }
 23+
 24+ function initiateMap( params ) {
 25+ OpenLayers.Lang.setCode( params.langCode );
 26+
 27+ var hasImageLayer = false;
 28+ for ( i = 0, n = params.layers.length; i < n; i++ ) {
 29+ // Idieally this would check if the objecct is of type OpenLayers.layer.image
 30+ if ( params.layers[i].options && params.layers[i].options.isImage === true ) {
 31+ hasImageLayer = true;
 32+ break;
 33+ }
 34+ }
 35+
 36+ // Create a new OpenLayers map with without any controls on it.
 37+ var mapOptions = {
 38+ controls: []
 39+ };
 40+
 41+ if ( !hasImageLayer ) {
 42+ mapOptions.projection = new OpenLayers.Projection("EPSG:900913");
 43+ mapOptions.displayProjection = new OpenLayers.Projection("EPSG:4326");
 44+ mapOptions.units = "m";
 45+ mapOptions.numZoomLevels = 18;
 46+ mapOptions.maxResolution = 156543.0339;
 47+ mapOptions.maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34);
 48+ }
 49+
 50+ // TODO
 51+ var mapElement = document.getElementById( 'open_layer_1' );
 52+
 53+ // Remove the loading map message.
 54+ mapElement.innerHTML = '';
 55+ alert('');
 56+ // TODO
 57+ var map = new OpenLayers.Map( 'open_layer_1', mapOptions );
 58+ alert('');
 59+ addControls( map, params.controls, mapElement );
 60+
 61+ // Add the base layers.
 62+ for ( i = 0, n = params.layers.length; i < n; i++ ) map.addLayer( params.layers[i] );
 63+
 64+ // Layer to hold the markers.
 65+ var markerLayer = new OpenLayers.Layer.Markers( 'Markers' ); // TODO
 66+ markerLayer.id= 'markerLayer';
 67+ map.addLayer( markerLayer );
 68+
 69+ var centerIsSet = params.centre.lon != null && params.centre.lat != null;
 70+
 71+ addMarkers( map, params, markerLayer, centerIsSet );
 72+
 73+ if ( centerIsSet ) { // When the center is provided, set it.
 74+ var centre = new OpenLayers.LonLat( params.centre.lon, params.centre.lat );
 75+
 76+ if ( !hasImageLayer ) {
 77+ centre.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
 78+ }
 79+
 80+ map.setCenter( centre );
 81+ }
 82+
 83+ if (params.zoom != null) map.zoomTo(params.zoom); // When the zoom is provided, set it.
 84+ }
 85+
 86+ function addControls( map, controls, mapElement ) {
 87+ // Add the controls.
 88+ for ( var i = controls.length - 1; i >= 0; i-- ) {
 89+
 90+ // If a string is provided, find the correct name for the control, and use eval to create the object itself.
 91+ if ( typeof controls[i] == 'string' ) {
 92+ if ( controls[i].toLowerCase() == 'autopanzoom' ) {
 93+ if ( mapElement.offsetHeight > 140 ) controls[i] = mapElement.offsetHeight > 320 ? 'panzoombar' : 'panzoom';
 94+ }
 95+
 96+ control = getValidControlName( controls[i] );
 97+
 98+ if ( control ) {
 99+ eval(' map.addControl( new OpenLayers.Control.' + control + '() ); ');
 100+ }
 101+ }
 102+ else {
 103+ map.addControl(controls[i]); // If a control is provided, instead a string, just add it.
 104+ controls[i].activate(); // And activate it.
 105+ }
 106+
 107+ }
 108+ }
 109+
 110+ function addMarkers( map, params, markerLayer, centerIsSet ) {
 111+ var bounds = null;
 112+
 113+ if ( params.markers.length > 1 && ( !centerIsSet || params.zoom == null ) ) {
 114+ bounds = new OpenLayers.Bounds();
 115+ }
 116+
 117+ for ( i = params.markers.length - 1; i >= 0; i-- ) {
 118+ params.markers[i].lonlat = new OpenLayers.LonLat( params.markers[i].lon, params.markers[i].lat );
 119+
 120+ if ( !hasImageLayer ) {
 121+ params.markers[i].lonlat.transform( new OpenLayers.Projection( "EPSG:4326" ), new OpenLayers.Projection( "EPSG:900913" ) );
 122+ }
 123+
 124+ if ( bounds != null ) bounds.extend( params.markers[i].lonlat ); // Extend the bounds when no center is set.
 125+ markerLayer.addMarker( getOLMarker( markerLayer, params.markers[i], map.getProjectionObject() ) ); // Create and add the marker.
 126+ }
 127+
 128+ if ( bounds != null ) map.zoomToExtent( bounds ); // If a bounds object has been created, use it to set the zoom and center.
 129+ }
 130+
 131+ /**
 132+ * Gets a valid control name (with excat lower and upper case letters),
 133+ * or returns false when the control is not allowed.
 134+ */
 135+ function getValidControlName( control ) {
 136+ var OLControls = [
 137+ 'ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan',
 138+ 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher',
 139+ 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar',
 140+ 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan',
 141+ 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink',
 142+ 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split',
 143+ 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel',
 144+ 'ZoomToMaxExtent'
 145+ ];
 146+
 147+ for ( var i = OLControls.length - 1; i >= 0; i-- ) {
 148+ if ( control == OLControls[i].toLowerCase() ) {
 149+ return OLControls[i];
 150+ }
 151+ }
 152+
 153+ return false;
 154+ }
 155+
 156+ function getOLMarker(markerLayer, markerData, projectionObject) {
 157+ var marker;
 158+
 159+ if (markerData.icon != "") {
 160+ //var iconSize = new OpenLayers.Size(10,17);
 161+ //var iconOffset = new OpenLayers.Pixel(-(iconSize.w/2), -iconSize.h);
 162+ marker = new OpenLayers.Marker(markerData.lonlat, new OpenLayers.Icon(markerData.icon)); // , iconSize, iconOffset
 163+ } else {
 164+ marker = new OpenLayers.Marker(markerData.lonlat);
 165+ }
 166+
 167+ if ( markerData.title.length + markerData.label.length > 0 ) {
 168+
 169+ // This is the handler for the mousedown event on the marker, and displays the popup.
 170+ marker.events.register('mousedown', marker,
 171+ function(evt) {
 172+ var popup = new OpenLayers.Feature(markerLayer, markerData.lonlat).createPopup(true);
 173+
 174+ if (markerData.title.length > 0 && markerData.label.length > 0) { // Add the title and label to the popup text.
 175+ popup.setContentHTML('<b>' + markerData.title + '</b><hr />' + markerData.label);
 176+ }
 177+ else {
 178+ popup.setContentHTML(markerData.title + markerData.label);
 179+ }
 180+
 181+ popup.setOpacity(0.85);
 182+ markerLayer.map.addPopup(popup);
 183+ OpenLayers.Event.stop(evt); // Stop the event.
 184+ }
 185+ );
 186+
 187+ }
 188+
 189+ return marker;
 190+ }
 191+
 192+ function initOLSettings(minWidth, minHeight) {
 193+ OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
 194+ OpenLayers.Util.onImageLoadErrorColor = 'transparent';
 195+ OpenLayers.Feature.prototype.popupClass = OpenLayers.Class(
 196+ OpenLayers.Popup.FramedCloud,
 197+ {
 198+ 'autoSize': true,
 199+ 'minSize': new OpenLayers.Size(minWidth, minHeight)
 200+ }
 201+ );
 202+ }
 203+
 204+} );
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/services/OpenLayers/ext.maps.openlayers.js
___________________________________________________________________
Added: svn:eol-style
1205 + native
Index: trunk/extensions/Maps/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_map parser functions with Google Maps.
 5+ * Class for handling the display_map parser hook with Google Maps.
66 *
77 * @file Maps_GoogleMapsDispMap.php
88 * @ingroup MapsGoogleMaps
@@ -10,13 +10,10 @@
1111 */
1212 final class MapsGoogleMapsDispMap extends MapsBaseMap {
1313
14 - protected function initSpecificParamInfo( array &$parameters ) {
15 - }
16 -
1714 /**
18 - * @see MapsBaseMap::addSpecificMapHTML()
 15+ * @see MapsBaseMap::getMapHTML()
1916 */
20 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function getMapHTML( array $params, Parser $parser ) {
2118 $mapName = $this->service->getMapId();
2219
2320 $this->service->addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls );
Index: trunk/extensions/Maps/includes/services/OSM/Maps_OSMDispMap.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_map parser function with OSM.
 5+ * Class for handling the display_map parser hook with OSM.
66 *
77 * @since 0.6.4
88 *
@@ -13,11 +13,9 @@
1414 class MapsOSMDispMap extends MapsBaseMap {
1515
1616 /**
17 - * @see MapsBaseMap::addSpecificMapHTML()
18 - *
19 - * @since 0.6.4
 17+ * @see MapsBaseMap::getMapHTML()
2018 */
21 - public function addSpecificMapHTML( Parser $parser ) {
 19+ public function getMapHTML( array $params, Parser $parser ) {
2220 global $wgLang;
2321
2422 $thumbs = $this->thumbs ? 'yes' : 'no';
Index: trunk/extensions/Maps/includes/parserHooks/Maps_DisplayMap.php
@@ -102,7 +102,7 @@
103103 // Get an instance of the class handling the current parser hook and service.
104104 $mapClass = $service->getFeatureInstance( $this->getName() );
105105
106 - return $mapClass->getMapHtml( $parameters, $this->parser );
 106+ return $mapClass->renderMap( $parameters, $this->parser );
107107 }
108108
109109 /**
Index: trunk/extensions/Maps/includes/Maps_MappingServices.php
@@ -204,7 +204,7 @@
205205 *
206206 * @since 0.6.6
207207 *
208 - * @return array
 208+ * @return array of string
209209 */
210210 public static function getAllServiceValues() {
211211 global $egMapsAvailableServices;
@@ -217,6 +217,23 @@
218218 }
219219
220220 return $allServiceValues;
221 - }
 221+ }
222222
 223+ /**
 224+ * Returns an array with an instance of a MappingService object for every available mapping service.
 225+ *
 226+ * @since 0.7.3
 227+ *
 228+ * @return array of MappingService
 229+ */
 230+ public static function getAllObjects() {
 231+ $objects = array();
 232+
 233+ foreach ( self::$registeredServices as $service => $class ) {
 234+ $objects[] = self::getServiceInstance( $service );
 235+ }
 236+
 237+ return $objects;
 238+ }
 239+
223240 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/features/Maps_BaseMap.php
@@ -13,87 +13,72 @@
1414 abstract class MapsBaseMap {
1515
1616 /**
 17+ * @since 0.6.x
 18+ *
1719 * @var iMappingService
1820 */
1921 protected $service;
20 -
21 - protected $centreLat, $centreLon;
2222
23 - protected $output = '';
24 -
25 - private $specificParameters = false;
2623 /**
27 - * Constructor.
 24+ * @since 0.7.3
2825 *
29 - * @param MapsMappingService $service
 26+ * @var array
3027 */
31 - public function __construct( iMappingService $service ) {
32 - $this->service = $service;
33 - }
 28+ protected $properties = array();
3429
3530 /**
36 - * Sets the map properties as class fields.
 31+ * Returns the HTML to display the map.
3732 *
38 - * @param array $mapProperties
 33+ * @since 0.7.3
 34+ *
 35+ * @param array $params
 36+ * @param $parser
 37+ *
 38+ * @return string
3939 */
40 - protected function setMapProperties( array $mapProperties ) {
41 - foreach ( $mapProperties as $paramName => $paramValue ) {
42 - if ( !property_exists( __CLASS__, $paramName ) ) {
43 - $this-> { $paramName } = $paramValue;
44 - }
45 - else {
46 - // If this happens in any way, it could be a big vunerability, so throw an exception.
47 - throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
48 - }
49 - }
50 - }
 40+ protected abstract function getMapHTML( array $params, Parser $parser );
5141
5242 /**
53 - * Returns the specific parameters by first checking if they have been initialized yet,
54 - * doing to work if this is not the case, and then returning them.
 43+ * Constructor.
5544 *
56 - * @return array
 45+ * @param MapsMappingService $service
5746 */
58 - public final function getSpecificParameterInfo() {
59 - if ( $this->specificParameters === false ) {
60 - $this->specificParameters = array();
61 - $this->initSpecificParamInfo( $this->specificParameters );
62 - }
63 -
64 - return $this->specificParameters;
 47+ public function __construct( iMappingService $service ) {
 48+ $this->service = $service;
6549 }
6650
6751 /**
68 - * Initializes the specific parameters.
 52+ * @see
6953 *
70 - * Override this method to set parameters specific to a feature service comibination in
71 - * the inheriting class.
72 - *
73 - * @param array $parameters
74 - */
75 - protected function initSpecificParamInfo( array &$parameters ) {
 54+ * @since 0.7.3
 55+ */
 56+ public function addParameterInfo( array &$params ) {
7657 }
7758
7859 /**
7960 * Handles the request from the parser hook by doing the work that's common for all
8061 * mapping services, calling the specific methods and finally returning the resulting output.
8162 *
 63+ * @since 0.7.3
 64+ *
8265 * @param array $params
8366 * @param Parser $parser
8467 *
8568 * @return html
8669 */
87 - public final function getMapHtml( array $params, Parser $parser ) {
88 - $this->setMapProperties( $params );
 70+ public final function renderMap( array $params, Parser $parser ) {
 71+ $this->setCentre( $params );
8972
90 - $this->setCentre();
 73+ if ( $params['zoom'] == 'null' ) {
 74+ $params['zoom'] = $this->service->getDefaultZoom();
 75+ }
9176
92 - if ( $this->zoom == 'null' ) {
93 - $this->zoom = $this->service->getDefaultZoom();
 77+ $output = $this->getMapHTML( $params, $parser );
 78+
 79+ if ( method_exists( 'OutputPage', 'addModules' ) ) {
 80+ $output .= $this->getJSON( $params, $parser );
9481 }
9582
96 - $this->addSpecificMapHTML( $parser );
97 -
9883 global $wgTitle;
9984 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
10085 global $wgOut;
@@ -103,48 +88,66 @@
10489 $this->service->addDependencies( $parser );
10590 }
10691
107 - return $this->output;
 92+ return $output;
10893 }
10994
11095 /**
111 - * Sets the $centreLat and $centreLon fields.
112 - */
113 - protected function setCentre() {
114 - if ( empty( $this->coordinates ) ) { // If centre is not set, use the default latitude and longitutde.
115 - $this->setCentreToDefault();
 96+ * Returns the JSON with the maps data.
 97+ *
 98+ * @since 0.7.3
 99+ *
 100+ * @param array $params
 101+ * @param Parser $parser
 102+ *
 103+ * @return string
 104+ */
 105+ protected function getJSON( array $params, Parser $parser ) {
 106+ $object = $this->getJSONObject( $params, $parser );
 107+
 108+ if ( $object === false ) {
 109+ return '';
116110 }
117 - else { // If a centre value is set, geocode when needed and use it.
118 - $this->coordinates = MapsGeocoders::attemptToGeocode( $this->coordinates, $this->geoservice, $this->service->getName() );
119 -
120 - // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
121 - if ( $this->coordinates ) {
122 - $this->centreLat = Xml::escapeJsString( $this->coordinates['lat'] );
123 - $this->centreLon = Xml::escapeJsString( $this->coordinates['lon'] );
124 - }
125 - else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
126 - $this->setCentreToDefault();
127 - }
128 - }
 111+
 112+ // TODO
 113+ return Html::inlineScript( "maps=[]; maps['{$this->service->getName()}']=[]; maps['{$this->service->getName()}'].push(" . json_encode( $object ) . ')' );
129114 }
130115
131116 /**
132 - * Attempts to set the centreLat and centreLon fields to the Maps default.
133 - * When this fails (aka the default is not valid), an exception is thrown.
 117+ * Returns a PHP object to encode to JSON with the map data.
 118+ *
 119+ * @since 0.7.3
 120+ *
 121+ * @param array $params
 122+ * @param Parser $parser
134123 *
135 - * @since 0.7
 124+ * @return mixed
 125+ */
 126+ protected function getJSONObject( array $params, Parser $parser ) {
 127+ return $params;
 128+ }
 129+
 130+ /**
 131+ * Translates the coordinates field to the centre field and makes sure it's set to it's default when invalid.
136132 */
137 - protected function setCentreToDefault() {
138 - global $egMapsDefaultMapCentre;
 133+ protected function setCentre( array &$params ) {
 134+ // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
 135+ if ( $params['coordinates'] === false ) {
 136+ global $egMapsDefaultMapCentre;
139137
140 - $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $this->geoservice, $this->service->getName() );
141 -
142 - if ( $centre === false ) {
143 - throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' );
 138+ $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $params['geoservice'], $this->service->getName() );
 139+
 140+ if ( $centre === false ) {
 141+ throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' );
 142+ }
 143+ else {
 144+ $params['centre'] = $centre;
 145+ }
144146 }
145147 else {
146 - $this->centreLat = Xml::escapeJsString( $centre['lat'] );
147 - $this->centreLon = Xml::escapeJsString( $centre['lon'] );
 148+ $params['centre'] = MapsCoordinateParser::parseCoordinates( $params['coordinates'] );
148149 }
149 - }
 150+
 151+ unset( $params['coordinates'] );
 152+ }
150153
151154 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.hooks.php
@@ -69,15 +69,24 @@
7070 * @return true
7171 */
7272 public static function registerResourceLoaderModules( ResourceLoader &$resourceLoader ) {
73 - global $wgExtensionAssetsPath;
 73+ global $egMapsScriptPath;
7474
75 - $modules = array(
 75+ $modules = array(
 76+ 'ext.maps.common' => array(
 77+
 78+ ),
7679 );
7780
 81+ // TODO: makes more sense to have a seperate hook for each service
 82+ foreach ( MapsMappingServices::getAllObjects() as $service ) {
 83+ $modules = array_merge( $modules, $service->getResourceModuleDefinitions() );
 84+ }
 85+
7886 foreach ( $modules as $name => $resources ) {
7987 $resourceLoader->register( $name, new ResourceLoaderFileModule(
8088 array_merge_recursive( $resources, array( 'group' => 'ext.maps' ) ),
81 - dirname( __FILE__ ), "$wgExtensionAssetsPath/Maps"
 89+ dirname( __FILE__ ) . '/includes/services/OpenLayers/',
 90+ $egMapsScriptPath . '/includes/services/OpenLayers/'
8291 ) );
8392 }
8493

Follow-up revisions

RevisionCommit summaryAuthorDate
r76255Follow up to r76228 - partial fix - still expecting problems for OpenLayers w...jeroendedauw17:43, 7 November 2010
r76256Follow up to r76228 and r76255 - partial fix - fixed OpenLayers for display p...jeroendedauw18:27, 7 November 2010
r76257Follow up to r76228 and r76255 - partial fix - fixed Yahoo! Maps for display mapjeroendedauw18:36, 7 November 2010
r76259Follow up to r76228 and r76255 - Fixed OSM and Google Maps v3 servicesjeroendedauw18:45, 7 November 2010

Comments

#Comment by Jeroen De Dauw (talk | contribs)   01:04, 7 November 2010

Accidentally committed experimental code that breaks stuff, will make follow up commit to fix this soonish.

#Comment by Jeroen De Dauw (talk | contribs)   18:46, 7 November 2010

Should be fixed now.

Status & tagging log