r67448 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67447‎ | r67448 | r67449 >
Date:10:05, 6 June 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.3.2 - improved distance code
Modified paths:
  • /trunk/extensions/Maps/Includes/Maps_DistanceParser.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Includes/Maps_DistanceParser.php
@@ -26,6 +26,8 @@
2727 */
2828 class MapsDistanceParser {
2929
 30+ private static $validatedDistanceUnit = false;
 31+
3032 /**
3133 * Parses a distance optionaly containing a unit to a float value in meters.
3234 *
@@ -81,17 +83,27 @@
8284 return $egMapsDistanceUnits[self::getValidUnit( $unit )];
8385 }
8486
 87+ /**
 88+ * Returns a valid unit. If the provided one is invalid, the default will be used.
 89+ *
 90+ * @param string $unit
 91+ */
8592 public static function getValidUnit( $unit = null ) {
8693 global $egMapsDistanceUnit, $egMapsDistanceUnits;
8794
88 - if ( $unit == null ) {
 95+ // This ensures the value for $egMapsDistanceUnit is correct, and caches the result.
 96+ if ( !self::$validatedDistanceUnit ) {
 97+ if ( !array_key_exists( $egMapsDistanceUnit, $egMapsDistanceUnits ) ) {
 98+ $egMapsDistanceUnit = $egMapsDistanceUnits[0];
 99+ }
 100+
 101+ self::$validatedDistanceUnit = true;
 102+ }
 103+
 104+ if ( $unit == null || !array_key_exists( $unit, $egMapsDistanceUnits ) ) {
89105 $unit = $egMapsDistanceUnit;
90106 }
91107
92 - if ( !array_key_exists( $unit, $egMapsDistanceUnits ) ) {
93 - $unit = $egMapsDistanceUnits[0];
94 - }
95 -
96108 return $unit;
97109 }
98110
Index: trunk/extensions/Maps/Maps.php
@@ -98,7 +98,7 @@
9999
100100 // Remove all hooked in services that should not be available.
101101 foreach ( $egMapsServices as $service => $data ) {
102 - if ( ! in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] );
 102+ if ( !in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] );
103103 }
104104 $egMapsAvailableServices = array_keys( $egMapsServices );
105105

Status & tagging log