r64503 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64502‎ | r64503 | r64504 >
Date:21:21, 1 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Rewrote #geocode parser function to support named parameters, and coordinate notation specification.
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * This file contains registration
 5+ * This file contains the registration functions for the following parser functions:
66 *
77 * {{#geocode:<Address>|<param1>=<value1>|<param2>=<value2>}}
88 * {{#geocodelat:<Address>|<param1>=<value1>|<param2>=<value2>}}
@@ -67,9 +67,95 @@
6868 *
6969 * @return string
7070 */
71 - public static function renderGeocoder( Parser $parser, $coordsOrAddress, $service = '', $mappingService = '' ) {
72 - if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::attemptToGeocodeToString( $coordsOrAddress, $service, $mappingService );
73 - return $geovalues ? $geovalues : '';
 71+ public static function renderGeocoder( Parser $parser ) {
 72+ global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsAvailableCoordNotations;
 73+ global $egMapsDefaultServices, $egMapsDefaultGeoService, $egMapsCoordinateNotation;
 74+ global $egMapsAllowCoordsGeocoding, $egMapsCoordinateDirectional;
 75+
 76+ $args = func_get_args();
 77+
 78+ // We already know the $parser.
 79+ array_shift( $args );
 80+
 81+ // For backward compatibility with pre 0.6.
 82+ $defaultParams = array( 'location', 'service', 'mappingservice' );
 83+ $parameters = array();
 84+
 85+ // Determine all parameter names and value, and take care of default (nameless)
 86+ // parameters, by turning them into named ones.
 87+ foreach( $args as $arg ) {
 88+ $parts = explode( '=', $arg );
 89+ if ( count( $parts ) == 1 ) {
 90+ if ( count( $defaultParams ) > 0 ) {
 91+ $defaultParam = array_shift( $defaultParams );
 92+ $parameters[$defaultParam] = $parts[0];
 93+ }
 94+ } else {
 95+ $name = array_shift( $parts );
 96+ $parameters[$name] = implode( $parts );
 97+ }
 98+ }
 99+
 100+ $parameterInfo = array(
 101+ 'location' => array(
 102+ 'required' => true
 103+ ),
 104+ 'mappingservice' => array(
 105+ 'criteria' => array(
 106+ 'in_array' => $egMapsAvailableServices
 107+ ),
 108+ 'default' => $egMapsDefaultServices['pf']
 109+ ),
 110+ 'service' => array(
 111+ 'criteria' => array(
 112+ 'in_array' => array_keys( $egMapsAvailableGeoServices )
 113+ ),
 114+ 'default' => $egMapsDefaultGeoService
 115+ ),
 116+ 'notation' => array(
 117+ 'criteria' => array(
 118+ 'in_array' => $egMapsAvailableCoordNotations
 119+ ),
 120+ 'default' => $egMapsCoordinateNotation
 121+ ),
 122+ 'allowcoordinates' => array(
 123+ 'type' => 'boolean',
 124+ 'default' => $egMapsAllowCoordsGeocoding
 125+ ),
 126+ 'directional' => array(
 127+ 'type' => 'boolean',
 128+ 'default' => $egMapsCoordinateDirectional
 129+ ),
 130+ );
 131+
 132+ $manager = new ValidatorManager();
 133+
 134+ $parameters = $manager->manageMapparameters( $parameters, $parameterInfo );
 135+
 136+ $doGeocoding = $parameters !== false;
 137+
 138+ if ( $doGeocoding ) {
 139+ if ( self::geocoderIsAvailable() ) {
 140+ $geovalues = MapsGeocoder::attemptToGeocodeToString(
 141+ $parameters['location'],
 142+ $parameters['service'],
 143+ $parameters['mappingservice'],
 144+ $parameters['allowcoordinates'],
 145+ $parameters['notation'],
 146+ $parameters['directional']
 147+ );
 148+ return ( $geovalues ? $geovalues : '' ) . $manager->getErrorList();
 149+ }
 150+ else {
 151+ return htmlspecialchars( wfMsg( 'maps-geocoder-not-available' ) );
 152+ }
 153+ } else {
 154+ return $manager->getErrorList();
 155+ }
 156+
 157+ //$egMapsAvailableCoordNotations
 158+
 159+ ;
74160 }
75161
76162 /**
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -52,19 +52,19 @@
5353 'service' => array(
5454 'criteria' => array(
5555 'in_array' => $egMapsAvailableServices
56 - ),
 56+ ),
5757 'default' => $egMapsDefaultServices['pf']
58 - ),
 58+ ),
5959 'coordinates' => array(
6060 'aliases' => array( 'coords', 'location', 'locations' ),
61 - ),
 61+ ),
6262 'geoservice' => array(
6363 'criteria' => array(
6464 'in_array' => array_keys( $egMapsAvailableGeoServices )
65 - ),
 65+ ),
6666 'default' => $egMapsDefaultGeoService
67 - ),
68 - );
 67+ ),
 68+ );
6969 }
7070
7171 /**
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -40,6 +40,9 @@
4141 $1',
4242 'maps_map_cannot_be_displayed' => 'The map cannot be displayed.',
4343
 44+ // Geocoding
 45+ 'maps-geocoder-not-available' => 'The geocoding feature is of Maps is not available, your location can not be geocoded.',
 46+
4447 // Mapping services
4548 'maps_googlemaps2' => 'Google Maps v2',
4649 'maps_googlemaps3' => 'Google Maps v3',
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -118,11 +118,12 @@
119119
120120 # Enum. The default output format of coordinates.
121121 # Possible values: Maps_COORDS_FLOAT, Maps_COORDS_DMS, Maps_COORDS_DM, Maps_COORDS_DD
122 -$egMapsCoordinateNotation = Maps_COORDS_FLOAT;
 122+$egMapsCoordinateNotation = Maps_COORDS_DMS;
123123
124124 # Boolean. Indicates if coordinates should be outputted in directional notation by default.
125125 $egMapsCoordinateDirectional = false;
126126
 127+$egMapsAllowCoordsGeocoding = true;
127128
128129
129130

Status & tagging log