r64306 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64305‎ | r64306 | r64307 >
Date:20:10, 28 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - Follow up to r64299 - Fixed issues with previouse revs
Modified paths:
  • /trunk/extensions/Maps/Geocoders/Maps_Geocoder.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Utils.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -92,10 +92,9 @@
9393 foreach ( $this->coordinates as $coordinates ) {
9494 $args = explode( '~', $coordinates );
9595
96 - $args[0] = str_replace( '″', '"', $args[0] );
97 - $args[0] = str_replace( '′', "'", $args[0] );
 96+ $markerData = MapsCoordinateParser::parseCoordinates( $args[0] );
9897
99 - $markerData = MapsUtils::getLatLon( $args[0] );
 98+ if ( !$markerData ) continue;
10099
101100 if ( count( $args ) > 1 ) {
102101 // Parse and add the point specific title if it's present.
@@ -178,7 +177,6 @@
179178
180179 // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
181180 if ( $this->centre ) {
182 - $this->centre = MapsUtils::getLatLon( $this->centre );
183181 $this->centre_lat = Xml::escapeJsString( $this->centre['lat'] );
184182 $this->centre_lon = Xml::escapeJsString( $this->centre['lon'] );
185183 }
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -77,7 +77,6 @@
7878
7979 // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
8080 if ( $this->coordinates ) {
81 - $this->coordinates = MapsUtils::getLatLon( $this->coordinates );
8281 $this->centre_lat = Xml::escapeJsString( $this->coordinates['lat'] );
8382 $this->centre_lon = Xml::escapeJsString( $this->coordinates['lon'] );
8483 }
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -232,7 +232,7 @@
233233 $args[0] = trim( $args[0] );
234234
235235 if ( strlen( $args[0] ) > 0 ) {
236 - $coords = MapsGeocoder::attemptToGeocode( $args[0], $geoservice, $service, $isDefault );
 236+ $coords = MapsGeocoder::attemptToGeocodeToString( $args[0], $geoservice, $service, $isDefault );
237237
238238 if ( $coords ) {
239239 $args[0] = $coords;
Index: trunk/extensions/Maps/Maps.php
@@ -74,7 +74,7 @@
7575 function efMapsSetup() {
7676 global $wgExtensionCredits, $wgLang, $wgAutoloadClasses, $IP;
7777 global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsDefaultGeoService;
78 - global $egMapsAvailableGeoServices, $egMapsDir, $egMapsAvailableFeatures, $egMapsJsExt;
 78+ global $egMapsAvailableGeoServices, $egMapsDir, $egMapsAvailableFeatures, $egMapsUseMinJs, $egMapsJsExt;
7979
8080 // Remove all hooked in services that should not be available.
8181 foreach ( $egMapsServices as $service => $data ) {
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -279,7 +279,9 @@
280280 </div></form></div>
281281 EOT;
282282
283 - $output .= "<script type='$wgJsMimeType'>" . implode( "\n", $onloadFunctions ) . '</script>';
 283+ if ( count($onloadFunctions) > 0 ) {
 284+ $output .= "<script type='$wgJsMimeType'>" . implode( "\n", $onloadFunctions ) . '</script>';
 285+ }
284286 }
285287
286288 /**
Index: trunk/extensions/Maps/Maps_Utils.php
@@ -19,116 +19,8 @@
2020 // TODO: merge with parding done in the geo coord type located in SM.
2121
2222 class MapsUtils {
23 -
24 - /*
25 - * Returns an array containing the latitude (lat) and longitude (lon)
26 - * of the provided coordinate string.
27 - *
28 - * @param string $coordinates
29 - */
30 - public static function getLatLon( $coordinates ) {
31 - $containsComma = strpos( $coordinates, ',' ) !== false;
32 - $coordinates = $containsComma ? preg_split ( '/,/', $coordinates ) : explode ( ' ', $coordinates );
3323
34 - if ( count ( $coordinates ) == 2 ) {
35 - return array (
36 - 'lat' => MapsUtils::convertCoord ( $coordinates [0] ),
37 - 'lon' => MapsUtils::convertCoord ( $coordinates [1] )
38 - );
39 - } else {
40 - return array ( 'lat' => null, 'lon' => null );
41 - }
42 - }
43 -
4424 /**
45 - *
46 - * @param $deg_coord
47 - * @return unknown_type
48 - */
49 - private static function convertCoord( $deg_coord = '' ) {
50 - if ( preg_match ( '/°/', $deg_coord ) ) {
51 - if ( preg_match ( '/"/', $deg_coord ) ) {
52 - return MapsUtils::DMSToDecimal ( $deg_coord );
53 - } else {
54 - return MapsUtils::decDegree2Decimal ( $deg_coord );
55 - }
56 - }
57 - return $deg_coord;
58 - }
59 -
60 - /**
61 - *
62 - *
63 - * @param $deg_coord
64 - * @return unknown_type
65 - */
66 - private static function DMSToDecimal( $dmsCoordinates = '' ) {
67 - $degreePosition = strpos( $dmsCoordinates, '°' );
68 - $minutePosition = strpos( $dmsCoordinates, '.' );
69 - $secondPosition = strpos( $dmsCoordinates, '"' );
70 -
71 - $minuteLength = $minutePosition - $degreePosition - 1;
72 - $secondLength = $secondPosition - $minutePosition - 1;
73 -
74 - $direction = substr ( strrev ( $dmsCoordinates ), 0, 1 );
75 -
76 - $degrees = substr ( $dmsCoordinates, 0, $dpos );
77 - $minutes = substr ( $dmsCoordinates, $dpos + 1, $mlen );
78 - $seconds = substr ( $dmsCoordinates, $mpos + 1, $slen );
79 -
80 - $seconds = ( $seconds / 60 );
81 - $minutes = ( $minutes + $seconds );
82 - $minutes = ( $minutes / 60 );
83 - $decimal = ( $degrees + $minutes );
84 -
85 - // South latitudes and West longitudes need to return a negative result
86 - if ( $direction == "S" || $direction == "W" ) {
87 - $decimal *= - 1;
88 - }
89 - return $decimal;
90 - }
91 -
92 - /**
93 - *
94 - * @param $deg_coord
95 - * @return unknown_type
96 - */
97 - private static function decDegree2Decimal( $deg_coord = "" ) {
98 - $direction = substr ( strrev ( $deg_coord ), 0, 1 );
99 - $decimal = floatval ( $deg_coord );
100 - if ( ( $direction == "S" ) or ( $direction == "W" ) ) {
101 - $decimal *= - 1;
102 - }
103 - return $decimal;
104 - }
105 -
106 - /**
107 - *
108 - * @param $decimal
109 - * @return unknown_type
110 - */
111 - public static function latDecimal2Degree( $decimal ) {
112 - if ( $decimal < 0 ) {
113 - return abs ( $decimal ) . "° S";
114 - } else {
115 - return $decimal . "° N";
116 - }
117 - }
118 -
119 - /**
120 - *
121 - * @param $decimal
122 - * @return unknown_type
123 - */
124 - public static function lonDecimal2Degree( $decimal ) {
125 - if ( $decimal < 0 ) {
126 - return abs ( $decimal ) . "° W";
127 - } else {
128 - return $decimal . "° E";
129 - }
130 - }
131 -
132 - /**
13325 * Convert from WGS84 to spherical mercator.
13426 */
13527 public static function forwardMercator( array $lonlat ) {
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php
@@ -40,29 +40,26 @@
4141 * @param string $geoservice
4242 * @param string $service
4343 * @param boolean $checkForCoords
44 - * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats.
45 - * @param boolean $directional Indicates if the target notation should be directional. Defaults to false.
4644 *
47 - * @return string or boolean
 45+ * @return array or false
4846 */
49 - public static function attemptToGeocode( $coordsOrAddress, $geoservice, $service, $checkForCoords = true, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) {
 47+ public static function attemptToGeocode( $coordsOrAddress, $geoservice, $service, $checkForCoords = true ) {
5048 if ( $checkForCoords ) {
5149 if ( MapsCoordinateParser::areCoordinates( $coordsOrAddress ) ) {
52 - $parsedCoordinates = MapsCoordinateParser::parseCoordinates( $coordsOrAddress );
53 - return MapsCoordinateParser::formatCoordinates( $parsedCoordinates, $targetFormat, $directional );
 50+ return MapsCoordinateParser::parseCoordinates( $coordsOrAddress );
5451 } else {
55 - return self::geocodeToString( $coordsOrAddress, $geoservice, $service, $targetFormat, $directional );
 52+ return self::geocode( $coordsOrAddress, $geoservice, $service );
5653 }
5754 } else {
58 - return self::geocodeToString( $coordsOrAddress, $geoservice, $service, $targetFormat, $directional );
 55+ return self::geocode( $coordsOrAddress, $geoservice, $service );
5956 }
60 - }
 57+ }
6158
6259 /**
6360 * Geocodes an address with the provided geocoding service and returns the result
6461 * as a string with the optionally provided format, or false when the geocoding failed.
6562 *
66 - * @param string $address
 63+ * @param string $coordsOrAddress
6764 * @param string $service
6865 * @param string $mappingService
6966 * @param coordinate type $targetFormat The notation to which they should be formatted. Defaults to floats.
@@ -70,9 +67,9 @@
7168 *
7269 * @return formatted coordinate string or false
7370 */
74 - public static function geocodeToString( $address, $service = '', $mappingService = '', $targetFormat = Maps_COORDS_FLOAT, $directional = false ) {
75 - $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService );
76 - return $geovalues ? MapsCoordinateParser::formatCoordinates( $geovalues, $targetFormat, $directional ) : false;
 71+ public static function attemptToGeocodeToString( $coordsOrAddress, $service = '', $mappingService = '', $checkForCoords = true, $targetFormat = Maps_COORDS_FLOAT, $directional = false ) {
 72+ $geoValues = self::attemptToGeocode( $coordsOrAddress, $service, $mappingService, $checkForCoords );
 73+ return $geoValues ? MapsCoordinateParser::formatCoordinates( $geoValues, $targetFormat, $directional ) : false;
7774 }
7875
7976 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64299Changes for 0.6...jeroendedauw19:09, 28 March 2010

Status & tagging log