r95376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95375‎ | r95376 | r95377 >
Date:06:29, 24 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added API module for geocoding
Modified paths:
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Geocoders.php (modified) (history)
  • /trunk/extensions/Maps/includes/api (added) (history)
  • /trunk/extensions/Maps/includes/api/ApiGeocode.php (added) (history)
  • /trunk/extensions/Maps/includes/geocoders/Maps_GeonamesGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.php
@@ -83,8 +83,9 @@
8484 $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
8585 $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
8686 $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php';
87 -//$wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php';
8887
 88+$wgAutoloadClasses['ApiGeocode'] = $incDir . 'api/ApiGeocode.php';
 89+
8990 // Autoload the "includes/criteria/" classes.
9091 $criDir = $incDir . 'criteria/';
9192 $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php';
@@ -136,7 +137,9 @@
137138 $wgAutoloadClasses['MapsMapsDoc'] = $phDir . 'Maps_MapsDoc.php';
138139 unset( $phDir );
139140 unset( $incDir );
140 -
 141+
 142+$wgAPIModules['geocode'] = 'ApiGeocode';
 143+
141144 $wgExtensionMessagesFiles['MapsMagic'] = $egMapsDir . 'Maps.i18n.magic.php';
142145
143146 $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
@@ -269,6 +272,15 @@
270273 'dependencies' => 'jquery.ui.resizable'
271274 );
272275
 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+
273285 $egMapsGlobalJSVars = array();
274286
275287
Index: trunk/extensions/Maps/RELEASE-NOTES
@@ -7,11 +7,17 @@
88 http://mapping.referata.com/wiki/Maps/Version_history#Maps_change_log
99
1010
 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+
1118 === Maps 1.0.2 ===
1219 (2011-08-24)
1320
1421 * 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.
1622 * Fixed internationalization of distances (bug 30467).
1723
1824 === Maps 1.0.1 ===
Index: trunk/extensions/Maps/includes/Maps_Geocoders.php
@@ -47,6 +47,14 @@
4848 private static $globalGeocoderCache = array();
4949
5050 /**
 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+ /**
5159 * Returns if this class can do geocoding operations.
5260 * Ie. if there are any geocoders available.
5361 *
@@ -55,17 +63,45 @@
5664 * @return boolean
5765 */
5866 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;
6092
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;
6795 }
6896
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;
70106 }
71107
72108 /**
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
1105 + Id
Added: svn:eol-style
2106 + native
Index: trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php
@@ -59,8 +59,8 @@
6060 if ( !$lon || !$lat ) return false;
6161
6262 return array(
63 - 'lat' => $lat,
64 - 'lon' => $lon
 63+ 'lat' => (float)$lat,
 64+ 'lon' => (float)$lon
6565 );
6666 }
6767
Index: trunk/extensions/Maps/includes/geocoders/Maps_GeonamesGeocoder.php
@@ -62,8 +62,8 @@
6363 if ( !$lon || !$lat ) return false;
6464
6565 return array(
66 - 'lat' => $lat,
67 - 'lon' => $lon
 66+ 'lat' => (float)$lat,
 67+ 'lon' => (float)$lon
6868 );
6969 }
7070
Index: trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php
@@ -58,8 +58,8 @@
5959 if ( !$lon || !$lat ) return false;
6060
6161 return array(
62 - 'lat' => $lat,
63 - 'lon' => $lon
 62+ 'lat' => (float)$lat,
 63+ 'lon' => (float)$lon
6464 );
6565 }
6666

Follow-up revisions

RevisionCommit summaryAuthorDate
r95383fu r95376jeroendedauw07:02, 24 August 2011