Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -83,8 +83,9 @@ |
84 | 84 | $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php'; |
85 | 85 | $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php'; |
86 | 86 | $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php'; |
87 | | -//$wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php'; |
88 | 87 | |
| 88 | +$wgAutoloadClasses['ApiGeocode'] = $incDir . 'api/ApiGeocode.php'; |
| 89 | + |
89 | 90 | // Autoload the "includes/criteria/" classes. |
90 | 91 | $criDir = $incDir . 'criteria/'; |
91 | 92 | $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php'; |
— | — | @@ -136,7 +137,9 @@ |
137 | 138 | $wgAutoloadClasses['MapsMapsDoc'] = $phDir . 'Maps_MapsDoc.php'; |
138 | 139 | unset( $phDir ); |
139 | 140 | unset( $incDir ); |
140 | | - |
| 141 | + |
| 142 | +$wgAPIModules['geocode'] = 'ApiGeocode'; |
| 143 | + |
141 | 144 | $wgExtensionMessagesFiles['MapsMagic'] = $egMapsDir . 'Maps.i18n.magic.php'; |
142 | 145 | |
143 | 146 | $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php'; |
— | — | @@ -269,6 +272,15 @@ |
270 | 273 | 'dependencies' => 'jquery.ui.resizable' |
271 | 274 | ); |
272 | 275 | |
| 276 | +$wgAvailableRights[] = 'geocode'; |
| 277 | + |
| 278 | +# Users that can manage the surveys. |
| 279 | +$wgGroupPermissions['*' ]['geocode'] = true; |
| 280 | +$wgGroupPermissions['user' ]['geocode'] = true; |
| 281 | +$wgGroupPermissions['autoconfirmed']['geocode'] = true; |
| 282 | +$wgGroupPermissions['bot' ]['geocode'] = true; |
| 283 | +$wgGroupPermissions['sysop' ]['geocode'] = true; |
| 284 | + |
273 | 285 | $egMapsGlobalJSVars = array(); |
274 | 286 | |
275 | 287 | |
Index: trunk/extensions/Maps/RELEASE-NOTES |
— | — | @@ -7,11 +7,17 @@ |
8 | 8 | http://mapping.referata.com/wiki/Maps/Version_history#Maps_change_log |
9 | 9 | |
10 | 10 | |
| 11 | +=== Maps 1.0.3 === |
| 12 | +(2011-xx-xx) |
| 13 | + |
| 14 | +* Added API module for geocoding. |
| 15 | +* Added 'geocoding' right. |
| 16 | +* Fixed Google Maps v3 JavaScript issue occuring on MediaWiki 1.17. |
| 17 | + |
11 | 18 | === Maps 1.0.2 === |
12 | 19 | (2011-08-24) |
13 | 20 | |
14 | 21 | * Fixed Google Maps v3 JavaScript issue occuring when using Google Earth on unsupported systems. |
15 | | -* Fixed Google Maps v3 JavaScript issue occuring on MediaWiki 1.17 due to buggy mw.config.get. |
16 | 22 | * Fixed internationalization of distances (bug 30467). |
17 | 23 | |
18 | 24 | === Maps 1.0.1 === |
Index: trunk/extensions/Maps/includes/Maps_Geocoders.php |
— | — | @@ -47,6 +47,14 @@ |
48 | 48 | private static $globalGeocoderCache = array(); |
49 | 49 | |
50 | 50 | /** |
| 51 | + * Can geocoding happen, ie are there any geocoders available. |
| 52 | + * |
| 53 | + * @since 1.0.3 |
| 54 | + * @var boolean |
| 55 | + */ |
| 56 | + protected static $canGeocode = false; |
| 57 | + |
| 58 | + /** |
51 | 59 | * Returns if this class can do geocoding operations. |
52 | 60 | * Ie. if there are any geocoders available. |
53 | 61 | * |
— | — | @@ -55,17 +63,45 @@ |
56 | 64 | * @return boolean |
57 | 65 | */ |
58 | 66 | public static function canGeocode() { |
59 | | - static $canGeocode = null; |
| 67 | + self::init(); |
| 68 | + return self::$canGeocode; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Gets a list of available geocoders. |
| 73 | + * |
| 74 | + * @since 1.0.3 |
| 75 | + * |
| 76 | + * @return array |
| 77 | + */ |
| 78 | + public static function getAvailableGeocoders() { |
| 79 | + self::init(); |
| 80 | + return array_keys( self::$registeredGeocoders ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Initiate the geocoding functionality. |
| 85 | + * |
| 86 | + * @since 1.0.3 |
| 87 | + * |
| 88 | + * @return boolean Indicates if init happened |
| 89 | + */ |
| 90 | + public static function init() { |
| 91 | + static $initiated = false; |
60 | 92 | |
61 | | - if ( is_null( $canGeocode ) ) { |
62 | | - // Register the geocoders. |
63 | | - wfRunHooks( 'GeocoderFirstCallInit' ); |
64 | | - |
65 | | - // Determine if there are any geocoders. |
66 | | - $canGeocode = count( self::$registeredGeocoders ) > 0; |
| 93 | + if ( $initiated ) { |
| 94 | + return false; |
67 | 95 | } |
68 | 96 | |
69 | | - return $canGeocode; |
| 97 | + $initiated = true; |
| 98 | + |
| 99 | + // Register the geocoders. |
| 100 | + wfRunHooks( 'GeocoderFirstCallInit' ); |
| 101 | + |
| 102 | + // Determine if there are any geocoders. |
| 103 | + self::$canGeocode = count( self::$registeredGeocoders ) > 0; |
| 104 | + |
| 105 | + return true; |
70 | 106 | } |
71 | 107 | |
72 | 108 | /** |
Index: trunk/extensions/Maps/includes/api/ApiGeocode.php |
— | — | @@ -0,0 +1,103 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module for geocoding. |
| 6 | + * |
| 7 | + * @since 1.0.3 |
| 8 | + * |
| 9 | + * @file ApiGeocode.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiGeocode extends ApiBase { |
| 17 | + |
| 18 | + public function __construct( $main, $action ) { |
| 19 | + parent::__construct( $main, $action ); |
| 20 | + } |
| 21 | + |
| 22 | + public function execute() { |
| 23 | + global $wgUser; |
| 24 | + |
| 25 | + if ( !$wgUser->isAllowed( 'geocode' ) || $wgUser->isBlocked() ) { |
| 26 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 27 | + } |
| 28 | + |
| 29 | + $params = $this->extractRequestParams(); |
| 30 | + |
| 31 | + $results = array(); |
| 32 | + |
| 33 | + foreach ( array_unique( $params['locations'] ) as $location ) { |
| 34 | + $result = MapsGeocoders::geocode( $location, $params['service'] ); |
| 35 | + |
| 36 | + $results[$location] = array( |
| 37 | + 'count' => $result === false ? 0 : 1, |
| 38 | + 'locations' => array() |
| 39 | + ); |
| 40 | + |
| 41 | + if ( $result !== false ) { |
| 42 | + $results[$location]['locations'][] = $result; |
| 43 | + } |
| 44 | + |
| 45 | + $this->getResult()->setIndexedTagName( $results[$location]['locations'], 'location' ); |
| 46 | + } |
| 47 | + |
| 48 | + $this->getResult()->addValue( |
| 49 | + null, |
| 50 | + 'results', |
| 51 | + $results |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + public function getAllowedParams() { |
| 56 | + return array( |
| 57 | + 'locations' => array( |
| 58 | + ApiBase::PARAM_TYPE => 'string', |
| 59 | + ApiBase::PARAM_REQUIRED => true, |
| 60 | + ApiBase::PARAM_ISMULTI => true, |
| 61 | + ), |
| 62 | + 'service' => array( |
| 63 | + ApiBase::PARAM_TYPE => MapsGeocoders::getAvailableGeocoders(), |
| 64 | + ), |
| 65 | + 'props' => array( |
| 66 | + ApiBase::PARAM_ISMULTI => true, |
| 67 | + ApiBase::PARAM_TYPE => array( 'lat', 'lon', 'alt' ), |
| 68 | + ApiBase::PARAM_DFLT => 'lat|lon', |
| 69 | + ), |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + public function getParamDescription() { |
| 74 | + return array( |
| 75 | + 'locations' => 'The locations to geocode', |
| 76 | + 'service' => 'The geocoding service to use', |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + public function getDescription() { |
| 81 | + return array( |
| 82 | + 'API module for geocoding.' |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + public function getPossibleErrors() { |
| 87 | + return array_merge( parent::getPossibleErrors(), array( |
| 88 | + array( 'missingparam', 'locations' ), |
| 89 | + ) ); |
| 90 | + } |
| 91 | + |
| 92 | + protected function getExamples() { |
| 93 | + return array( |
| 94 | + 'api.php?action=geocode&locations=new york', |
| 95 | + 'api.php?action=geocode&locations=new york|brussels|london', |
| 96 | + 'api.php?action=geocode&locations=new york&service=geonames', |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + public function getVersion() { |
| 101 | + return __CLASS__ . ': $Id$'; |
| 102 | + } |
| 103 | + |
| 104 | +} |
Property changes on: trunk/extensions/Maps/includes/api/ApiGeocode.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 105 | + Id |
Added: svn:eol-style |
2 | 106 | + native |
Index: trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php |
— | — | @@ -59,8 +59,8 @@ |
60 | 60 | if ( !$lon || !$lat ) return false; |
61 | 61 | |
62 | 62 | return array( |
63 | | - 'lat' => $lat, |
64 | | - 'lon' => $lon |
| 63 | + 'lat' => (float)$lat, |
| 64 | + 'lon' => (float)$lon |
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
Index: trunk/extensions/Maps/includes/geocoders/Maps_GeonamesGeocoder.php |
— | — | @@ -62,8 +62,8 @@ |
63 | 63 | if ( !$lon || !$lat ) return false; |
64 | 64 | |
65 | 65 | return array( |
66 | | - 'lat' => $lat, |
67 | | - 'lon' => $lon |
| 66 | + 'lat' => (float)$lat, |
| 67 | + 'lon' => (float)$lon |
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
Index: trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php |
— | — | @@ -58,8 +58,8 @@ |
59 | 59 | if ( !$lon || !$lat ) return false; |
60 | 60 | |
61 | 61 | return array( |
62 | | - 'lat' => $lat, |
63 | | - 'lon' => $lon |
| 62 | + 'lat' => (float)$lat, |
| 63 | + 'lon' => (float)$lon |
64 | 64 | ); |
65 | 65 | } |
66 | 66 | |