r64944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64943‎ | r64944 | r64945 >
Date:20:19, 11 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added docs and fixed some small stuff
Modified paths:
  • /trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
@@ -27,6 +27,7 @@
2828 */
2929 function efMapsGeoFunctionsMagic( &$magicWords, $langCode ) {
3030 $magicWords['geodistance'] = array( 0, 'geodistance' );
 31+ $magicWords['finddestination'] = array( 0, 'finddestination' );
3132
3233 return true; // Unless we return true, other parser functions won't get loaded.
3334 }
@@ -37,12 +38,19 @@
3839 function efMapsGeoFunctions( &$wgParser ) {
3940 // Hooks to enable the geocoding parser functions.
4041 $wgParser->setFunctionHook( 'geodistance', array( 'MapsGeoFunctions', 'renderGeoDistance' ) );
 42+ $wgParser->setFunctionHook( 'finddestination', array( 'MapsGeoFunctions', 'renderFindDestination' ) );
4143
4244 return true;
4345 }
4446
4547 final class MapsGeoFunctions {
4648
 49+ /**
 50+ * Handler for the #geodistance parser function.
 51+ * See http://mapping.referata.com/wiki/Geodistance
 52+ *
 53+ * @param Parser $parser
 54+ */
4755 function renderGeoDistance( Parser &$parser ) {
4856 $args = func_get_args();
4957
@@ -124,16 +132,68 @@
125133 return array( $output, 'noparse' => true, 'isHTML' => true );
126134 }
127135
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+
129185 // TODO
130186 }
131187
132188 /**
 189+ * Returns the geographical distance between two coordinates.
 190+ * See http://en.wikipedia.org/wiki/Geographical_distance
133191 *
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.
136196 */
137 - public static function calculateDistance( $start, $end ) {
 197+ public static function calculateDistance( array $start, array $end ) {
138198 $northRad1 = deg2rad( $start['lat'] );
139199 $eastRad1 = deg2rad( $start['lon'] );
140200
@@ -162,12 +222,15 @@
163223 }
164224
165225 /**
 226+ * Finds a destination given a starting location, bearing and distance.
166227 *
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.
170233 */
171 - public static function findDestination( $startingCoordinates, $bearing, $distance ) {
 234+ public static function findDestination( array $startingCoordinates, $bearing, $distance ) {
172235 $angularDistance = $distance / Maps_EARTH_RADIUS;
173236 $lat = asin(
174237 sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) +
@@ -184,6 +247,8 @@
185248
186249 /**
187250 * Returns a boolean indicating if MapsGeocoder is available.
 251+ *
 252+ * @return Boolean
188253 */
189254 private static function geocoderIsAvailable() {
190255 global $wgAutoloadClasses;
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -112,12 +112,12 @@
113113 ),
114114 'default' => $egMapsDefaultGeoService
115115 ),
116 - 'notation' => array(
 116+ 'format' => array(
117117 'criteria' => array(
118118 'in_array' => $egMapsAvailableCoordNotations
119119 ),
120120 'aliases' => array(
121 - 'format'
 121+ 'notation'
122122 ),
123123 'default' => $egMapsCoordinateNotation
124124 ),
Index: trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php
@@ -48,7 +48,7 @@
4949 array_shift( $args );
5050
5151 // For backward compatibility with pre 0.6.
52 - $defaultParams = array( 'location', 'notation', 'directional' );
 52+ $defaultParams = array( 'location', 'format', 'directional' );
5353 $parameters = array();
5454
5555 // Determine all parameter names and value, and take care of default (nameless)
@@ -70,12 +70,12 @@
7171 'location' => array(
7272 'required' => true
7373 ),
74 - 'notation' => array(
 74+ 'format' => array(
7575 'criteria' => array(
7676 'in_array' => $egMapsAvailableCoordNotations
7777 ),
7878 'aliases' => array(
79 - 'format'
 79+ 'notation'
8080 ),
8181 'default' => $egMapsCoordinateNotation
8282 ),

Status & tagging log