http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65307
Revision: 65307
Author: jeroendedauw
Date: 2010-04-20 12:37:25 +0000 (Tue, 20 Apr 2010)
Log Message:
-----------
Follow up to r65108 - Fixed coordinate handling for display_map and
display_point(s)
Modified Paths:
--------------
trunk/extensions/Maps/Geocoders/Maps_Geocoder.php
trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
trunk/extensions/Maps/Maps.php
trunk/extensions/Maps/Maps_MapFeature.php
trunk/extensions/Maps/Maps_Mapper.php
trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
Modified: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php
===================================================================
--- trunk/extensions/Maps/Geocoders/Maps_Geocoder.php 2010-04-20 11:52:06 UTC
(rev 65306)
+++ trunk/extensions/Maps/Geocoders/Maps_Geocoder.php 2010-04-20 12:37:25 UTC
(rev 65307)
@@ -50,6 +50,16 @@
}
/**
+ *
+ * @param string $coordsOrAddress
+ *
+ * @return boolean
+ */
+ public static function isLocation( $coordsOrAddress ) {
+ return self::attemptToGeocode( $coordsOrAddress ) !== false;
+ }
+
+ /**
* Geocodes an address with the provided geocoding service and returns
the result
* as a string with the optionally provided format, or false when the
geocoding failed.
*
Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
===================================================================
--- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php 2010-04-20
11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php 2010-04-20
12:37:25 UTC (rev 65307)
@@ -68,62 +68,62 @@
$egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range']
= array( 0, 20 );
$egMapsServices[self::SERVICE_NAME]['parameters'] = array(
- 'controls' => array(
- 'type' => array( 'string', 'list' ),
- 'criteria' => array(
- 'in_array' =>
self::getControlNames()
- ),
- 'default' => $egMapsGMapControls,
- 'output-type' => array( 'list', ',',
'\'' )
- ),
- 'type' => array(
- 'aliases' => array( 'map-type', 'map
type' ),
- 'criteria' => array(
- 'in_array' => $allowedTypes
- ),
- 'default' => $egMapsGoogleMapsType, //
FIXME: default value should not be used when not present in types parameter.
- 'output-type' => 'gmaptype'
- ),
- 'types' => array(
- 'type' => array( 'string', 'list' ),
- 'aliases' => array( 'map-types', 'map
types' ),
- 'criteria' => array(
- 'in_array' => $allowedTypes
- ),
- 'default' => $egMapsGoogleMapsTypes,
- 'output-types' => array( 'gmaptypes',
'list' )
- ),
- 'autozoom' => array(
- 'type' => 'boolean',
- 'aliases' => array( 'auto zoom', 'mouse
zoom', 'mousezoom' ),
- 'default' => $egMapsGoogleAutozoom,
- 'output-type' => 'boolstr'
- ),
- );
+ 'controls' => array(
+ 'type' => array( 'string', 'list' ),
+ 'criteria' => array(
+ 'in_array' => self::getControlNames()
+ ),
+ 'default' => $egMapsGMapControls,
+ 'output-type' => array( 'list', ',', '\'' )
+ ),
+ 'type' => array(
+ 'aliases' => array( 'map-type', 'map type' ),
+ 'criteria' => array(
+ 'in_array' => $allowedTypes
+ ),
+ 'default' => $egMapsGoogleMapsType, // FIXME:
default value should not be used when not present in types parameter.
+ 'output-type' => 'gmaptype'
+ ),
+ 'types' => array(
+ 'type' => array( 'string', 'list' ),
+ 'aliases' => array( 'map-types', 'map types' ),
+ 'criteria' => array(
+ 'in_array' => $allowedTypes
+ ),
+ 'default' => $egMapsGoogleMapsTypes,
+ 'output-types' => array( 'gmaptypes', 'list' )
+ ),
+ 'autozoom' => array(
+ 'type' => 'boolean',
+ 'aliases' => array( 'auto zoom', 'mouse zoom',
'mousezoom' ),
+ 'default' => $egMapsGoogleAutozoom,
+ 'output-type' => 'boolstr'
+ ),
+ );
}
//
http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
private static $mapTypes = array(
- 'normal' => 'G_NORMAL_MAP',
- 'satellite' => 'G_SATELLITE_MAP',
- 'hybrid' => 'G_HYBRID_MAP',
- 'terrain' => 'G_PHYSICAL_MAP',
- 'physical' => 'G_PHYSICAL_MAP',
- 'earth' => 'G_SATELLITE_3D_MAP',
- 'sky' => 'G_SKY_VISIBLE_MAP',
- 'moon' => 'G_MOON_VISIBLE_MAP',
- 'moon-elevation' =>
'G_MOON_ELEVATION_MAP',
- 'mars' => 'G_MARS_VISIBLE_MAP',
- 'mars-elevation' =>
'G_MARS_ELEVATION_MAP',
- 'mars-infrared' => 'G_MARS_INFRARED_MAP'
- );
+ 'normal' => 'G_NORMAL_MAP',
+ 'satellite' => 'G_SATELLITE_MAP',
+ 'hybrid' => 'G_HYBRID_MAP',
+ 'terrain' => 'G_PHYSICAL_MAP',
+ 'physical' => 'G_PHYSICAL_MAP',
+ 'earth' => 'G_SATELLITE_3D_MAP',
+ 'sky' => 'G_SKY_VISIBLE_MAP',
+ 'moon' => 'G_MOON_VISIBLE_MAP',
+ 'moon-elevation' => 'G_MOON_ELEVATION_MAP',
+ 'mars' => 'G_MARS_VISIBLE_MAP',
+ 'mars-elevation' => 'G_MARS_ELEVATION_MAP',
+ 'mars-infrared' => 'G_MARS_INFRARED_MAP'
+ );
private static $overlayData = array(
- 'photos' => '0',
- 'videos' => '1',
- 'wikipedia' => '2',
- 'webcams' => '3'
- );
+ 'photos' => '0',
+ 'videos' => '1',
+ 'wikipedia' => '2',
+ 'webcams' => '3'
+ );
/**
* Returns the names of all supported map types.
@@ -145,7 +145,7 @@
return array(
'auto', 'large', 'small', 'large-original',
'small-original', 'zoom', 'type', 'type-menu',
'overlays', 'overview', 'overview-map', 'scale',
'nav-label', 'nav'
- );
+ );
}
/**
@@ -319,6 +319,8 @@
* Add CSS for the overlays.
*
* @param $output
+ *
+ * TODO
*/
private static function addOverlayCss( &$output ) {
$css = <<<END
Modified: trunk/extensions/Maps/Maps.php
===================================================================
--- trunk/extensions/Maps/Maps.php 2010-04-20 11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/Maps.php 2010-04-20 12:37:25 UTC (rev 65307)
@@ -33,7 +33,7 @@
echo '<b>Warning:</b> You need to have <a
href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a>
installed in order to use <a
href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
}
else {
- define( 'Maps_VERSION', '0.6 a14' );
+ define( 'Maps_VERSION', '0.6 a15' );
// The different coordinate notations.
define( 'Maps_COORDS_FLOAT', 'float' );
@@ -119,7 +119,7 @@
'description' => wfMsgExt( 'maps_desc', 'parsemag',
$services_list ),
);
- MapsMapper::initializeMainParams();
+ MapsMapper::initialize();
$egMapsJsExt = $egMapsUseMinJs ? '.min.js' : '.js';
Modified: trunk/extensions/Maps/Maps_MapFeature.php
===================================================================
--- trunk/extensions/Maps/Maps_MapFeature.php 2010-04-20 11:52:06 UTC (rev
65306)
+++ trunk/extensions/Maps/Maps_MapFeature.php 2010-04-20 12:37:25 UTC (rev
65307)
@@ -89,16 +89,9 @@
* @return array
*/
public function getFeatureParameters() {
- global $egMapsAvailableServices, $egMapsAvailableGeoServices,
$egMapsDefaultGeoService;
+ global $egMapsAvailableServices, $egMapsAvailableGeoServices,
$egMapsDefaultGeoService, $egMapsMapWidth, $egMapsMapHeight;
- return array(
- 'coordinates' => array(
- 'aliases' => array( 'coords', 'location',
'locations' ),
- 'criteria' => array(
- 'is_location' => array()
- ),
- 'output-type' => 'format_coordinates',
- ),
+ return array(
'service' => array(
'criteria' => array(
'in_array' => $egMapsAvailableServices
@@ -110,6 +103,26 @@
),
'default' => $egMapsDefaultGeoService
),
+ 'zoom' => array(
+ 'type' => 'integer',
+ 'criteria' => array(
+ 'not_empty' => array()
+ )
+ ),
+ 'width' => array(
+ 'criteria' => array(
+ 'is_map_dimension' => array( 'width' ),
+ ),
+ 'default' => $egMapsMapWidth,
+ 'output-type' => array( 'mapdimension',
'width', $egMapsMapWidth )
+ ),
+ 'height' => array(
+ 'criteria' => array(
+ 'is_map_dimension' => array( 'height' ),
+ ),
+ 'default' => $egMapsMapHeight,
+ 'output-type' => array( 'mapdimension',
'height', $egMapsMapHeight )
+ ),
);
}
}
\ No newline at end of file
Modified: trunk/extensions/Maps/Maps_Mapper.php
===================================================================
--- trunk/extensions/Maps/Maps_Mapper.php 2010-04-20 11:52:06 UTC (rev
65306)
+++ trunk/extensions/Maps/Maps_Mapper.php 2010-04-20 12:37:25 UTC (rev
65307)
@@ -14,62 +14,52 @@
}
final class MapsMapper {
-
- private static $mainParams;
- public static function initializeMainParams() {
+ public static function initialize() {
global $egMapsSizeRestrictions, $egMapsMapWidth,
$egMapsMapHeight;
- Validator::addOutputFormat( 'mapdimension', array( __CLASS__,
'setMapDimension' ) );
Validator::addValidationFunction( 'is_map_dimension', array(
__CLASS__, 'isMapDimension' ) );
+ Validator::addValidationFunction( 'is_location', array(
__CLASS__, 'isLocation' ) );
+ Validator::addValidationFunction( 'are_locations', array(
__CLASS__, 'areLocations' ) );
- // Take care of maybe not having the geocoder available here.
- // This is done by hooking a MapsGeocoder function that can
handle addresses and coordinates,
- // or one of MapsCoordinateParser, which only accepts
coordinates.
+ Validator::addOutputFormat( 'mapdimension', array( __CLASS__,
'setMapDimension' ) );
+ Validator::addOutputFormat( 'coordinateSet', array( __CLASS__,
'formatLocation' ) );
+ Validator::addOutputFormat( 'coordinateSets', array( __CLASS__,
'formatLocations' ) );
+ }
+
+ public static function isLocation( $location ) {
if ( self::geocoderIsAvailable() ) {
- $locationValidationFunction = array( 'MapsGeocoder',
'attemptToGeocodeToString' );
- $locationFormattingFunction = array( __CLASS__,
'attemptToGeocodeToString' );
+ return MapsGeocoder::isLocation( $location );
} else {
- $locationValidationFunction = array(
'MapsCoordinateParser', 'areCoordinates' );
- $locationFormattingFunction = array( __CLASS__,
'parseAndFormat' );
+ return MapsCoordinateParser::areCoordinates( $location
);
}
-
- Validator::addValidationFunction( 'is_location',
$locationValidationFunction );
- Validator::addOutputFormat( 'format_coordinates',
$locationFormattingFunction );
-
- self::$mainParams = array(
- 'zoom' => array(
- 'type' => 'integer',
- 'criteria' => array(
- 'not_empty' => array()
- )
- ),
- 'width' => array(
- 'criteria' => array(
- 'is_map_dimension' => array( 'width' ),
- ),
- 'default' => $egMapsMapWidth,
- 'output-type' => array( 'mapdimension',
'width', $egMapsMapWidth )
- ),
- 'height' => array(
- 'criteria' => array(
- 'is_map_dimension' => array( 'height' ),
- ),
- 'default' => $egMapsMapHeight,
- 'output-type' => array( 'mapdimension',
'height', $egMapsMapHeight )
- ),
- );
}
- /**
- * Returns the main parameters array.
- *
- * @return array
- */
- public static function getMainParams() {
- return self::$mainParams;
- }
+ public static function areLocations( $locations ) {
+ $locations = (array)$locations;
+ foreach( $locations as $location ) {
+ if ( !self::isLocation( $location ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+ public static function formatLocation( &$location ) {
+ if ( self::geocoderIsAvailable() ) {
+ $location = MapsGeocoder::attemptToGeocodeToString(
$location );
+ } else {
+ $location = MapsCoordinateParser::parseAndFormat(
$location );
+ }
+ }
+
+ public static function formatLocations( &$locations ) {
+ $locations = (array)$locations;
+ foreach( $locations as &$location ) {
+ self::formatLocation( $location );
+ }
+ }
+
/**
* Returns a valid service. When an invalid service is provided, the
default one will be returned.
* Aliases are also chancged into the main service names @see
MapsMapper::getMainServiceName().
@@ -212,13 +202,5 @@
global $wgAutoloadClasses;
return array_key_exists( 'MapsGeocoder', $wgAutoloadClasses );
}
-
- public static function attemptToGeocodeToString( &$value ) {
- $value = MapsGeocoder::attemptToGeocodeToString( $value );
- }
- public static function parseAndFormat( &$value ) {
- $value = MapsCoordinateParser::parseAndFormat( $value );
- }
-
}
Modified: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
===================================================================
--- trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
2010-04-20 11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
2010-04-20 12:37:25 UTC (rev 65307)
@@ -35,7 +35,15 @@
array(
'service' => array(
'default' =>
$egMapsDefaultServices['display_map']
- )
+ ),
+ 'coordinates' => array(
+ 'required' => true,
+ 'aliases' => array( 'coords',
'location', 'locations' ),
+ 'criteria' => array(
+ 'is_location' => array()
+ ),
+ 'output-type' => 'coordinateSet',
+ ),
)
);
}
Modified:
trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
===================================================================
--- trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
2010-04-20 11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
2010-04-20 12:37:25 UTC (rev 65307)
@@ -53,6 +53,15 @@
'not_empty' => array()
)
),
+ 'coordinates' => array(
+ 'required' => true,
+ 'type' => array( 'string', 'list', ';'
),
+ 'aliases' => array( 'coords',
'location', 'locations' ),
+ 'criteria' => array(
+ 'are_locations' => array()
+ ),
+ 'output-type' => 'coordinateSets',
+ ),
)
);
}
@@ -113,8 +122,6 @@
* @param unknown_type $parser
*/
private function setMarkerData( $parser ) {
- $this->coordinates = explode( ';', $this->coordinates );
-
$this->title = Xml::escapeJsString( $parser->recursiveTagParse(
$this->title ) );
$this->label = Xml::escapeJsString( $parser->recursiveTagParse(
$this->label ) );
Modified:
trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
===================================================================
--- trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
2010-04-20 11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
2010-04-20 12:37:25 UTC (rev 65307)
@@ -132,8 +132,6 @@
* See http://mapping.referata.com/wiki/Finddestination
*
* @param Parser $parser
- *
- * FIXME: something here is going wrong - need to debug
*/
public static function renderFindDestination( Parser &$parser ) {
global $egMapsAvailableServices, $egMapsAvailableGeoServices,
$egMapsDefaultGeoService, $egMapsAvailableCoordNotations;
@@ -280,6 +278,8 @@
* @param float $distance The distance to travel in km.
*
* @return array The desitination coordinates, as non-directional
floats in an array with lat and lon keys.
+ *
+ * FIXME: something here is going wrong - need to debug
*/
public static function findDestination( array $startingCoordinates,
$bearing, $distance ) {
$startingCoordinates['lat'] =
(float)$startingCoordinates['lat'];
Modified: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
===================================================================
--- trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
2010-04-20 11:52:06 UTC (rev 65306)
+++ trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
2010-04-20 12:37:25 UTC (rev 65307)
@@ -79,8 +79,6 @@
$service = MapsMapper::getValidService( $setService ? $service
: '', $parserFunction );
- // TODO: hook into Validator for main parameter validation,
geocoding and coordinate parsing
-
$mapClass = new
$egMapsServices[$service]['features'][$parserFunction]();
$manager = new ValidatorManager();
@@ -92,8 +90,7 @@
* again overidden by the service parameters (the ones spesific
to the service),
* and finally by the spesific parameters (the ones spesific to
a service-feature combination).
*/
- $parameterInfo = array_merge( MapsMapper::getMainParams(),
self::$parameters );
- $parameterInfo = array_merge( $parameterInfo,
$mapClass->getFeatureParameters() );
+ $parameterInfo = array_merge( self::$parameters,
$mapClass->getFeatureParameters() );
$parameterInfo = array_merge( $parameterInfo,
$egMapsServices[$service]['parameters'] );
$parameterInfo = array_merge( $parameterInfo,
$mapClass->getSpecificParameterInfo() );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs