Index: trunk/extensions/Maps/Maps.i18n.magic.php |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | 'geocode' => array( 0, 'geocode' ), |
11 | 11 | 'geocodelat' => array( 0, 'geocodelat' ), |
12 | 12 | 'geocodelon' => array( 0, 'geocodelon' ), |
| 13 | + 'geodistance' => array( 0, 'geodistance' ), |
| 14 | + 'finddestination' => array( 0, 'finddestination' ), |
13 | 15 | ); |
14 | 16 | |
15 | 17 | $magicWords['ar'] = array( |
Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | $doCalculation = $parameters !== false; |
79 | 79 | |
80 | 80 | if ( $doCalculation ) { |
81 | | - $canGeocode = self::geocoderIsAvailable(); |
| 81 | + $canGeocode = MapsMapper::geocoderIsAvailable(); |
82 | 82 | |
83 | 83 | if ( $canGeocode ) { |
84 | 84 | $start = MapsGeocoder::attemptToGeocode( $parameters['location1'] ); |
— | — | @@ -195,7 +195,7 @@ |
196 | 196 | $doCalculation = $parameters !== false; |
197 | 197 | |
198 | 198 | if ( $doCalculation ) { |
199 | | - $canGeocode = self::geocoderIsAvailable(); |
| 199 | + $canGeocode = MapsMapper::geocoderIsAvailable(); |
200 | 200 | |
201 | 201 | if ( $canGeocode ) { |
202 | 202 | $location = MapsGeocoder::attemptToGeocode( $parameters['location'] ); |
— | — | @@ -298,15 +298,5 @@ |
299 | 299 | ); |
300 | 300 | } |
301 | 301 | |
302 | | - /** |
303 | | - * Returns a boolean indicating if MapsGeocoder is available. |
304 | | - * |
305 | | - * @return Boolean |
306 | | - */ |
307 | | - private static function geocoderIsAvailable() { |
308 | | - global $wgAutoloadClasses; |
309 | | - return array_key_exists( 'MapsGeocoder', $wgAutoloadClasses ); |
310 | | - } |
311 | | - |
312 | 302 | } |
313 | 303 | |
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php |
— | — | @@ -145,7 +145,7 @@ |
146 | 146 | * @return string |
147 | 147 | */ |
148 | 148 | public static function renderGeocoderLat( Parser &$parser, $address, $service = '', $mappingService = '' ) { |
149 | | - if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
| 149 | + if ( MapsMapper::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
150 | 150 | return $geovalues ? $geovalues['lat'] : ''; |
151 | 151 | } |
152 | 152 | |
— | — | @@ -161,11 +161,8 @@ |
162 | 162 | * @return string |
163 | 163 | */ |
164 | 164 | public static function renderGeocoderLon( Parser &$parser, $address, $service = '', $mappingService = '' ) { |
165 | | - if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
| 165 | + if ( MapsMapper::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
166 | 166 | return $geovalues ? $geovalues['lon'] : ''; |
167 | 167 | } |
168 | 168 | |
169 | | -} |
170 | | - |
171 | | - |
172 | | - |
| 169 | +} |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | * and will load the required classes. |
33 | 33 | */ |
34 | 34 | public static function initialize() { |
35 | | - global $egMapsDir, $IP, $wgAutoloadClasses, $egMapsFeatures, $egMapsServices; |
| 35 | + global $egMapsDir, $egMapsFeatures; |
36 | 36 | |
37 | 37 | include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php'; |
38 | 38 | |
— | — | @@ -44,7 +44,6 @@ |
45 | 45 | } |
46 | 46 | |
47 | 47 | private static function initializeParams() { |
48 | | - global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
49 | 48 | } |
50 | 49 | |
51 | 50 | /** |
— | — | @@ -110,7 +109,12 @@ |
111 | 110 | // Call the function according to the map service to get the HTML output. |
112 | 111 | $output = $mapClass->displayMap( $parser, $parameters ) . $manager->getErrorList(); |
113 | 112 | } else { |
114 | | - // TODO: add errors to output depending on validator fatal level |
| 113 | + // TODO: Get failiures |
| 114 | + if ( $egValidatorFatalLevel == Validator_ERRORS_WARN ) { |
| 115 | + $output .= htmlspecialchars( wfMsg( '' ) ); |
| 116 | + } elseif ( $egValidatorFatalLevel > Validator_ERRORS_WARN ) { |
| 117 | + $output .= htmlspecialchars( wfMsg( '' ) ); |
| 118 | + } |
115 | 119 | } |
116 | 120 | |
117 | 121 | // Return the result. |
— | — | @@ -131,8 +135,8 @@ |
132 | 136 | public static function inParamAliases( $name, $mainParamName, array $paramInfo = array(), $compareMainName = true ) { |
133 | 137 | $equals = $compareMainName && $mainParamName == $name; |
134 | 138 | |
135 | | - if ( array_key_exists( $mainParamName, $paramInfo ) ) { |
136 | | - $equals = $equals || in_array( $name, $paramInfo[$mainParamName] ); |
| 139 | + if ( !$equals && array_key_exists( $mainParamName, $paramInfo ) ) { |
| 140 | + $equals = in_array( $name, $paramInfo[$mainParamName] ); |
137 | 141 | } |
138 | 142 | |
139 | 143 | return $equals; |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | 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>.'; |
35 | 35 | } |
36 | 36 | else { |
37 | | - define( 'Maps_VERSION', '0.6 a13' ); |
| 37 | + define( 'Maps_VERSION', '0.6 a14' ); |
38 | 38 | |
39 | 39 | // The different coordinate notations. |
40 | 40 | define( 'Maps_COORDS_FLOAT', 'float' ); |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -23,6 +23,20 @@ |
24 | 24 | Validator::addOutputFormat( 'mapdimension', array( __CLASS__, 'setMapDimension' ) ); |
25 | 25 | Validator::addValidationFunction( 'is_map_dimension', array( __CLASS__, 'isMapDimension' ) ); |
26 | 26 | |
| 27 | + // Take care of maybe not having the geocoder available here. |
| 28 | + // This is done by hooking a MapsGeocoder function that can handle addresses and coordinates, |
| 29 | + // or one of MapsCoordinateParser, which only accepts coordinates. |
| 30 | + if ( self::geocoderIsAvailable() ) { |
| 31 | + $locationValidationFunction = array( 'MapsGeocoder', 'attemptToGeocodeToString' ); |
| 32 | + $locationFormattingFunction = array( __CLASS__, 'attemptToGeocodeToString' ); |
| 33 | + } else { |
| 34 | + $locationValidationFunction = array( 'MapsCoordinateParser', 'areCoordinates' ); |
| 35 | + $locationFormattingFunction = array( __CLASS__, 'parseAndFormat' ); |
| 36 | + } |
| 37 | + |
| 38 | + Validator::addValidationFunction( 'is_location', $locationValidationFunction ); |
| 39 | + Validator::addOutputFormat( 'format_coordinates', $locationFormattingFunction ); |
| 40 | + |
27 | 41 | self::$mainParams = array( |
28 | 42 | 'zoom' => array( |
29 | 43 | 'type' => 'integer', |
— | — | @@ -189,4 +203,22 @@ |
190 | 204 | self::isMapDimension( $value, $dimension, true, $default ); |
191 | 205 | } |
192 | 206 | |
| 207 | + /** |
| 208 | + * Returns a boolean indicating if MapsGeocoder is available. |
| 209 | + * |
| 210 | + * @return Boolean |
| 211 | + */ |
| 212 | + public static function geocoderIsAvailable() { |
| 213 | + global $wgAutoloadClasses; |
| 214 | + return array_key_exists( 'MapsGeocoder', $wgAutoloadClasses ); |
| 215 | + } |
| 216 | + |
| 217 | + public static function attemptToGeocodeToString( &$value ) { |
| 218 | + $value = MapsGeocoder::attemptToGeocodeToString( $value ); |
| 219 | + } |
| 220 | + |
| 221 | + public static function parseAndFormat( &$value ) { |
| 222 | + $value = MapsCoordinateParser::parseAndFormat( $value ); |
| 223 | + } |
| 224 | + |
193 | 225 | } |
Index: trunk/extensions/Maps/Maps_MapFeature.php |
— | — | @@ -92,14 +92,18 @@ |
93 | 93 | global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
94 | 94 | |
95 | 95 | return array( |
| 96 | + 'coordinates' => array( |
| 97 | + 'aliases' => array( 'coords', 'location', 'locations' ), |
| 98 | + 'criteria' => array( |
| 99 | + 'is_location' => array() |
| 100 | + ), |
| 101 | + 'output-type' => 'format_coordinates', |
| 102 | + ), |
96 | 103 | 'service' => array( |
97 | 104 | 'criteria' => array( |
98 | 105 | 'in_array' => $egMapsAvailableServices |
99 | 106 | ), |
100 | 107 | ), |
101 | | - 'coordinates' => array( |
102 | | - 'aliases' => array( 'coords', 'location', 'locations' ), |
103 | | - ), |
104 | 108 | 'geoservice' => array( |
105 | 109 | 'criteria' => array( |
106 | 110 | 'in_array' => $egMapsAvailableGeoServices |
Index: trunk/extensions/Maps/Maps_CoordinateParser.php |
— | — | @@ -141,6 +141,24 @@ |
142 | 142 | * @return string |
143 | 143 | */ |
144 | 144 | public static function formatCoordinates( array $coordinates, $targetFormat = Maps_COORDS_FLOAT, $directional = false, $separator = ', ' ) { |
| 145 | + return implode( $separator, self::formatToArray( $coordinates, $targetFormat, $directional ) ); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Turns a given coordinate set into a single string that gets formatted |
| 150 | + * depending on the $targetType and $directional parameters. |
| 151 | + * |
| 152 | + * they will be parsed to the given notation, which defaults to |
| 153 | + * non-directional floats |
| 154 | + * |
| 155 | + * @param array $coordinates The set of coordinates that needs to be formatted. Either an associative |
| 156 | + * array with lat and lon keys, or a numbered aray with lat on index 0, and lon on index 1. |
| 157 | + * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats. |
| 158 | + * @param boolean $directional Indicates if the target notation should be directional. Defaults to false. |
| 159 | + * |
| 160 | + * @return array |
| 161 | + */ |
| 162 | + public static function formatToArray( array $coordinates, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) { |
145 | 163 | if ( !array_key_exists( 'lat', $coordinates ) || !array_key_exists( 'lon', $coordinates ) ) { |
146 | 164 | list( $coordinates['lat'], $coordinates['lon'] ) = $coordinates; |
147 | 165 | } |
— | — | @@ -150,9 +168,7 @@ |
151 | 169 | 'lon' => self::formatCoordinate( $coordinates['lon'], $targetFormat ), |
152 | 170 | ); |
153 | 171 | |
154 | | - $coordinates = self::setAngles( $coordinates, $directional ); |
155 | | - |
156 | | - return implode( $separator, $coordinates ); |
| 172 | + return self::setAngles( $coordinates, $directional ); |
157 | 173 | } |
158 | 174 | |
159 | 175 | /** |
— | — | @@ -443,4 +459,21 @@ |
444 | 460 | return self::$mSeperatorsRegex; |
445 | 461 | } |
446 | 462 | |
| 463 | + /** |
| 464 | + * |
| 465 | + * @param unknown_type $coordinates |
| 466 | + * @param unknown_type $targetFormat |
| 467 | + * @param unknown_type $directional |
| 468 | + * |
| 469 | + * return |
| 470 | + */ |
| 471 | + public static function parseAndFormat( $coordinates, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) { |
| 472 | + $parsedCoords = self::parseCoordinates( $coordinates ); |
| 473 | + if ( $parsedCoords ) { |
| 474 | + return self::formatCoordinates( $parsedCoords ); |
| 475 | + } else { |
| 476 | + return false; |
| 477 | + } |
| 478 | + } |
| 479 | + |
447 | 480 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php |
— | — | @@ -33,6 +33,7 @@ |
34 | 34 | * @param string $geoservice |
35 | 35 | * @param string $mappingService |
36 | 36 | * @param boolean $checkForCoords |
| 37 | + * @param boolean $checkForCoords |
37 | 38 | * |
38 | 39 | * @return array or false |
39 | 40 | */ |
— | — | @@ -55,10 +56,11 @@ |
56 | 57 | * @param string $coordsOrAddress |
57 | 58 | * @param string $service |
58 | 59 | * @param string $mappingService |
| 60 | + * @param boolean $checkForCoords |
59 | 61 | * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats. |
60 | 62 | * @param boolean $directional Indicates if the target notation should be directional. Defaults to false. |
61 | 63 | * |
62 | | - * @return formatted coordinate string or false |
| 64 | + * @return formatted coordinates string or false |
63 | 65 | */ |
64 | 66 | public static function attemptToGeocodeToString( $coordsOrAddress, $service = '', $mappingService = false, $checkForCoords = true, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) { |
65 | 67 | $geoValues = self::attemptToGeocode( $coordsOrAddress, $service, $mappingService, $checkForCoords ); |
— | — | @@ -97,6 +99,22 @@ |
98 | 100 | } |
99 | 101 | |
100 | 102 | /** |
| 103 | + * Does the same as Geocode, but also formats the result into a string. |
| 104 | + * |
| 105 | + * @param string $coordsOrAddress |
| 106 | + * @param string $service |
| 107 | + * @param string $mappingService |
| 108 | + * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats. |
| 109 | + * @param boolean $directional Indicates if the target notation should be directional. Defaults to false. |
| 110 | + * |
| 111 | + * @return formatted coordinates string or false |
| 112 | + */ |
| 113 | + public static function geocodeToString( $address, $service = '', $mappingService = false, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) { |
| 114 | + $coordinates = self::geocode( $address, $service, $mappingService ); |
| 115 | + return $coordinates ? MapsCoordinateParser::formatCoordinates( $coordinates, $targetFormat, $directional ) : false; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
101 | 119 | * Makes sure that the geo service is one of the available ones. |
102 | 120 | * Also enforces licencing restrictions when no geocoding service is explicitly provided. |
103 | 121 | * |
— | — | @@ -120,16 +138,13 @@ |
121 | 139 | } |
122 | 140 | |
123 | 141 | // If no overrides where applied, use the default mapping service. |
124 | | - if ( strlen( $service ) < 1 ) $service = $egMapsDefaultGeoService; |
| 142 | + if ( $service == '' ) $service = $egMapsDefaultGeoService; |
125 | 143 | } |
126 | 144 | else { |
127 | 145 | // If a service is provided, but is not supported, use the default. |
128 | | - if ( ! array_key_exists( $service, $egMapsAvailableGeoServices ) ) $service = $egMapsDefaultGeoService; |
| 146 | + if ( !array_key_exists( $service, $egMapsAvailableGeoServices ) ) $service = $egMapsDefaultGeoService; |
129 | 147 | } |
130 | 148 | |
131 | 149 | return $service; |
132 | 150 | } |
133 | | -} |
134 | | - |
135 | | - |
136 | | - |
| 151 | +} |
\ No newline at end of file |