tosfos has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92250


Change subject: Added geocoder.us geocoding service
......................................................................

Added geocoder.us geocoding service

Change-Id: I22926c7b66046146e5723e583b0698ea4059f750
---
M Maps.classes.php
M Maps.php
M Maps_Settings.php
A includes/geocoders/Maps_GeocoderusGeocoder.php
4 files changed, 68 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Maps 
refs/changes/50/92250/1

diff --git a/Maps.classes.php b/Maps.classes.php
index 248e640..1ddb325 100644
--- a/Maps.classes.php
+++ b/Maps.classes.php
@@ -49,6 +49,7 @@
 
 $classes['MapsGeonamesGeocoder']               = __DIR__ . 
'/includes/geocoders/Maps_GeonamesGeocoder.php';
 $classes['MapsGoogleGeocoder']                         = __DIR__ . 
'/includes/geocoders/Maps_GoogleGeocoder.php';
+$classes['MapsGeocoderusGeocoder']                     = __DIR__ . 
'/includes/geocoders/Maps_GeocoderusGeocoder.php';
 
 $classes['SpecialMapEditor']                   = __DIR__ . 
'/includes/specials/SpecialMapEditor.php';
 
diff --git a/Maps.php b/Maps.php
index 1c48a53..404f494 100644
--- a/Maps.php
+++ b/Maps.php
@@ -32,7 +32,7 @@
        return;
 }
 
-define( 'Maps_VERSION' , '3.0 alpha' );
+define( 'Maps_VERSION' , '3.0.1 alpha' );
 
 // Include the composer autoloader if it is present.
 if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
@@ -210,6 +210,9 @@
        // Registration of the Google Geocoding (v2) service geocoder.
        $wgHooks['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
 
+       // Registration of the geocoder.us service geocoder.
+       $wgHooks['GeocoderFirstCallInit'][] = 
'MapsGeocoderusGeocoder::register';
+
        // Layers
 
        // Registration of the image layer type.
diff --git a/Maps_Settings.php b/Maps_Settings.php
index 3543ff8..bc69a91 100644
--- a/Maps_Settings.php
+++ b/Maps_Settings.php
@@ -62,6 +62,7 @@
        $egMapsAvailableGeoServices = array(
                'geonames',
                'google',
+               'geocoderus',
        );
 
        // String. The default geocoding service, which will be used when no 
service is
diff --git a/includes/geocoders/Maps_GeocoderusGeocoder.php 
b/includes/geocoders/Maps_GeocoderusGeocoder.php
new file mode 100644
index 0000000..9f14433
--- /dev/null
+++ b/includes/geocoders/Maps_GeocoderusGeocoder.php
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * Class for geocoding requests with geocoder.us Service.
+ *
+ *
+ * @file Maps_GeocoderusGeocoder.php
+ * @ingroup Maps
+ * @ingroup Geocoders
+ *
+ * @licence GNU GPL v2+
+ */
+final class MapsGeocoderusGeocoder extends \Maps\Geocoder {
+
+       /**
+        * Registers the geocoder.
+        * 
+        * No LSB in pre-5.3 PHP *sigh*.
+        * This is to be refactored as soon as php >=5.3 becomes acceptable.
+        * 
+        * @since 3.0.1
+        */
+       public static function register() {
+               \Maps\Geocoders::registerGeocoder( 'geocoderus', __CLASS__ );
+               return true;
+       }
+
+       /**
+        * @see \Maps\Geocoder::getRequestUrl
+        * 
+        * @since 3.0.1
+        * 
+        * @param string $address
+        * 
+        * @return string
+        */
+       protected function getRequestUrl( $address ) {
+               return 'http://geocoder.us/service/rest/?address=' . urlencode( 
$address );
+       }
+
+       /**
+        * @see \Maps\Geocoder::parseResponse
+        * 
+        * @since 3.0.1
+        * 
+        * @param string $address
+        * 
+        * @return array
+        */
+       protected function parseResponse( $response ) {
+               $lon = self::getXmlElementValue( $response, 'geo:long' );
+               $lat = self::getXmlElementValue( $response, 'geo:lat' );
+
+               // In case one of the values is not found, return false.
+               if ( !$lon || !$lat ) return false;
+
+               return array(
+                       'lat' => (float)$lat,
+                       'lon' => (float)$lon
+               );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/92250
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22926c7b66046146e5723e583b0698ea4059f750
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Maps
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to