Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -63,19 +63,22 @@ |
64 | 64 | return self::getMapHtml($parser, $params, 'display_point', $fails); |
65 | 65 | } |
66 | 66 | |
67 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) { |
| 67 | + // TODO: refactor up |
| 68 | + public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { |
68 | 69 | global $wgLang; |
69 | 70 | |
70 | 71 | $map = array(); |
| 72 | + $coordFails = array(); |
71 | 73 | |
72 | 74 | // Go through all parameters, split their names and values, and put them in the $map array. |
73 | 75 | foreach($params as $param) { |
74 | | - $split = split('=', $param); |
| 76 | + $split = explode('=', $param); |
75 | 77 | if (count($split) > 1) { |
76 | 78 | $paramName = strtolower(trim($split[0])); |
77 | 79 | $paramValue = trim($split[1]); |
78 | 80 | if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
79 | 81 | $map[$paramName] = $paramValue; |
| 82 | + if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); |
80 | 83 | } |
81 | 84 | } |
82 | 85 | else if (count($split) == 1) { // Default parameter (without name) |
— | — | @@ -94,13 +97,19 @@ |
95 | 98 | |
96 | 99 | // Call the function according to the map service to get the HTML output |
97 | 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 | + } |
98 | 105 | |
99 | | - if (count($coordFails) > 0) { |
100 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>'; |
| 106 | + if (count($geoFails) > 0) { |
| 107 | + $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
101 | 108 | } |
102 | 109 | } |
103 | | - elseif (trim($coords) == "" && count($coordFails) > 0) { |
104 | | - $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 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>' . wfMsgExt('maps_map_cannot_be_displayed') .'</i>'; |
105 | 114 | } |
106 | 115 | else { |
107 | 116 | $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
— | — | @@ -110,6 +119,7 @@ |
111 | 120 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
112 | 121 | } |
113 | 122 | |
| 123 | + // TODO: refactor up |
114 | 124 | private static function getParserClassInstance($service, $parserFunction) { |
115 | 125 | global $egMapsServices; |
116 | 126 | // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -62,10 +62,12 @@ |
63 | 63 | return self::getMapHtml($parser, $params, 'display_map', $fails); |
64 | 64 | } |
65 | 65 | |
66 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) { |
| 66 | + // TODO: refactor up |
| 67 | + public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { |
67 | 68 | global $wgLang; |
68 | 69 | |
69 | 70 | $map = array(); |
| 71 | + $coordFails = array(); |
70 | 72 | |
71 | 73 | // Go through all parameters, split their names and values, and put them in the $map array. |
72 | 74 | foreach($params as $param) { |
— | — | @@ -75,6 +77,7 @@ |
76 | 78 | $paramValue = trim($split[1]); |
77 | 79 | if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
78 | 80 | $map[$paramName] = $paramValue; |
| 81 | + if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); |
79 | 82 | } |
80 | 83 | } |
81 | 84 | else if (count($split) == 1) { // Default parameter (without name) |
— | — | @@ -94,12 +97,18 @@ |
95 | 98 | // Call the function according to the map service to get the HTML output |
96 | 99 | $output = $mapClass->displayMap($parser, $map); |
97 | 100 | |
98 | | - if (count($coordFails) > 0) { |
99 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>'; |
| 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>'; |
100 | 107 | } |
101 | 108 | } |
102 | | - elseif (trim($coords) == "" && count($coordFails) > 0) { |
103 | | - $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 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>' . wfMsgExt('maps_map_cannot_be_displayed') .'</i>'; |
104 | 113 | } |
105 | 114 | else { |
106 | 115 | $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | |
36 | 36 | $fails = array(); |
37 | 37 | |
| 38 | + // Get the service and geoservice from the parameters, since they are needed to geocode addresses. |
38 | 39 | for ($i = 0; $i < count($params); $i++) { |
39 | 40 | $split = split('=', $params[$i]); |
40 | 41 | if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { |
— | — | @@ -44,27 +45,31 @@ |
45 | 46 | } |
46 | 47 | } |
47 | 48 | |
| 49 | + // Make sure the service and geoservice are valid. |
48 | 50 | $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; |
49 | | - |
50 | | - if (!isset($geoservice)) $geoservice = ''; |
| 51 | + if (! isset($geoservice)) $geoservice = ''; |
51 | 52 | |
| 53 | + // Go over all parameters. |
52 | 54 | for ($i = 0; $i < count($params); $i++) { |
53 | | - |
54 | 55 | $split = split('=', $params[$i]); |
55 | | - $isAddress = ((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1) || count($split) == 1; |
| 56 | + $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1; |
| 57 | + $isDefault = count($split) == 1; |
56 | 58 | |
57 | | - if ($isAddress) { |
58 | | - $address_srting = count($split) == 1 ? $split[0] : $split[1]; |
| 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]; |
59 | 63 | $addresses = explode(';', $address_srting); |
60 | 64 | |
61 | 65 | $coordinates = array(); |
62 | 66 | |
| 67 | + // Go over every location and attempt to geocode it. |
63 | 68 | foreach($addresses as $address) { |
64 | 69 | $args = explode('~', $address); |
65 | 70 | $args[0] = trim($args[0]); |
66 | 71 | |
67 | 72 | if (strlen($args[0]) > 0) { |
68 | | - $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service); |
| 73 | + $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault); |
69 | 74 | |
70 | 75 | if ($coords) { |
71 | 76 | $args[0] = $coords; |
— | — | @@ -76,7 +81,8 @@ |
77 | 82 | } |
78 | 83 | } |
79 | 84 | |
80 | | - $params[$i] = 'coordinates=' . implode(';', $coordinates); |
| 85 | + // Add the geocoded result back to the parameter list. |
| 86 | + $params[$i] = implode(';', $coordinates); |
81 | 87 | |
82 | 88 | } |
83 | 89 | |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -47,6 +47,31 @@ |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
| 51 | + /** |
| 52 | + * Filters all non coordinate valus from a coordinate string, |
| 53 | + * and returns an array containing all filtered out values. |
| 54 | + * |
| 55 | + * @param string $coordList |
| 56 | + * @return array |
| 57 | + */ |
| 58 | + public static function filterInvalidCoords(&$coordList, $delimeter = ';') { |
| 59 | + $coordFails = array(); |
| 60 | + $validCoordinates = array(); |
| 61 | + $coordinates = explode($delimeter, $coordList); |
| 62 | + |
| 63 | + foreach($coordinates as $coordinate) { |
| 64 | + if (MapsGeocodeUtils::isCoordinate($coordinate)) { |
| 65 | + $validCoordinates[] = $coordinate; |
| 66 | + } |
| 67 | + else { |
| 68 | + $coordFails[] = $coordinate; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + $coordList = implode($delimeter, $validCoordinates); |
| 73 | + return $coordFails; |
| 74 | + } |
| 75 | + |
51 | 76 | |
52 | 77 | |
53 | 78 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('Maps_VERSION', '0.4.2 a2'); |
| 27 | +define('Maps_VERSION', '0.4.2 rc1'); |
28 | 28 | |
29 | 29 | $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; |
30 | 30 | $egMapsIP = $IP . '/extensions/Maps'; |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -39,9 +39,9 @@ |
40 | 40 | * Gets if a provided name is present in the aliases array of a parameter |
41 | 41 | * name in the $mainParams array. |
42 | 42 | * |
43 | | - * @param string $name |
44 | | - * @param string $mainParamName |
45 | | - * @param string $compareMainName |
| 43 | + * @param string $name The name you want to check for. |
| 44 | + * @param string $mainParamName The main parameter name. |
| 45 | + * @param boolean $compareMainName Boolean indicating wether the main name should also be compared. |
46 | 46 | * @return boolean |
47 | 47 | */ |
48 | 48 | public static function inParamAliases($name, $mainParamName, $compareMainName = true) { |
Index: trunk/extensions/Maps/Maps.i18n.php |
— | — | @@ -21,12 +21,15 @@ |
22 | 22 | Available mapping services: $1", |
23 | 23 | 'maps_map' => 'Map', |
24 | 24 | |
25 | | - // Geocoding errors |
| 25 | + // Coordinate errors |
26 | 26 | 'maps_coordinates_missing' => 'No coordinates provided for the map.', |
27 | | - 'maps_geocoding_failed' => 'The following {{PLURAL:$2|address|addresses}} could not be geocoded: $1. |
28 | | -The map cannot be displayed.', |
| 27 | + 'maps_geocoding_failed' => 'The following {{PLURAL:$2|address|addresses}} could not be geocoded: $1.', |
29 | 28 | 'maps_geocoding_failed_for' => 'The following {{PLURAL:$2|address|addresses}} could not be geocoded and {{PLURAL:$2|has|have}} been omitted from the map: |
30 | 29 | $1', |
| 30 | + 'maps_unrecognized_coords' => 'The following coordinates where not recognized: $1.', |
| 31 | + 'maps_unrecognized_coords_for' => 'The following coordinates where not recognized and {{PLURAL:$2|has|have}} been omitted from the map: |
| 32 | +$1', |
| 33 | + 'maps_map_cannot_be_displayed' => 'The map cannot be displayed.', |
31 | 34 | |
32 | 35 | // Parameter errors. Used when strict parameter validation is turned on. |
33 | 36 | 'maps_error_parameters' => 'The following errors have been detected in your syntaxis', |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | # Array. The default overlays for the Google Maps overlays control, and wether they should be shown at pageload. |
169 | 169 | # This value will only be used when the user does not provide one. |
170 | 170 | # Available values: photos, videos, wikipedia, webcams |
171 | | -$egMapsGMapOverlays = array('photos' => false, 'videos' => true, 'wikipedia' => true, 'webcams' => false); |
| 171 | +$egMapsGMapOverlays = array('photos' => false, 'videos' => false, 'wikipedia' => false, 'webcams' => false); |
172 | 172 | |
173 | 173 | |
174 | 174 | |
Index: trunk/extensions/Maps/Geocoders/Maps_GeocodeUtils.php |
— | — | @@ -25,9 +25,14 @@ |
26 | 26 | * |
27 | 27 | * @return string or boolean |
28 | 28 | */ |
29 | | - public static function attemptToGeocode($coordsOrAddress, $geoservice, $service) { |
30 | | - if (MapsGeocodeUtils::isCoordinate($coordsOrAddress)) { |
31 | | - $coords = $coordsOrAddress; |
| 29 | + public static function attemptToGeocode($coordsOrAddress, $geoservice, $service, $checkForCoords = true) { |
| 30 | + if ($checkForCoords) { |
| 31 | + if (MapsGeocodeUtils::isCoordinate($coordsOrAddress)) { |
| 32 | + $coords = $coordsOrAddress; |
| 33 | + } |
| 34 | + else { |
| 35 | + $coords = MapsGeocoder::geocodeToString($coordsOrAddress, $geoservice, $service); |
| 36 | + } |
32 | 37 | } |
33 | 38 | else { |
34 | 39 | $coords = MapsGeocoder::geocodeToString($coordsOrAddress, $geoservice, $service); |
— | — | @@ -43,18 +48,19 @@ |
44 | 49 | * |
45 | 50 | * @return boolean |
46 | 51 | */ |
47 | | - private static function isCoordinate($coordsOrAddress) { |
| 52 | + public static function isCoordinate($coordsOrAddress) { |
48 | 53 | $coordRegexes = array( |
49 | | - '/^(-)?\d{1,3}(\.\d{1,7})?,(\s)?(-)?\d{1,3}(\.\d{1,7})?$/', // Floats |
| 54 | + '/^(-)?\d{1,3}(\.\d{1,14})?,(\s)?(-)?\d{1,3}(\.\d{1,14})?$/', // Floats |
50 | 55 | '/^(\d{1,3}°)(\d{1,2}(\′|\'))?((\d{1,2}(″|"))?|(\d{1,2}\.\d{1,2}(″|"))?)(N|S)(\s)?(\d{1,3}°)(\d{1,2}(\′|\'))?((\d{1,2}(″|"))?|(\d{1,2}\.\d{1,2}(″|"))?)(E|W)$/', // DMS |
51 | | - '/^(-)?\d{1,3}(|\.\d{1,7})°,(\s)?(-)?(\s)?\d{1,3}(|\.\d{1,7})°$/', // DD |
52 | | - '/(-)?\d{1,3}°\d{1,3}(\.\d{1,7}\')?,(\s)?(-)?\d{1,3}°\d{1,3}(\.\d{1,7}\')?$/', // DM |
| 56 | + '/^(-)?\d{1,3}(|\.\d{1,14})°,(\s)?(-)?(\s)?\d{1,3}(|\.\d{1,14})°$/', // DD |
| 57 | + '/^\d{1,3}(|\.\d{1,14})°(\s)?(N|S),(\s)?(\s)?\d{1,3}(|\.\d{1,14})°(\s)(E|W)?$/', // DD (directional) |
| 58 | + '/(-)?\d{1,3}°\d{1,3}(\.\d{1,14}\')?,(\s)?(-)?\d{1,3}°\d{1,3}(\.\d{1,14}\')?$/', // DM |
53 | 59 | ); |
54 | 60 | |
55 | 61 | $isCoordinate = false; |
56 | 62 | |
57 | 63 | foreach ($coordRegexes as $coordRegex) { |
58 | | - if (preg_match($coordRegex, $coordsOrAddress)) { |
| 64 | + if (preg_match($coordRegex, trim($coordsOrAddress))) { |
59 | 65 | $isCoordinate = true; |
60 | 66 | continue; |
61 | 67 | } |