Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | */ |
29 | 29 | function efMapsGeoFunctionsMagic( &$magicWords, $langCode ) { |
30 | 30 | $magicWords['geodistance'] = array( 0, 'geodistance' ); |
| 31 | + $magicWords['finddestination'] = array( 0, 'finddestination' ); |
31 | 32 | |
32 | 33 | return true; // Unless we return true, other parser functions won't get loaded. |
33 | 34 | } |
— | — | @@ -37,12 +38,19 @@ |
38 | 39 | function efMapsGeoFunctions( &$wgParser ) { |
39 | 40 | // Hooks to enable the geocoding parser functions. |
40 | 41 | $wgParser->setFunctionHook( 'geodistance', array( 'MapsGeoFunctions', 'renderGeoDistance' ) ); |
| 42 | + $wgParser->setFunctionHook( 'finddestination', array( 'MapsGeoFunctions', 'renderFindDestination' ) ); |
41 | 43 | |
42 | 44 | return true; |
43 | 45 | } |
44 | 46 | |
45 | 47 | final class MapsGeoFunctions { |
46 | 48 | |
| 49 | + /** |
| 50 | + * Handler for the #geodistance parser function. |
| 51 | + * See http://mapping.referata.com/wiki/Geodistance |
| 52 | + * |
| 53 | + * @param Parser $parser |
| 54 | + */ |
47 | 55 | function renderGeoDistance( Parser &$parser ) { |
48 | 56 | $args = func_get_args(); |
49 | 57 | |
— | — | @@ -124,16 +132,68 @@ |
125 | 133 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
126 | 134 | } |
127 | 135 | |
128 | | - public static function renderFindDestination() { |
| 136 | + /** |
| 137 | + * Handler for the #finddestination parser function. |
| 138 | + * See http://mapping.referata.com/wiki/Finddestination |
| 139 | + * |
| 140 | + * @param Parser $parser |
| 141 | + */ |
| 142 | + public static function renderFindDestination( Parser &$parser ) { |
| 143 | + $args = func_get_args(); |
| 144 | + |
| 145 | + // We already know the $parser. |
| 146 | + array_shift( $args ); |
| 147 | + |
| 148 | + // Default parameter assignment, to allow for nameless syntax. |
| 149 | + $defaultParams = array( 'location', 'bearing', 'distance' ); |
| 150 | + $parameters = array(); |
| 151 | + |
| 152 | + // Determine all parameter names and value, and take care of default (nameless) |
| 153 | + // parameters, by turning them into named ones. |
| 154 | + foreach( $args as $arg ) { |
| 155 | + $parts = explode( '=', $arg ); |
| 156 | + if ( count( $parts ) == 1 ) { |
| 157 | + if ( count( $defaultParams ) > 0 ) { |
| 158 | + $defaultParam = array_shift( $defaultParams ); |
| 159 | + $parameters[$defaultParam] = trim( $parts[0] ); |
| 160 | + } |
| 161 | + } else { |
| 162 | + $name = strtolower( trim( array_shift( $parts ) ) ); |
| 163 | + $parameters[$name] = trim( implode( $parts ) ); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + $parameterInfo = array( |
| 168 | + 'location' => array( |
| 169 | + 'required' => true |
| 170 | + ), |
| 171 | + 'bearing' => array( |
| 172 | + 'required' => true |
| 173 | + ), |
| 174 | + 'distance' => array( |
| 175 | + 'required' => true |
| 176 | + ), |
| 177 | + ); |
| 178 | + |
| 179 | + $manager = new ValidatorManager(); |
| 180 | + |
| 181 | + $parameters = $manager->manageMapparameters( $parameters, $parameterInfo ); |
| 182 | + |
| 183 | + $doCalculation = $parameters !== false; |
| 184 | + |
129 | 185 | // TODO |
130 | 186 | } |
131 | 187 | |
132 | 188 | /** |
| 189 | + * Returns the geographical distance between two coordinates. |
| 190 | + * See http://en.wikipedia.org/wiki/Geographical_distance |
133 | 191 | * |
134 | | - * @param unknown_type $start |
135 | | - * @param unknown_type $end |
| 192 | + * @param array $start The first coordinates, as non-directional floats in an array with lat and lon keys. |
| 193 | + * @param array $end The second coordinates, as non-directional floats in an array with lat and lon keys. |
| 194 | + * |
| 195 | + * @return float Distance in km. |
136 | 196 | */ |
137 | | - public static function calculateDistance( $start, $end ) { |
| 197 | + public static function calculateDistance( array $start, array $end ) { |
138 | 198 | $northRad1 = deg2rad( $start['lat'] ); |
139 | 199 | $eastRad1 = deg2rad( $start['lon'] ); |
140 | 200 | |
— | — | @@ -162,12 +222,15 @@ |
163 | 223 | } |
164 | 224 | |
165 | 225 | /** |
| 226 | + * Finds a destination given a starting location, bearing and distance. |
166 | 227 | * |
167 | | - * @param unknown_type $startingCoordinates |
168 | | - * @param unknown_type $bearing |
169 | | - * @param unknown_type $distance |
| 228 | + * @param array $startingCoordinates The starting coordinates, as non-directional floats in an array with lat and lon keys. |
| 229 | + * @param float $bearing The initial bearing in degrees. |
| 230 | + * @param float $distance The distance to travel in km. |
| 231 | + * |
| 232 | + * @return array The desitination coordinates, as non-directional floats in an array with lat and lon keys. |
170 | 233 | */ |
171 | | - public static function findDestination( $startingCoordinates, $bearing, $distance ) { |
| 234 | + public static function findDestination( array $startingCoordinates, $bearing, $distance ) { |
172 | 235 | $angularDistance = $distance / Maps_EARTH_RADIUS; |
173 | 236 | $lat = asin( |
174 | 237 | sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) + |
— | — | @@ -184,6 +247,8 @@ |
185 | 248 | |
186 | 249 | /** |
187 | 250 | * Returns a boolean indicating if MapsGeocoder is available. |
| 251 | + * |
| 252 | + * @return Boolean |
188 | 253 | */ |
189 | 254 | private static function geocoderIsAvailable() { |
190 | 255 | global $wgAutoloadClasses; |
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php |
— | — | @@ -112,12 +112,12 @@ |
113 | 113 | ), |
114 | 114 | 'default' => $egMapsDefaultGeoService |
115 | 115 | ), |
116 | | - 'notation' => array( |
| 116 | + 'format' => array( |
117 | 117 | 'criteria' => array( |
118 | 118 | 'in_array' => $egMapsAvailableCoordNotations |
119 | 119 | ), |
120 | 120 | 'aliases' => array( |
121 | | - 'format' |
| 121 | + 'notation' |
122 | 122 | ), |
123 | 123 | 'default' => $egMapsCoordinateNotation |
124 | 124 | ), |
Index: trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | array_shift( $args ); |
50 | 50 | |
51 | 51 | // For backward compatibility with pre 0.6. |
52 | | - $defaultParams = array( 'location', 'notation', 'directional' ); |
| 52 | + $defaultParams = array( 'location', 'format', 'directional' ); |
53 | 53 | $parameters = array(); |
54 | 54 | |
55 | 55 | // Determine all parameter names and value, and take care of default (nameless) |
— | — | @@ -70,12 +70,12 @@ |
71 | 71 | 'location' => array( |
72 | 72 | 'required' => true |
73 | 73 | ), |
74 | | - 'notation' => array( |
| 74 | + 'format' => array( |
75 | 75 | 'criteria' => array( |
76 | 76 | 'in_array' => $egMapsAvailableCoordNotations |
77 | 77 | ), |
78 | 78 | 'aliases' => array( |
79 | | - 'format' |
| 79 | + 'notation' |
80 | 80 | ), |
81 | 81 | 'default' => $egMapsCoordinateNotation |
82 | 82 | ), |