r66298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66297‎ | r66298 | r66299 >
Date:21:01, 12 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added support for several distance units
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php (deleted) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php
@@ -1 +0,0 @@
2 -<?php
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -88,7 +88,7 @@
8989 $distance = count( $parts ) > 0 ? trim( array_shift( $parts ) ) : false;
9090
9191 if ( $distance !== false ) {
92 - if ( preg_match( '/^\d+(\.\d+)?\)$/', $distance ) ) {
 92+ if ( preg_match( '/^\d+(\.\d+)?(\s.+)\)$/', $distance ) ) {
9393 $distance = substr( $distance, 0, -1 );
9494 }
9595 else {
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
@@ -28,6 +28,28 @@
2929 public function __construct( SMGeoCoordsValue $dataValue, $radius ) {
3030 parent::__construct( $dataValue, SM_CMP_NEAR );
3131
 32+ // Parse the radius to the actual value and the optional unit.
 33+ $radius = preg_replace('/\s\s+/', ' ', $radius);
 34+ $parts = explode( ' ', $radius );
 35+ $radius = (float)array_shift( $parts );
 36+
 37+ // If there is a unit, find it's ratio and apply it to the radius value.
 38+ if ( count( $parts ) > 0 ) {
 39+ $unit = strtolower( implode( ' ', $parts ) );
 40+
 41+ $ratio = array(
 42+ 'km' => 1000,
 43+ 'mile' => 1609.344,
 44+ 'miles' => 1609.344,
 45+ 'nautical mile' => 1852,
 46+ 'nautical miles' => 1852,
 47+ );
 48+
 49+ if ( array_key_exists( $unit, $ratio ) ) {
 50+ $radius = $radius * $ratio[$unit];
 51+ }
 52+ }
 53+
3254 // If the MapsGeoFunctions class is not loaded, we can not create the bounding box,
3355 // so don't add any conditions.
3456 if ( self::geoFunctionsAreAvailable() ) {
@@ -38,7 +60,7 @@
3961 'lat' => $dbKeys[0],
4062 'lon' => $dbKeys[1]
4163 ),
42 - $radius * 1000
 64+ $radius
4365 );
4466 }
4567 }

Status & tagging log