r59170 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59169‎ | r59170 | r59171 >
Date:14:14, 17 November 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php (deleted) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_point(s) parser functions with OpenLayers
 5+ * File holding the MapsOpenLayersDispPoint class.
66 *
77 * @file Maps_OpenLayersDispPoint.php
88 * @ingroup MapsOpenLayers
@@ -13,6 +13,12 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+
 18+/**
 19+ * Class for handling the display_point(s) parser functions with OpenLayers.
 20+ *
 21+ * @author Jeroen De Dauw
 22+ */
1723 class MapsOpenLayersDispPoint extends MapsBasePointMap {
1824
1925 public $serviceName = MapsOpenLayersUtils::SERVICE_NAME;
@@ -28,6 +34,8 @@
2935
3036 $this->elementNamePrefix = $egMapsOpenLayersPrefix;
3137 $this->defaultZoom = $egMapsOpenLayersZoom;
 38+
 39+ $this->markerStringFormat = 'getOLMarkerData(lat, lon, "title", "label", "icon")';
3240 }
3341
3442 /**
@@ -53,31 +61,12 @@
5462 $controlItems = MapsOpenLayersUtils::createControlsString($this->controls);
5563
5664 MapsMapper::enforceArrayValues($this->layers);
57 - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
 65+ $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
5866
59 - $markerItems = array();
60 -
61 - // TODO: Refactor up
62 - foreach ($this->markerData as $markerData) {
63 - $lat = $markerData['lat'];
64 - $lon = $markerData['lon'];
65 -
66 - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
67 - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
68 -
69 - $title = str_replace("'", "\'", $title);
70 - $label = str_replace("'", "\'", $label);
71 -
72 - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
73 - $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')";
74 - }
75 -
76 - $markersString = implode(',', $markerItems);
77 -
7867 $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
7968 <script type='$wgJsMimeType'> /*<![CDATA[*/
8069 addOnloadHook(
81 - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString], $this->height)
 70+ initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$this->markerString], $this->height)
8271 );
8372 /*]]>*/ </script>";
8473 }
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php
@@ -1,94 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding the MapsParserGeocoder class.
6 - *
7 - * @file Maps_ParserGeocoder.php
8 - * @ingroup Maps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -/**
18 - * Class that holds static helpers for the mapping parser functions. The helpers aid in
19 - * determining the availability of the geocoding parser functions and calling them.
20 - *
21 - * @author Jeroen De Dauw
22 - *
23 - */
24 -final class MapsParserGeocoder {
25 -
26 - /**
27 - * Changes the values of the address or addresses parameter into coordinates
28 - * in the provided array. Returns an array containing the addresses that
29 - * could not be geocoded.
30 - *
31 - * @param array $params
32 - */
33 - public static function changeAddressesToCoords(&$params) {
34 - global $egMapsDefaultService;
35 -
36 - $fails = array();
37 -
38 - // Get the service and geoservice from the parameters, since they are needed to geocode addresses.
39 - for ($i = 0; $i < count($params); $i++) {
40 - $split = explode('=', $params[$i]);
41 - if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) {
42 - $service = trim($split[1]);
43 - }
44 - else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
45 - $geoservice = trim($split[1]);
46 - }
47 - }
48 -
49 - // Make sure the service and geoservice are valid.
50 - $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService;
51 - if (! isset($geoservice)) $geoservice = '';
52 -
53 - // Go over all parameters.
54 - for ($i = 0; $i < count($params); $i++) {
55 - $split = explode('=', $params[$i]);
56 - $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1;
57 - $isDefault = count($split) == 1;
58 -
59 - // If a parameter is either the default (no name), or an addresses list, extract all locations.
60 - if ($isAddress || $isDefault) {
61 -
62 - $address_srting = $split[count($split) == 1 ? 0 : 1];
63 - $addresses = explode(';', $address_srting);
64 -
65 - $coordinates = array();
66 -
67 - // Go over every location and attempt to geocode it.
68 - foreach($addresses as $address) {
69 - $args = explode('~', $address);
70 - $args[0] = trim($args[0]);
71 -
72 - if (strlen($args[0]) > 0) {
73 - $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault);
74 -
75 - if ($coords) {
76 - $args[0] = $coords;
77 - $coordinates[] = implode('~', $args);
78 - }
79 - else {
80 - $fails[] = $args[0];
81 - }
82 - }
83 - }
84 -
85 - // Add the geocoded result back to the parameter list.
86 - $params[$i] = implode(';', $coordinates);
87 -
88 - }
89 -
90 - }
91 -
92 - return $fails;
93 - }
94 -
95 -}
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - *
 5+ * File holding the registration and handling functions for the display_point parser function.
66 *
77 * @file Maps_DisplayPoint.php
88 * @ingroup Maps
@@ -20,111 +20,42 @@
2121 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
2222
2323 /**
24 - * Adds the magic words for the parser functions
 24+ * Adds the magic words for the parser functions.
2525 */
2626 function efMapsDisplayPointMagic( &$magicWords, $langCode ) {
2727 // The display_address(es) aliases are for backward compatibility only, and will be removed eventually.
2828 $magicWords['display_point'] = array( 0, 'display_point', 'display_points', 'display_address', 'display_addresses' );
2929
30 - return true; // Unless we return true, other parser functions won't get loaded
 30+ return true; // Unless we return true, other parser functions won't get loaded.
3131 }
3232
3333 /**
3434 * Adds the parser function hooks
3535 */
3636 function efMapsRegisterDisplayPoint(&$wgParser) {
37 - // Hooks to enable the '#display_point' and '#display_points' parser functions
 37+ // Hooks to enable the '#display_point' and '#display_points' parser functions.
3838 $wgParser->setFunctionHook( 'display_point', array('MapsDisplayPoint', 'displayPointRender') );
3939
4040 return true;
4141 }
4242
4343 /**
 44+ * Class containing the rendering functions for the display_point parser function.
4445 *
45 - *
4646 * @author Jeroen De Dauw
4747 *
4848 */
4949 final class MapsDisplayPoint {
5050
5151 /**
52 - * Sets the default map properties, gets the map HTML depending
53 - * on the provided service, and then returns it.
 52+ * Returns the output for a display_point call.
5453 *
5554 * @param unknown_type $parser
5655 * @return array
5756 */
5857 public static function displayPointRender(&$parser) {
59 - $params = func_get_args();
60 - array_shift( $params ); // We already know the $parser ...
61 -
62 - $fails = MapsParserGeocoder::changeAddressesToCoords($params);
63 -
64 - return self::getMapHtml($parser, $params, 'display_point', $fails);
 58+ $args = func_get_args();
 59+ return MapsParserFunctions::getMapHtml($parser, $args, 'display_point');
6560 }
6661
67 - // TODO: refactor up
68 - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) {
69 - global $wgLang;
70 -
71 - $map = array();
72 - $coordFails = array();
73 -
74 - // Go through all parameters, split their names and values, and put them in the $map array.
75 - foreach($params as $param) {
76 - $split = explode('=', $param);
77 - if (count($split) > 1) {
78 - $paramName = strtolower(trim($split[0]));
79 - $paramValue = trim($split[1]);
80 - if (strlen($paramName) > 0 && strlen($paramValue) > 0) {
81 - $map[$paramName] = $paramValue;
82 - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]);
83 - }
84 - }
85 - else if (count($split) == 1) { // Default parameter (without name)
86 - $split[0] = trim($split[0]);
87 - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0];
88 - }
89 - }
90 -
91 - $coords = MapsMapper::getParamValue('coordinates', $map);
92 -
93 - if ($coords) {
94 - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
95 - $map['service'] = MapsMapper::getValidService($map['service'], 'pf');
96 -
97 - $mapClass = self::getParserClassInstance($map['service'], $parserFunction);
98 -
99 - // Call the function according to the map service to get the HTML output
100 - $output = $mapClass->displayMap($parser, $map);
101 -
102 - if (count($coordFails) > 0) {
103 - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
104 - }
105 -
106 - if (count($geoFails) > 0) {
107 - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
108 - }
109 - }
110 - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) {
111 - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
112 - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
113 - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>';
114 - }
115 - else {
116 - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>';
117 - }
118 -
119 - // Return the result
120 - return array( $output, 'noparse' => true, 'isHTML' => true );
121 - }
122 -
123 - // TODO: refactor up
124 - private static function getParserClassInstance($service, $parserFunction) {
125 - global $egMapsServices;
126 - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not.
127 - //die($egMapsServices[$service]['pf'][$parserFunction]['class']);
128 - return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
129 - }
130 -
13162 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -1,13 +1,11 @@
22 <?php
33
44 /**
5 - * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s)
6 - * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore
7 - * forces inheriting classes to implement sereveral methods.
8 - *
 5+ * File holding class MapsBasePointMap.
 6+ *
97 * @file Maps_BasePointMap.php
108 * @ingroup Maps
11 - *
 9+ *
1210 * @author Jeroen De Dauw
1311 */
1412
@@ -15,9 +13,18 @@
1614 die( 'Not an entry point.' );
1715 }
1816
 17+/**
 18+ * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s)
 19+ * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore
 20+ * forces inheriting classes to implement sereveral methods.
 21+ *
 22+ * @author Jeroen De Dauw
 23+ */
1924 abstract class MapsBasePointMap extends MapsMapFeature {
2025
21 - protected $markerData = array();
 26+ private $markerData = array();
 27+ protected $markerStringFormat = '';
 28+ protected $markerString;
2229
2330 /**
2431 * Handles the request from the parser hook by doing the work that's common for all
@@ -31,13 +38,15 @@
3239 public final function displayMap(&$parser, array $params) {
3340 $this->setMapSettings();
3441
35 - $coords = $this->manageMapProperties($params, __CLASS__);
 42+ /* $coords = */ $this->manageMapProperties($params, __CLASS__);
3643
3744 $this->doMapServiceLoad();
3845
3946 $this->setMapName();
4047
41 - $this->setCoordinates($parser);
 48+ $this->setCoordinates($parser);
 49+
 50+ $this->createMarkerString();
4251
4352 $this->setZoom();
4453
@@ -110,6 +119,35 @@
111120 }
112121
113122 /**
 123+ * Creates a JS string with the marker data.
 124+ *
 125+ * @return unknown_type
 126+ */
 127+ private function createMarkerString() {
 128+ $markerItems = array();
 129+
 130+ foreach ($this->markerData as $markerData) {
 131+ $lat = $markerData['lat'];
 132+ $lon = $markerData['lon'];
 133+
 134+ $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
 135+ $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
 136+
 137+ $title = str_replace("'", "\'", $title);
 138+ $label = str_replace("'", "\'", $label);
 139+
 140+ $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
 141+
 142+ $markerItems[] = str_replace( array('lon', 'lat', 'title', 'label', 'icon'),
 143+ array($lon, $lat, $title, $label, $label),
 144+ $this->markerStringFormat
 145+ );
 146+ }
 147+
 148+ $this->markerString = implode(',', $markerItems);
 149+ }
 150+
 151+ /**
114152 * Sets the $centre_lat and $centre_lon fields.
115153 * Note: this needs to be done AFTRE the maker coordinates are set.
116154 */
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - *
 5+ * File holding the registration and handling functions for the display_map parser function.
66 *
77 * @file Maps_DisplayMap.php
88 * @ingroup Maps
@@ -20,109 +20,41 @@
2121 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
2222
2323 /**
24 - * Adds the magic words for the parser functions
 24+ * Adds the magic words for the parser functions.
2525 */
2626 function efMapsDisplayMapMagic( &$magicWords, $langCode ) {
2727 $magicWords['display_map'] = array( 0, 'display_map');
2828
29 - return true; // Unless we return true, other parser functions won't get loaded
 29+ return true; // Unless we return true, other parser functions won't get loaded.
3030 }
3131
3232 /**
3333 * Adds the parser function hooks
3434 */
3535 function efMapsRegisterDisplayMap(&$wgParser) {
36 - // A hook to enable the '#display_map' parser function
 36+ // A hook to enable the '#display_map' parser function.
3737 $wgParser->setFunctionHook( 'display_map', array('MapsDisplayMap', 'displayMapRender') );
3838
3939 return true;
4040 }
4141
4242 /**
 43+ * Class containing the rendering functions for the display_map parser function.
4344 *
44 - *
4545 * @author Jeroen De Dauw
4646 *
4747 */
4848 final class MapsDisplayMap {
4949
5050 /**
51 - * If an address value is provided, turn it into coordinates,
52 - * then calls getMapHtml() and returns it's result.
 51+ * Returns the output for a display_map call.
5352 *
5453 * @param unknown_type $parser
5554 * @return array
5655 */
57 - public static function displayMapRender(&$parser) {
58 - $params = func_get_args();
59 - array_shift( $params ); // We already know the $parser ...
60 -
61 - $fails = MapsParserGeocoder::changeAddressesToCoords($params);
62 -
63 - return self::getMapHtml($parser, $params, 'display_map', $fails);
 56+ public static function displayMapRender(&$parser) {
 57+ $args = func_get_args();
 58+ return MapsParserFunctions::getMapHtml($parser, $args, 'display_map');
6459 }
65 -
66 - // TODO: refactor up
67 - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) {
68 - global $wgLang;
69 -
70 - $map = array();
71 - $coordFails = array();
72 -
73 - // Go through all parameters, split their names and values, and put them in the $map array.
74 - foreach($params as $param) {
75 - $split = split('=', $param);
76 - if (count($split) > 1) {
77 - $paramName = strtolower(trim($split[0]));
78 - $paramValue = trim($split[1]);
79 - if (strlen($paramName) > 0 && strlen($paramValue) > 0) {
80 - $map[$paramName] = $paramValue;
81 - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]);
82 - }
83 - }
84 - else if (count($split) == 1) { // Default parameter (without name)
85 - $split[0] = trim($split[0]);
86 - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0];
87 - }
88 - }
89 -
90 - $coords = MapsMapper::getParamValue('coordinates', $map);
91 -
92 - if ($coords) {
93 - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
94 - $map['service'] = MapsMapper::getValidService($map['service'], 'pf');
95 -
96 - $mapClass = self::getParserClassInstance($map['service'], $parserFunction);
97 -
98 - // Call the function according to the map service to get the HTML output
99 - $output = $mapClass->displayMap($parser, $map);
100 -
101 - if (count($coordFails) > 0) {
102 - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
103 - }
104 -
105 - if (count($geoFails) > 0) {
106 - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($geoFails ), count( $geoFails ) ) . '</i>';
107 - }
108 - }
109 - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) {
110 - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
111 - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
112 - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>';
113 - }
114 - else {
115 - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>';
116 - }
117 -
118 - // Return the result
119 - return array( $output, 'noparse' => true, 'isHTML' => true );
120 - }
12160
122 - private static function getParserClassInstance($service, $parserFunction) {
123 - global $egMapsServices;
124 - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not.
125 - //die($egMapsServices[$service]['pf'][$parserFunction]['class']);
126 - return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
127 - }
128 -
12961 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -15,23 +15,18 @@
1616
1717 /**
1818 * A class that holds handlers for the mapping parser functions.
19 - * Spesific functions are located in @see MapsUtils
2019 *
2120 * @author Jeroen De Dauw
22 - *
2321 */
2422 final class MapsParserFunctions {
2523
2624 /**
2725 * Initialize the parser functions feature. This function handles the parser function hook,
2826 * and will load the required classes.
29 - *
3027 */
3128 public static function initialize() {
32 - global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices;
 29+ global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsServices;
3330
34 - $wgAutoloadClasses['MapsParserGeocoder'] = $egMapsIP. '/ParserFunctions/Maps_ParserGeocoder.php';
35 -
3631 foreach($egMapsServices as $serviceName => $serviceData) {
3732 // Check if the service has parser function support
3833 $hasPFs = array_key_exists('pf', $serviceData);
@@ -48,13 +43,83 @@
4944 }
5045
5146 /**
 47+ * Returns the output for the call to the specified parser function.
 48+ *
 49+ * @param $parser
 50+ * @param array $params
 51+ * @param string $parserFunction
 52+ *
 53+ * @return array
 54+ */
 55+ public static function getMapHtml(&$parser, array $params, $parserFunction) {
 56+ global $wgLang;
 57+
 58+ array_shift( $params ); // We already know the $parser.
 59+
 60+ $map = array();
 61+ $coordFails = array();
 62+
 63+ $geoFails = self::changeAddressesToCoords($params);
 64+
 65+ // Go through all parameters, split their names and values, and put them in the $map array.
 66+ foreach($params as $param) {
 67+ $split = explode('=', $param);
 68+ if (count($split) > 1) {
 69+ $paramName = strtolower(trim($split[0]));
 70+ $paramValue = trim($split[1]);
 71+ if (strlen($paramName) > 0 && strlen($paramValue) > 0) {
 72+ $map[$paramName] = $paramValue;
 73+ if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = self::filterInvalidCoords($map[$paramName]);
 74+ }
 75+ }
 76+ else if (count($split) == 1) { // Default parameter (without name)
 77+ $split[0] = trim($split[0]);
 78+ if (strlen($split[0]) > 0) $map['coordinates'] = $split[0];
 79+ }
 80+ }
 81+
 82+ $coords = MapsMapper::getParamValue('coordinates', $map);
 83+
 84+ if ($coords) {
 85+ if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
 86+ $map['service'] = MapsMapper::getValidService($map['service'], 'pf');
 87+
 88+ $mapClass = self::getParserClassInstance($map['service'], $parserFunction);
 89+
 90+ // Call the function according to the map service to get the HTML output
 91+ $output = $mapClass->displayMap($parser, $map);
 92+
 93+ if (count($coordFails) > 0) {
 94+ $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
 95+ }
 96+
 97+ if (count($geoFails) > 0) {
 98+ $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
 99+ }
 100+ }
 101+ elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) {
 102+ if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
 103+ if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
 104+ $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>';
 105+ }
 106+ else {
 107+ $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>';
 108+ }
 109+
 110+ // Return the result
 111+ return array( $output, 'noparse' => true, 'isHTML' => true );
 112+ }
 113+
 114+ /**
52115 * Filters all non coordinate valus from a coordinate string,
53116 * and returns an array containing all filtered out values.
54117 *
55118 * @param string $coordList
 119+ * @param string $delimeter
 120+ *
56121 * @return array
57122 */
58 - public static function filterInvalidCoords(&$coordList, $delimeter = ';') {
 123+ private static function filterInvalidCoords(&$coordList, $delimeter = ';') {
59124 $coordFails = array();
60125 $validCoordinates = array();
61126 $coordinates = explode($delimeter, $coordList);
@@ -72,6 +137,89 @@
73138 return $coordFails;
74139 }
75140
 141+ /**
 142+ * Changes the values of the address or addresses parameter into coordinates
 143+ * in the provided array. Returns an array containing the addresses that
 144+ * could not be geocoded.
 145+ *
 146+ * @param array $params
 147+ *
 148+ * @return array
 149+ */
 150+ private static function changeAddressesToCoords(&$params) {
 151+ global $egMapsDefaultService;
76152
 153+ $fails = array();
 154+
 155+ // Get the service and geoservice from the parameters, since they are needed to geocode addresses.
 156+ for ($i = 0; $i < count($params); $i++) {
 157+ $split = explode('=', $params[$i]);
 158+ if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) {
 159+ $service = trim($split[1]);
 160+ }
 161+ else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
 162+ $geoservice = trim($split[1]);
 163+ }
 164+ }
77165
 166+ // Make sure the service and geoservice are valid.
 167+ $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService;
 168+ if (! isset($geoservice)) $geoservice = '';
 169+
 170+ // Go over all parameters.
 171+ for ($i = 0; $i < count($params); $i++) {
 172+ $split = explode('=', $params[$i]);
 173+ $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1;
 174+ $isDefault = count($split) == 1;
 175+
 176+ // If a parameter is either the default (no name), or an addresses list, extract all locations.
 177+ if ($isAddress || $isDefault) {
 178+
 179+ $address_srting = $split[count($split) == 1 ? 0 : 1];
 180+ $addresses = explode(';', $address_srting);
 181+
 182+ $coordinates = array();
 183+
 184+ // Go over every location and attempt to geocode it.
 185+ foreach($addresses as $address) {
 186+ $args = explode('~', $address);
 187+ $args[0] = trim($args[0]);
 188+
 189+ if (strlen($args[0]) > 0) {
 190+ $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault);
 191+
 192+ if ($coords) {
 193+ $args[0] = $coords;
 194+ $coordinates[] = implode('~', $args);
 195+ }
 196+ else {
 197+ $fails[] = $args[0];
 198+ }
 199+ }
 200+ }
 201+
 202+ // Add the geocoded result back to the parameter list.
 203+ $params[$i] = implode(';', $coordinates);
 204+
 205+ }
 206+
 207+ }
 208+
 209+ return $fails;
 210+ }
 211+
 212+ /**
 213+ * Returns an instance of the class supporting the spesified mapping service for
 214+ * the also spesified parser function.
 215+ *
 216+ * @param string $service
 217+ * @param string $parserFunction
 218+ *
 219+ * @return class
 220+ */
 221+ private static function getParserClassInstance($service, $parserFunction) {
 222+ global $egMapsServices;
 223+ return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
 224+ }
 225+
78226 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.php
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.4.2 rc2');
 27+define('Maps_VERSION', '0.5 a1');
2828
2929 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
3030 $egMapsIP = $IP . '/extensions/Maps';
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_point(s) parser functions with OSM.
 5+ * File holding the MapsOSMDispPoint class.
66 *
77 * @file Maps_OSMDispPoint.php
88 * @ingroup MapsOpenStreetMap
@@ -13,6 +13,11 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+/**
 18+ * Class for handling the display_point(s) parser functions with OSM.
 19+ *
 20+ * @author Jeroen De Dauw
 21+ */
1722 class MapsOSMDispPoint extends MapsBasePointMap {
1823
1924 public $serviceName = MapsOSMUtils::SERVICE_NAME;
@@ -28,6 +33,8 @@
2934
3035 $this->elementNamePrefix = $egMapsOSMPrefix;
3136 $this->defaultZoom = $egMapsOSMZoom;
 37+
 38+ $this->markerStringFormat = 'getOSMMarkerData(lat, lon, "title", "label", "icon")';
3239 }
3340
3441 /**
@@ -48,27 +55,8 @@
4956 *
5057 */
5158 public function addSpecificMapHTML() {
52 - global $wgJsMimeType;
 59+ global $wgJsMimeType;
5360
54 - $markerItems = array();
55 -
56 - // TODO: Refactor up
57 - foreach ($this->markerData as $markerData) {
58 - $lat = $markerData['lat'];
59 - $lon = $markerData['lon'];
60 -
61 - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
62 - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
63 -
64 - $title = str_replace("'", "\'", $title);
65 - $label = str_replace("'", "\'", $label);
66 -
67 - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
68 - $markerItems[] = "getOSMMarkerData($lon, $lat, '$title', '$label', '$icon')";
69 - }
70 -
71 - $markersString = implode(',', $markerItems);
72 -
7361 $controlItems = MapsOSMUtils::createControlsString($this->controls);
7462
7563 $this->output .= <<<EOT
@@ -81,7 +69,7 @@
8270 zoom: $this->zoom,
8371 width: $this->width,
8472 height: $this->height,
85 - markers: [$markersString],
 73+ markers: [$this->markerString],
8674 controls: [$controlItems]
8775
8876 });</script>
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -42,6 +42,7 @@
4343 * @param string $name The name you want to check for.
4444 * @param string $mainParamName The main parameter name.
4545 * @param boolean $compareMainName Boolean indicating wether the main name should also be compared.
 46+ *
4647 * @return boolean
4748 */
4849 public static function inParamAliases($name, $mainParamName, $compareMainName = true) {
@@ -61,6 +62,7 @@
6263 * @param string $paramName
6364 * @param array $stack
6465 * @param boolean $checkForAliases
 66+ *
6567 * @return boolean
6668 */
6769 public static function paramIsPresent($paramName, array $stack, $checkForAliases = true) {
@@ -84,6 +86,7 @@
8587 * @param string $paramName
8688 * @param array $stack
8789 * @param boolean $checkForAliases
 90+ *
8891 * @return the parameter value or false
8992 */
9093 public static function getParamValue($paramName, array $stack, $checkForAliases = true) {
@@ -109,6 +112,7 @@
110113 * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service.
111114 * @param boolean $strict If set to false, values which a key that does not
112115 * exist in the $map array will be retained.
 116+ *
113117 * @return array
114118 */
115119 public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) {
@@ -154,7 +158,7 @@
155159 * @param string $delimeter
156160 */
157161 public static function enforceArrayValues(&$values, $delimeter = ',') {
158 - if (!is_array($values)) $values = split($delimeter, $values); // If not an array yet, split the values
 162+ if (!is_array($values)) $values = explode($delimeter, $values); // If not an array yet, split the values
159163 for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values
160164 }
161165
@@ -165,6 +169,8 @@
166170 * @param array $items
167171 * @param array $defaultItems
168172 * @param boolean $asStrings
 173+ * @param boolean $toLower
 174+ *
169175 * @return string
170176 */
171177 public static function createJSItemsString(array $items, array $defaultItems = null, $asStrings = true, $toLower = true) {
@@ -180,6 +186,8 @@
181187 *
182188 * @param array $paramz
183189 * @param array $serviceParameters
 190+ * @param boolean $strict
 191+ *
184192 * @return array
185193 */
186194 public static function getValidParams(array $paramz, array $serviceParameters, $strict = true) {
@@ -201,6 +209,7 @@
202210 *
203211 * @param string $paramName
204212 * @param array $allowedParms
 213+ *
205214 * @return string
206215 */
207216 private static function getMainParamName($paramName, array $allowedParms) {
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php
@@ -124,7 +124,7 @@
125125 * @param string $output
126126 */
127127 public static function addGMapDependencies(&$output) {
128 - global $wgJsMimeType, $wgLang, $wgOut;
 128+ global $wgJsMimeType, $wgLang;
129129 global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion;
130130
131131 if (empty($egGoogleMapsOnThisPage)) {
@@ -150,26 +150,6 @@
151151 }
152152
153153 /**
154 - * Returns a boolean representing if the earth map type should be showed or not,
155 - * when provided the the wiki code value.
156 - *
157 - * @param string $earthValue
158 - * @param boolean $adaptDefault When not set to false, the default map type will be changed to earth when earth is enabled
159 - * @return boolean Indicates wether the earth type should be enabled.
160 - */
161 - public static function getEarthValue($earthValue, $adaptDefault = true) {
162 - $trueValues = array('on', 'yes');
163 - $enabled = in_array($earthValue, $trueValues);
164 -
165 - if ($enabled && $adaptDefault) {
166 - global $egMapsGoogleMapsType;
167 - $egMapsGoogleMapsType = 'G_SATELLITE_3D_MAP';
168 - }
169 -
170 - return $enabled;
171 - }
172 -
173 - /**
174154 * Returns a JS items string with the provided types. The earth type will
175155 * be added to it when it's not present and $enableEarth is true. If there are
176156 * no types, the default will be used.
@@ -178,13 +158,10 @@
179159 * @param boolean $enableEarth
180160 * @return string
181161 */
182 - public static function createTypesString(array &$types, $enableEarth = false) {
 162+ public static function createTypesString(array &$types) {
183163 global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid;
184164
185165 $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType'));
186 -
187 - // This is to ensure backwards compatibility with 0.1 and 0.2.
188 - if ($enableEarth && ! in_array('G_SATELLITE_3D_MAP', $types)) $types[] = 'G_SATELLITE_3D_MAP';
189166
190167 return MapsMapper::createJSItemsString($types, null, false, false);
191168 }
@@ -202,11 +179,12 @@
203180 }
204181
205182 /**
 183+ * Adds the needed output for the overlays control.
206184 *
207 - *
208185 * @param string $output
209186 * @param string $mapName
210 - * @return unknown_type
 187+ * @param string $overlays
 188+ * @param string $controls
211189 */
212190 public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) {
213191 global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType;
@@ -223,7 +201,7 @@
224202 MapsMapper::enforceArrayValues($overlays);
225203 $validOverlays = array();
226204 foreach ($overlays as $overlay) {
227 - $segements = split('-', $overlay);
 205+ $segements = explode('-', $overlay);
228206 $name = $segements[0];
229207
230208 if (in_array($name, $overlayNames)) {
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_point(s) parser functions with Google Maps
 5+ * File holding the MapsGoogleMapsDispPoint class.
66 *
77 * @file Maps_GoogleMapsDispPoint.php
88 * @ingroup MapsGoogleMaps
@@ -13,6 +13,11 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+/**
 18+ * Class for handling the display_point(s) parser functions with Google Maps.
 19+ *
 20+ * @author Jeroen De Dauw
 21+ */
1722 final class MapsGoogleMapsDispPoint extends MapsBasePointMap {
1823
1924 public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME;
@@ -28,6 +33,8 @@
2934
3035 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
3136 $this->defaultZoom = $egMapsGoogleMapsZoom;
 37+
 38+ $this->markerStringFormat = 'getGMarkerData(lat, lon, "title", "label", "icon")';
3239 }
3340
3441 /**
@@ -48,10 +55,8 @@
4956 *
5057 */
5158 public function addSpecificMapHTML() {
52 - global $wgJsMimeType, $wgOut;
 59+ global $wgJsMimeType;
5360
54 - $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth);
55 -
5661 $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true);
5762
5863 $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
@@ -60,28 +65,9 @@
6166
6267 $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
6368
64 - $markerItems = array();
65 -
66 - // TODO: Refactor up
67 - foreach ($this->markerData as $markerData) {
68 - $lat = $markerData['lat'];
69 - $lon = $markerData['lon'];
70 -
71 - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
72 - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
73 -
74 - $title = str_replace("'", "\'", $title);
75 - $label = str_replace("'", "\'", $label);
76 -
77 - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
78 - $markerItems[] = "getGMarkerData($lat, $lon, '$title', '$label', '$icon')";
79 - }
80 -
81 - $markersString = implode(',', $markerItems);
82 -
8369 $this->types = explode(",", $this->types);
8470
85 - $typesString = MapsGoogleMapsUtils::createTypesString($this->types, $enableEarth);
 71+ $typesString = MapsGoogleMapsUtils::createTypesString($this->types);
8672
8773 $this->output .=<<<END
8874
@@ -100,7 +86,7 @@
10187 controls: [$this->controls],
10288 scrollWheelZoom: $this->autozoom
10389 },
104 - [$markersString]
 90+ [$this->markerString]
10591 )
10692 );
10793 /*]]>*/ </script>
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Class for handling the display_point(s) parser functions with Yahoo! Maps
 5+ * File holding the MapsYahooMapsDispPoint class.
66 *
77 * @file Maps_YahooMapsDispPoint.php
88 * @ingroup MapsYahooMaps
@@ -13,6 +13,11 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+/**
 18+ * Class for handling the display_point(s) parser functions with Yahoo! Maps.
 19+ *
 20+ * @author Jeroen De Dauw
 21+ */
1722 class MapsYahooMapsDispPoint extends MapsBasePointMap {
1823
1924 public $serviceName = MapsYahooMapsUtils::SERVICE_NAME;
@@ -28,6 +33,8 @@
2934
3035 $this->elementNamePrefix = $egMapsYahooMapsPrefix;
3136 $this->defaultZoom = $egMapsYahooMapsZoom;
 37+
 38+ $this->markerStringFormat = 'getYMarkerData(lat, lon, "title", "label", "icon")';
3239 }
3340
3441 /**
@@ -55,25 +62,6 @@
5663 $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
5764
5865 $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
59 -
60 - $markerItems = array();
61 -
62 - // TODO: Refactor up
63 - foreach ($this->markerData as $markerData) {
64 - $lat = $markerData['lat'];
65 - $lon = $markerData['lon'];
66 -
67 - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
68 - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
69 -
70 - $title = str_replace("'", "\'", $title);
71 - $label = str_replace("'", "\'", $label);
72 -
73 - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
74 - $markerItems[] = "getYMarkerData($lat, $lon, '$title', '$label', '$icon')";
75 - }
76 -
77 - $markersString = implode(',', $markerItems);
7866
7967 $this->types = explode(",", $this->types);
8068
@@ -84,7 +72,7 @@
8573
8674 <script type="$wgJsMimeType">/*<![CDATA[*/
8775 addOnloadHook(
88 - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString])
 76+ initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$this->markerString])
8977 );
9078 /*]]>*/</script>
9179 END;

Status & tagging log