r54415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54414‎ | r54415 | r54416 >
Date:01:01, 5 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Refactoring for 0.3
Note: this revision is highly unstable and will not work with the last one of SM.
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Geocoder.php (modified) (history)
  • /trunk/extensions/Maps/Maps_MapFeature.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Utils.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php
@@ -100,7 +100,7 @@
101101 */
102102 public static function createControlsString($controls) {
103103 global $egMapsOLControls;
104 - return MapsMapper::createControlsString($controls, $egMapsOLControls);
 104+ return MapsMapper::createJSItemsString($controls, $egMapsOLControls);
105105 }
106106
107107 /**
@@ -112,6 +112,14 @@
113113
114114 $this->elementNamePrefix = $egMapsOpenLayersPrefix;
115115 $this->defaultZoom = $egMapsOpenLayersZoom;
 116+
 117+ $this->serviceName = 'openlayers';
 118+
 119+ $this->defaultParams = array
 120+ (
 121+ 'layers' => array(),
 122+ 'baselayer' => ''
 123+ );
116124 }
117125
118126 /**
@@ -135,15 +143,27 @@
136144 global $wgJsMimeType;
137145
138146 $controlItems = self::createControlsString($this->controls);
 147+
 148+ MapsMapper::enforceArrayValues($this->layers);
139149 $layerItems = self::createLayersStringAndLoadDependencies($this->output, $this->layers);
140150
141151 MapsUtils::makePxValue($this->width);
142152 MapsUtils::makePxValue($this->height);
143153
 154+ $markerItems = array();
 155+
 156+ foreach ($this->markerData as $markerData) {
 157+ $lat = $markerData['lat'];
 158+ $lon = $markerData['lon'];
 159+ $markerItems[] = "getOLMarkerData($lon, $lat, '$this->title', '$this->label')";
 160+ }
 161+
 162+ $markersString = implode(',', $markerItems);
 163+
144164 $this->output .= "<div id='$this->mapName' style='width: $this->width; height: $this->height; background-color: #cccccc;'></div>
145165 <script type='$wgJsMimeType'> /*<![CDATA[*/
146166 addLoadEvent(
147 - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[getOLMarkerData($this->marker_lon, $this->marker_lat, '$this->title', '$this->label')])
 167+ initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString])
148168 );
149169 /*]]>*/ </script>";
150170 }
Index: trunk/extensions/Maps/Maps.php
@@ -46,15 +46,31 @@
4747
4848 $egMapsServices['googlemaps'] = array(
4949 'pf' => array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true),
50 - 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps')
 50+ 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
 51+ 'parameters' => array(
 52+ 'type' => array('map-type', 'map type'),
 53+ 'earth' => array(),
 54+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
 55+ 'class' => array()
 56+ )
5157 );
 58+
5259 $egMapsServices['openlayers'] = array(
5360 'pf' => array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true),
54 - 'aliases' => array('layers', 'openlayer')
 61+ 'aliases' => array('layers', 'openlayer'),
 62+ 'parameters' => array(
 63+ 'layers' => array(),
 64+ 'baselayer' => array()
 65+ )
5566 );
 67+
5668 $egMapsServices['yahoomaps'] = array(
5769 'pf' => array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMaps.php', 'local' => true),
58 - 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps')
 70+ 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
 71+ 'parameters' => array(
 72+ 'type' => array('map-type'),
 73+ 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
 74+ )
5975 );
6076
6177 /**
@@ -100,11 +116,13 @@
101117 function efMapsAddParserHooks() {
102118 global $wgParser;
103119
104 - // A hook to enable the '#display_point' parser function
 120+ // A hooks to enable the '#display_point' and '#display_points' parser functions
105121 $wgParser->setFunctionHook( 'display_point', array('MapsMapper', 'displayPointRender' ));
 122+ $wgParser->setFunctionHook( 'display_points', array('MapsMapper', 'displayPointsRender' ));
106123
107 - // A hook to enable the '#display_adress' parser function
 124+ // A hooks to enable the '#display_adress' and '#display_adresses' parser functions
108125 $wgParser->setFunctionHook( 'display_address', array('MapsMapper', 'displayAddressRender' ));
 126+ $wgParser->setFunctionHook( 'display_addresses', array('MapsMapper', 'displayAddressesRender' ));
109127
110128 // A hook to enable the geocoder parser functions
111129 $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder' ));
@@ -113,21 +131,13 @@
114132 }
115133
116134 /**
117 - * This function ensures backward compatibility with Semantic Google Maps and other extensions
118 - * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
119 - */
120 -function efMapsValidateGoogleMapsKey() {
121 - global $egGoogleMapsKey, $wgGoogleMapsKey;
122 -
123 - if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey;
124 -}
125 -
126 -/**
127135 * Adds the magic words for the parser functions
128136 */
129137 function efMapsFunctionMagic( &$magicWords, $langCode ) {
130138 $magicWords['display_point'] = array( 0, 'display_point' );
 139+ $magicWords['display_points'] = array( 0, 'display_points' );
131140 $magicWords['display_address'] = array( 0, 'display_address' );
 141+ $magicWords['display_addresses'] = array( 0, 'display_addresses' );
132142
133143 $magicWords['geocode'] = array( 0, 'geocode' );
134144 $magicWords['geocodelat'] = array ( 0, 'geocodelat' );
@@ -137,6 +147,16 @@
138148 }
139149
140150 /**
 151+ * This function ensures backward compatibility with Semantic Google Maps and other extensions
 152+ * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
 153+ */
 154+function efMapsValidateGoogleMapsKey() {
 155+ global $egGoogleMapsKey, $wgGoogleMapsKey;
 156+
 157+ if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey;
 158+}
 159+
 160+/**
141161 * Adds a link to Admin Links page
142162 */
143163 function efMapsAddToAdminLinks(&$admin_links_tree) {
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -14,61 +14,123 @@
1515 }
1616
1717 final class MapsMapper {
18 -
 18+
1919 /**
 20+ * Array holding the allowed main parameters and their alias.
 21+ * The array keys hold the main name, and the values are arrays holding the aliases.
 22+ *
 23+ * @var array
 24+ */
 25+ private static $mainParams = array
 26+ (
 27+ 'service' => array(),
 28+ 'coordinates' => array('coords', 'location'),
 29+ 'zoom' => array(),
 30+ 'centre' => array('center'),
 31+ 'width' => array(),
 32+ 'height' => array(),
 33+ 'controls' => array(),
 34+ 'label' => array(),
 35+ 'title' => array()
 36+ );
 37+
 38+ /**
2039 * Sets the default map properties and returns the new array.
 40+ * This function also ensures all the properties are present, even when being empty,
 41+ * which is important for the weakly typed classes using them.
2142 *
2243 * @param array $params Array containing the current set of pareters.
 44+ * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service.
2345 * @param boolean $strict If set to false, values which a key that does not
2446 * exist in the $map array will be retained.
2547 * @return unknown
2648 */
27 - public static function setDefaultParValues(array $params, $strict) {
28 - global $egMapsMapCoordinates, $egMapsMapWidth, $egMapsMapHeight, $egMapsEnableAutozoom, $egMapsEnableEarth;
 49+ public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) {
 50+ global $egMapsMapLat, $egMapsMapLon, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultZoom, $egMapsDefaultService;
2951
30 - $map = array(
31 - 'service' => '',
32 - 'coordinates' => $egMapsMapCoordinates,
33 - 'zoom' => '',
34 - 'centre' => '',
35 - 'type' => '',
36 - 'width' => "$egMapsMapWidth",
37 - 'height' => "$egMapsMapHeight",
38 - 'controls' => array(),
39 - 'autozoom' => $egMapsEnableAutozoom ? 'on' : 'off',
40 - 'earth' => $egMapsEnableEarth ? 'on' : 'off',
41 - 'class' => 'pmap',
42 - 'layers' => array(),
43 - 'baselayer' => '',
44 - 'title' => '',
45 - 'label' => '',
46 - 'style' => ''
47 - );
 52+ $mapDefaults = array(
 53+ 'service' => $egMapsDefaultService,
 54+ 'coordinates' => "$egMapsMapLat, $egMapsMapLon",
 55+ 'zoom' => $egMapsDefaultZoom,
 56+ 'centre' => '',
 57+ 'width' => $egMapsMapWidth,
 58+ 'height' => $egMapsMapHeight,
 59+ 'controls' => array(),
 60+ 'title' => '',
 61+ 'label' => ''
 62+ );
 63+
 64+ $map = array_merge($mapDefaults, $serviceDefaults);
4865
4966 foreach($params as $paramName => $paramValue) {
5067 if(array_key_exists($paramName, $map) || !$strict) $map[$paramName] = $paramValue;
5168 }
5269
53 - // Alias for centre
54 - if(array_key_exists('center', $params)) $map['centre'] = $params['center'];
 70+ return $map;
 71+ }
 72+
 73+ /**
 74+ * Returns a valid version of the provided parameter array. Paramaters that are not allowed will
 75+ * be ignored, and alias parameter names will be changed to main parameter names, using getMainParamName().
 76+ *
 77+ * @param unknown_type $params
 78+ * @param unknown_type $serviceParameters
 79+ * @return unknown
 80+ */
 81+ public static function getValidParams($params, $serviceParameters) {
 82+ $validParams = array();
5583
56 - self::enforceArrayValues($map['controls']);
57 - self::enforceArrayValues($map['layers']);
 84+ $allowedParms = array_merge(self::$mainParams, $serviceParameters);
5885
59 - return $map;
 86+ foreach($params as $paramName => $paramValue) {
 87+ $paramName = self::getMainParamName($paramName, $allowedParms);
 88+ if(array_key_exists($paramName, $allowedParms)) $validParams[$paramName] = $paramValue;
 89+ }
 90+
 91+ return $validParams;
6092 }
6193
 94+ /**
 95+ * Checks if the patameter name is an alias for an actual parameter,
 96+ * and changes it into the main paremeter name if this is the case.
 97+ *
 98+ * @param string $paramName
 99+ * @param array $allowedParms
 100+ * @return string
 101+ */
 102+ private static function getMainParamName($paramName, array $allowedParms) {
 103+ if (!array_key_exists($paramName, $allowedParms)) {
 104+ foreach ($allowedParms as $name => $aliases) {
 105+ if (in_array($paramName, $aliases)) $paramName = $name;
 106+ }
 107+ }
 108+
 109+ return $paramName;
 110+ }
 111+
 112+ /**
 113+ * Turns the provided values into an array by splitting it on comma's if
 114+ * it's not an array yet.
 115+ *
 116+ * @param unknown_type $values
 117+ * @param unknown_type $delimeter
 118+ */
62119 public static function enforceArrayValues(&$values, $delimeter = ',') {
63120 if (!is_array($values)) $values = split($delimeter, $values); // If not an array yet, split the values
64121 for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values
65122 }
66123
67 - public static function createControlsString(array $controls, array $defaultControls) {
68 - if (count($controls) < 1) $controls = $defaultControls;
69 - $controlItems = '';
70 - foreach ($controls as $control) $controlItems .= "'$control'" . ',';
71 -
72 - return strtolower(rtrim($controlItems, ','));
 124+ /**
 125+ * Checks if the items array has members, and sets it to the default when this is not the case.
 126+ * Then returns an imploded/joined, comma seperated, version of the array as string.
 127+ *
 128+ * @param array $items
 129+ * @param array $defaultItems
 130+ * @return unknown
 131+ */
 132+ public static function createJSItemsString(array $items, array $defaultItems) {
 133+ if (count($items) < 1) $items = $defaultItems;
 134+ return "'" . strtolower(implode("','", $items)) . "'";
73135 }
74136
75137 /**
@@ -79,6 +141,8 @@
80142 * @return unknown
81143 */
82144 public static function displayPointRender(&$parser) {
 145+ global $egMapsServices;
 146+
83147 $params = func_get_args();
84148 array_shift( $params ); // We already know the $parser ...
85149
@@ -98,24 +162,13 @@
99163 }
100164 }
101165
102 - $map = self::setDefaultParValues($map, true);
103 -
 166+ $map['coordinates'] = explode(';', $map['coordinates']);
 167+
104168 $map['service'] = self::getValidService($map['service']);
105 -
106169
107 - switch($map['service']) {
108 - case 'openlayers' :
109 - $mapClass = new MapsOpenLayers();
110 - break;
111 - case 'yahoomaps' :
112 - $mapClass = new MapsYahooMaps();
113 - break;
114 - default:
115 - $mapClass = new MapsGoogleMaps();
116 - break;
117 - }
 170+ $map = self::setDefaultParValues($map, $egMapsServices[$map['service']]['parameters'], true);
118171
119 - $mapClass = new $egMapsServices[$map['service']]['qp']['class']();
 172+ $mapClass = new $egMapsServices[$map['service']]['pf']['class']();
120173
121174 // Call the function according to the map service to get the HTML output
122175 $output = $mapClass->displayMap($parser, $map);
@@ -125,6 +178,16 @@
126179 }
127180
128181 /**
 182+ * Sets the default map properties, gets the map HTML depending
 183+ * on the provided service, and then returns it.
 184+ *
 185+ * @param unknown_type $parser
 186+ */
 187+ public static function displayPointsRender(&$parser) {
 188+ return self::displayPointRender(func_get_args());
 189+ }
 190+
 191+ /**
129192 * Turns the address parameter into coordinates, then lets
130193 * @see MapsMapper::displayPointRender() do the work and returns it.
131194 *
@@ -132,42 +195,64 @@
133196 * @return unknown
134197 */
135198 public static function displayAddressRender(&$parser) {
136 - // TODO: refactor to reduce redundancy and improve performance
137199 global $egMapsDefaultService;
138200
139201 $params = func_get_args();
140202 array_shift( $params ); // We already know the $parser ...
141203
 204+ self::changeAddressToCoords($params);
 205+
 206+ return self::displayPointRender($parser, $params);
 207+ }
 208+
 209+ /**
 210+ * Turns the address parameter into coordinates, then lets
 211+ * @see MapsMapper::displayPointRender() do the work and returns it.
 212+ *
 213+ * @param unknown_type $parser
 214+ */
 215+ public static function displayAddressesRender(&$parser) {
 216+ return self::displayAddressRender(func_get_args());
 217+ }
 218+
 219+ /**
 220+ * Changes the values of the address or addresses parameter into coordinates
 221+ * in the provided array.
 222+ *
 223+ * @param array $params
 224+ */
 225+ private static function changeAddressToCoords(&$params) {
 226+ global $egMapsDefaultService;
 227+
142228 for ($i = 0; $i < count($params); $i++) {
143229 $split = split('=', $params[$i]);
144230 if (strtolower(trim($split[0])) == 'service' && count($split) > 1) {
145231 $service = trim($split[1]);
146232 }
 233+ else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
 234+ $geoservice = trim($split[1]);
 235+ }
147236 }
148237
149 -
150238 $service = isset($service) ? MapsMapper::getValidService($service) : $egMapsDefaultService;
 239+ $geoservice = isset($geoservice) ? $geoservice : '';
151240
152 - $geoservice = '';
153 -
154241 for ($i = 0; $i < count($params); $i++) {
155242 $split = split('=', $params[$i]);
156 - if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
157 - $geoservice = trim($split[1]);
 243+ if (((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1) || count($split) == 1) {
 244+ $address_srting = count($split) == 1 ? $split[0] : $split[1];
 245+
 246+ $addresses = explode(';', $address_srting);
 247+
 248+ $coordinates = array();
 249+
 250+ foreach($addresses as $address) {
 251+ $coordinates[] = MapsGeocoder::renderGeocoder(null, trim($address), $geoservice, $service);
 252+ }
 253+
 254+ $params[$i] = 'coordinates=' . implode(';', $coordinates);
158255 }
159 - }
160 -
161 - for ($i = 0; $i < count($params); $i++) {
162 - $split = split('=', $params[$i]);
163 - if (strtolower(trim($split[0])) == 'address' && count($split) > 1) {
164 - $params[$i] = 'coordinates=' . MapsGeocoder::renderGeocoder($parser, trim($split[1]), $geoservice, $service);
165 - }
166 - if (count($split) == 1) { // Default parameter (without name)
167 - $params[$i] = 'coordinates=' . MapsGeocoder::renderGeocoder($parser, trim($split[0]), $geoservice, $service);
168 - }
169 - }
170 -
171 - return self::displayPointRender($parser, $params);
 256+ }
172257 }
173258
174259 /**
@@ -187,7 +272,7 @@
188273 }
189274
190275 /**
191 - * Checks if the service name is an allias for an actual service,
 276+ * Checks if the service name is an alias for an actual service,
192277 * and changes it into the main service name if this is the case.
193278 *
194279 * @param unknown_type $service
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -16,11 +16,11 @@
1717
1818 // http://code.google.com/apis/maps/documentation/introduction.html#MapTypes
1919 private static $mapTypes = array(
20 - 'earth' => 'G_SATELLITE_3D_MAP',
2120 'normal' => 'G_NORMAL_MAP',
2221 'satellite' => 'G_SATELLITE_MAP',
2322 'hybrid' => 'G_HYBRID_MAP',
2423 'physical' => 'G_PHYSICAL_MAP',
 24+ 'earth' => 'G_SATELLITE_3D_MAP',
2525 );
2626
2727 // http://code.google.com/apis/maps/documentation/controls.html#Controls_overview
@@ -35,10 +35,13 @@
3636 * possible Google Map type will be returned as default.
3737 */
3838 public static function getGMapType($type, $earthEnabled = false) {
39 - $keyz = array_keys(MapsGoogleMaps::$mapTypes);
40 - $defaultKey = $earthEnabled ? 0 : 1;
41 - $keyName = array_key_exists($type, MapsGoogleMaps::$mapTypes) ? $type : $keyz[ "$defaultKey" ];
42 - return self::$mapTypes[ $keyName ];
 39+ global $egMapsGoogleMapsType;
 40+
 41+ if (! array_key_exists($type, MapsGoogleMaps::$mapTypes)) {
 42+ $type = $earthEnabled ? "earth" : $egMapsGoogleMapsType;;
 43+ }
 44+
 45+ return self::$mapTypes[ $type ];
4346 }
4447
4548 /**
@@ -100,6 +103,16 @@
101104
102105 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
103106 $this->defaultZoom = $egMapsGoogleMapsZoom;
 107+
 108+ $this->serviceName = 'googlemaps';
 109+
 110+ $this->defaultParams = array
 111+ (
 112+ 'type' => '',
 113+ 'class' => 'pmap',
 114+ 'autozoom' => '',
 115+ 'earth' => ''
 116+ );
104117 }
105118
106119 /**
@@ -127,13 +140,25 @@
128141
129142 $this->type = self::getGMapType($this->type, $enableEarth);
130143 $control = self::getGControlType($this->controls);
131 -
 144+
 145+ $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true';
 146+
 147+ $markerItems = array();
 148+
 149+ foreach ($this->markerData as $markerData) {
 150+ $lat = $markerData['lat'];
 151+ $lon = $markerData['lon'];
 152+ $markerItems[] = "getGMarkerData($lat, $lon, '$this->title', '$this->label')";
 153+ }
 154+
 155+ $markersString = implode(',', $markerItems);
 156+
132157 $this->output .=<<<END
133158
134159 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
135160 <script type="$wgJsMimeType"> /*<![CDATA[*/
136161 addLoadEvent(
137 - initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, new $control(), $this->autozoom, $this->earth, [getGMarkerData($this->marker_lat, $this->marker_lon, '$this->title', '$this->label', '')])
 162+ initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, new $control(), $this->autozoom, $this->earth, [$markersString])
138163 );
139164 /*]]>*/ </script>
140165
Index: trunk/extensions/Maps/Maps_Geocoder.php
@@ -24,7 +24,7 @@
2525 private static $mEnableCache = true;
2626 private static $mGeocoderCache = array();
2727
28 - public static function renderGeocoder(&$parser, $address, $service = '', $mappingService = '') {
 28+ public static function renderGeocoder($parser, $address, $service = '', $mappingService = '') {
2929 $geovalues = MapsGeocoder::geocode($address, $service, $mappingService);
3030 return $geovalues ? $geovalues['lat'].', '.$geovalues['lon'] : '';
3131 }
Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -33,7 +33,12 @@
3434 */
3535 protected abstract function addSpecificMapHTML();
3636
 37+ protected $defaultParams = array();
 38+
 39+ protected $serviceName;
 40+
3741 protected $defaultZoom;
 42+
3843 protected $elementNr;
3944 protected $elementNamePrefix;
4045
@@ -50,15 +55,20 @@
5156 * @param unknown_type $map
5257 */
5358 protected function manageMapProperties($mapProperties, $className) {
54 - $mapProperties = MapsMapper::setDefaultParValues($mapProperties, true);
 59+ global $egMapsServices;
5560
 61+ $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
 62+ $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
 63+
5664 // Go through the array with map parameters and create new variables
5765 // with the name of the key and value of the item if they don't exist on class level yet.
5866 foreach($mapProperties as $paramName => $paramValue) {
5967 if (!property_exists($className, $paramName)) {
6068 $this->{$paramName} = $paramValue;
6169 }
62 - }
 70+ }
 71+
 72+ MapsMapper::enforceArrayValues($this->controls);
6373 }
6474
6575 /**
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -27,9 +27,8 @@
2828 * Google Map type will be returned as default.
2929 */
3030 public static function getYMapType($type) {
31 - $keyz = array_keys(MapsYahooMaps::$mapTypes);
32 - $keyName = array_key_exists($type, MapsYahooMaps::$mapTypes) ? $type : $keyz[0];
33 - return MapsYahooMaps::$mapTypes[ $keyName ];
 31+ if (! array_key_exists($type, MapsYahooMaps::$mapTypes)) $type = $egMapsYahooMapsType;
 32+ return MapsYahooMaps::$mapTypes[ $type ];
3433 }
3534
3635 /**
@@ -40,7 +39,7 @@
4140 */
4241 public static function createControlsString($controls) {
4342 global $egMapsYMapControls;
44 - return MapsMapper::createControlsString($controls, $egMapsYMapControls);
 43+ return MapsMapper::createJSItemsString($controls, $egMapsYMapControls);
4544 }
4645
4746 /**
@@ -68,6 +67,14 @@
6968
7069 $this->elementNamePrefix = $egMapsYahooMapsPrefix;
7170 $this->defaultZoom = $egMapsYahooMapsZoom;
 71+
 72+ $this->serviceName = 'yahoomaps';
 73+
 74+ $this->defaultParams = array
 75+ (
 76+ 'type' => '',
 77+ 'autozoom' => '',
 78+ );
7279 }
7380
7481 /**
@@ -96,12 +103,24 @@
97104 MapsUtils::makePxValue($this->width);
98105 MapsUtils::makePxValue($this->height);
99106
 107+ $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true';
 108+
 109+ $markerItems = array();
 110+
 111+ foreach ($this->markerData as $markerData) {
 112+ $lat = $markerData['lat'];
 113+ $lon = $markerData['lon'];
 114+ $markerItems[] = "getYMarkerData($lat, $lon, '$this->title', '$this->label', '')";
 115+ }
 116+
 117+ $markersString = implode(',', $markerItems);
 118+
100119 $this->output .= <<<END
101120 <div id="$this->mapName" style="width: $this->width; height: $this->height;"></div>
102121
103122 <script type="$wgJsMimeType">/*<![CDATA[*/
104123 addLoadEvent(
105 - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->controls], $this->autozoom, [getYMarkerData($this->marker_lat, $this->marker_lon, '$this->title', '$this->label', '')])
 124+ initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->controls], $this->autozoom, [$markersString])
106125 );
107126 /*]]>*/</script>
108127 END;
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -30,6 +30,8 @@
3131
3232
3333
 34+
 35+
3436 # Map services configuration
3537
3638 # Array of String. Array containing all the mapping services that will be made available to the user.
@@ -42,6 +44,8 @@
4345
4446
4547
 48+
 49+
4650 # Geocoding services configuration
4751
4852 # Array of String. Array containing all the geocoding services that will be made available to the user.
@@ -54,6 +58,8 @@
5559
5660
5761
 62+
 63+
5864 # General map properties configuration
5965
6066 # Integer. The default width and height of a map. These values will only be used when the user does not provide them.
@@ -61,20 +67,29 @@
6268 $egMapsMapHeight = 350;
6369
6470 # String. The default coordinates of the marker. This value will only be used when the user does not provide one.
65 -$egMapsMapCoordinates = '1,1';
 71+$egMapsMapLat = '1';
 72+$egMapsMapLon = '1';
6673
 74+# Integer. The default zoom of a map. This value will only be used when the user does not provide one.
 75+$egMapsDefaultZoom = 10; # Will be used when the default for a service is not provided
6776
6877
 78+
 79+
 80+
6981 # Specific map properties configuration
7082
 83+# Google maps
 84+
 85+# String. The Google Maps map name prefix. It can not be identical to the one of another mapping service.
 86+$egMapsGoogleMapsPrefix = 'map_google';
 87+
7188 # Integer. The default zoom of a map. This value will only be used when the user does not provide one.
72 -$egMapsGoogleMapsZoom = 14; # Google Maps
73 -$egMapsYahooMapsZoom = 4; # Yahoo! Maps
74 -$egMapsOpenLayersZoom = 10; # OpenLayers
 89+$egMapsGoogleMapsZoom = 14;
7590
7691 # Boolean. The default value for enabling or disabling the autozoom of a map.
77 -# This is for Google Maps and Yahoo! Maps only. This value will only be used when the user does not provide one.
78 -$egMapsEnableAutozoom = true;
 92+# This value will only be used when the user does not provide one.
 93+$egMapsGoogleAutozoom = true;
7994
8095 # Boolean. The default value for enabling or disabling the earth map type for Google Maps.
8196 # This value will only be used when the user does not provide one.
@@ -84,10 +99,40 @@
85100 # Available short values: large, small. Other values: http://code.google.com/apis/maps/documentation/controls.html#Controls_overview
86101 $egMapsGMapControl = 'large';
87102
 103+# String. The default map type. This value will only be used when the user does not provide one.
 104+$egMapsGoogleMapsType = 'normal';
 105+
 106+
 107+
 108+# Yahoo maps
 109+
 110+# String. The Yahoo maps map name prefix. It can not be identical to the one of another mapping service.
 111+$egMapsYahooMapsPrefix = 'map_yahoo';
 112+
 113+# Integer. The default zoom of a map. This value will only be used when the user does not provide one.
 114+$egMapsYahooMapsZoom = 4;
 115+
 116+# Boolean. The default value for enabling or disabling the autozoom of a map.
 117+# This value will only be used when the user does not provide one.
 118+$egMapsYahooAutozoom = true;
 119+
88120 # Array of String. The default controls for Yahoo! Maps. This value will only be used when the user does not provide one.
89121 # Available values: pan, zoom
90122 $egMapsYMapControls = array('pan', 'zoom');
91123
 124+# String. The default map type. This value will only be used when the user does not provide one.
 125+$egMapsYahooMapsType = 'normal';
 126+
 127+
 128+
 129+# OpenLayers
 130+
 131+# String. The OpenLayers map name prefix. It can not be identical to the one of another mapping service.
 132+$egMapsOpenLayersPrefix = 'open_layer';
 133+
 134+# Integer. The default zoom of a map. This value will only be used when the user does not provide one.
 135+$egMapsOpenLayersZoom = 10;
 136+
92137 # Array of String. The default controls for Open Layers. This value will only be used when the user does not provide one.
93138 # Available values: layerswitcher, mouseposition, panzoom, panzoombar, scaleline, navigation, keyboarddefaults, overviewmap, permalink
94139 # Note: panzoom and panzoombar can NOT be used together
@@ -97,9 +142,8 @@
98143 # Available values: google, bing, yahoo, openlayers, nasa
99144 $egMapsOLLayers = array('openlayers');
100145
101 -# String(s). The map name prefixes for each service. They can not be identical.
102 -$egMapsGoogleMapsPrefix = 'map_google';
103 -$egMapsYahooMapsPrefix = 'map_yahoo';
104 -$egMapsOpenLayersPrefix = 'open_layer';
105146
106147
 148+
 149+
 150+
Index: trunk/extensions/Maps/Maps_Utils.php
@@ -11,74 +11,75 @@
1212 * @author Jeroen De Dauw
1313 */
1414
15 -if( !defined( 'MEDIAWIKI' ) ) {
16 - die( 'Not an entry point.' );
 15+if (! defined ( 'MEDIAWIKI' )) {
 16+ die ( 'Not an entry point.' );
1717 }
1818
1919 class MapsUtils {
20 -
21 - public static function getLatLon($param2) {
22 - $coordinates = preg_split("/,/", $param2);
23 - if (count($coordinates) == 2) {
24 - $lat = MapsUtils::convertCoord($coordinates[0]);
25 - $lon = MapsUtils::convertCoord($coordinates[1]);
26 - return array($lat, $lon);
 20+
 21+ public static function getLatLon($coordinates) {
 22+ $coordinates = preg_split ( "/,/", $coordinates );
 23+ if (count ( $coordinates ) == 2) {
 24+ $lat = MapsUtils::convertCoord ( $coordinates [0] );
 25+ $lon = MapsUtils::convertCoord ( $coordinates [1] );
 26+ return array ('lat' => $lat, 'lon' => $lon);
 27+ } else {
 28+ return array ('lat' => null, 'lon' => null);
2729 }
28 - return array(null, null);
2930 }
30 -
31 - private static function degree2Decimal($deg_coord="") {
32 - $dpos=strpos($deg_coord,'°');
33 - $mpos=strpos($deg_coord,'.');
34 - $spos=strpos($deg_coord,'"');
35 - $mlen=(($mpos-$dpos)-1);
36 - $slen=(($spos-$mpos)-1);
37 - $direction=substr(strrev($deg_coord),0,1);
38 - $degrees=substr($deg_coord,0,$dpos);
39 - $minutes=substr($deg_coord,$dpos+1,$mlen);
40 - $seconds=substr($deg_coord,$mpos+1,$slen);
41 - $seconds=($seconds/60);
42 - $minutes=($minutes+$seconds);
43 - $minutes=($minutes/60);
44 - $decimal=($degrees+$minutes);
 31+
 32+ private static function degree2Decimal($deg_coord = "") {
 33+ $dpos = strpos ( $deg_coord, '°' );
 34+ $mpos = strpos ( $deg_coord, '.' );
 35+ $spos = strpos ( $deg_coord, '"' );
 36+ $mlen = (($mpos - $dpos) - 1);
 37+ $slen = (($spos - $mpos) - 1);
 38+ $direction = substr ( strrev ( $deg_coord ), 0, 1 );
 39+ $degrees = substr ( $deg_coord, 0, $dpos );
 40+ $minutes = substr ( $deg_coord, $dpos + 1, $mlen );
 41+ $seconds = substr ( $deg_coord, $mpos + 1, $slen );
 42+ $seconds = ($seconds / 60);
 43+ $minutes = ($minutes + $seconds);
 44+ $minutes = ($minutes / 60);
 45+ $decimal = ($degrees + $minutes);
4546 //South latitudes and West longitudes need to return a negative result
46 - if (($direction=="S") or ($direction=="W")) {
47 - $decimal *= -1;
 47+ if (($direction == "S") or ($direction == "W")) {
 48+ $decimal *= - 1;
4849 }
4950 return $decimal;
5051 }
51 -
 52+
5253 private static function decDegree2Decimal($deg_coord = "") {
53 - $direction = substr(strrev($deg_coord), 0, 1);
54 - $decimal = floatval($deg_coord);
 54+ $direction = substr ( strrev ( $deg_coord ), 0, 1 );
 55+ $decimal = floatval ( $deg_coord );
5556 if (($direction == "S") or ($direction == "W")) {
56 - $decimal *= -1;
 57+ $decimal *= - 1;
5758 }
5859 return $decimal;
5960 }
60 -
 61+
6162 private static function convertCoord($deg_coord = "") {
62 - if (preg_match('/°/', $deg_coord)) {
63 - if (preg_match('/"/', $deg_coord)) {
64 - return MapsUtils::degree2Decimal($deg_coord);
 63+ if (preg_match ( '/°/', $deg_coord )) {
 64+ if (preg_match ( '/"/', $deg_coord )) {
 65+ return MapsUtils::degree2Decimal ( $deg_coord );
6566 } else {
66 - return MapsUtils::decDegree2Decimal($deg_coord);
 67+ return MapsUtils::decDegree2Decimal ( $deg_coord );
6768 }
6869 }
6970 return $deg_coord;
7071 }
71 -
 72+
7273 public static function latDecimal2Degree($decimal) {
7374 if ($decimal < 0) {
74 - return abs($decimal) . "° S";
 75+ return abs ( $decimal ) . "° S";
7576 } else {
7677 return $decimal . "° N";
7778 }
7879 }
79 -
 80+
8081 public static function lonDecimal2Degree($decimal) {
8182 if ($decimal < 0) {
82 - return abs($decimal) . "° W";
 83+ return abs ( $decimal ) . "° W";
8384 } else {
8485 return $decimal . "° E";
8586 }
@@ -90,7 +91,8 @@
9192 * @param unknown_type $value
9293 */
9394 public static function makePxValue(&$value) {
94 - if (substr($value, strlen($value) - 2) != 'px') $value .= 'px';
 95+ if (substr ( $value, strlen ( $value ) - 2 ) != 'px')
 96+ $value .= 'px';
9597 }
9698
9799 }
Index: trunk/extensions/Maps/Maps_BaseMap.php
@@ -15,6 +15,8 @@
1616
1717 abstract class MapsBaseMap extends MapsMapFeature {
1818
 19+ protected $markerData = array();
 20+
1921 /**
2022 * Handles the request from the parser hook by doing the work that's common for all
2123 * mapping services, calling the specific methods and finally returning the resulting output.
@@ -31,8 +33,6 @@
3234
3335 $this->manageMapProperties($map, 'MapsBaseMap');
3436
35 - $this->autozoom = ($this->autozoom == 'no' || $this->autozoom == 'off') ? 'false' : 'true';
36 -
3737 $this->setZoom();
3838
3939 $this->setCoordinates();
@@ -43,8 +43,6 @@
4444 return $this->output;
4545 }
4646
47 -
48 -
4947 /**
5048 * Sets the zoom level to the provided value, or when not set, to the default.
5149 *
@@ -57,10 +55,12 @@
5856 * Sets the $marler_lon and $marler_lat fields.
5957 *
6058 */
61 - private function setCoordinates() {
62 - $this->coordinates = str_replace('″', '"', $this->coordinates);
63 - $this->coordinates = str_replace('′', "'", $this->coordinates);
64 - list($this->marker_lat, $this->marker_lon) = MapsUtils::getLatLon($this->coordinates);
 59+ private function setCoordinates() {
 60+ foreach($this->coordinates as $coordinates) {
 61+ $coordinates = str_replace('″', '"', $coordinates);
 62+ $coordinates = str_replace('′', "'", $coordinates);
 63+ $this->markerData[] = MapsUtils::getLatLon($coordinates);
 64+ }
6565 }
6666
6767 /**
@@ -70,11 +70,24 @@
7171 */
7272 private function setCentre() {
7373 if (empty($this->centre)) {
74 - $this->centre_lat = $this->marker_lat;
75 - $this->centre_lon = $this->marker_lon;
 74+ if (count($this->markerData) == 1) {
 75+ $this->centre_lat = $this->markerData[0]['lat'];
 76+ $this->centre_lon = $this->markerData[0]['lon'];
 77+ }
 78+ elseif (count($this->markerData) > 1) {
 79+ // TODO
 80+ die("// TODO: calculate centre and zoom (with SGM code?)");
 81+ }
 82+ else {
 83+ global $egMapsMapLat, $egMapsMapLon;
 84+ $this->centre_lat = $egMapsMapLat;
 85+ $this->centre_lon = $egMapsMapLon;
 86+ }
7687 }
7788 else {
78 - list($this->centre_lat, $this->centre_lon) = MapsUtils::getLatLon($this->centre);
 89+ $centre = MapsUtils::getLatLon($this->centre);
 90+ $this->centre_lat = $centre['lat'];
 91+ $this->centre_lon = $centre['lon'];
7992 }
8093 }
8194

Status & tagging log