r64422 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64421‎ | r64422 | r64423 >
Date:05:18, 31 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - Mayor rewrite of how services and features are hooked.
Modified paths:
  • /trunk/extensions/Maps/Geocoders/Maps_Geocoder.php (modified) (history)
  • /trunk/extensions/Maps/Geocoders/Maps_Geocoders.php (modified) (history)
  • /trunk/extensions/Maps/Geocoders/Maps_GeonamesGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/Geocoders/Maps_GoogleGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/Geocoders/Maps_YahooGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3.php
@@ -20,17 +20,10 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['googlemaps3'] = array(
25 - 'pf' => array(
26 - // 'display_point' => array('class' => 'MapsGoogleMaps3DispPoint', 'file' => 'GoogleMaps3/Maps_GoogleMaps3DispPoint.php', 'local' => true),
27 - 'display_map' => array( 'class' => 'MapsGoogleMaps3DispMap', 'file' => 'GoogleMaps3/Maps_GoogleMaps3DispMap.php', 'local' => true ),
28 - ),
29 - 'classes' => array(
30 - array( 'class' => 'MapsGoogleMaps3', 'file' => 'GoogleMaps3/Maps_GoogleMaps3.php', 'local' => true )
31 - ),
32 - 'aliases' => array( 'google3', 'googlemap3', 'gmap3', 'gmaps3' ),
33 - );
 24+$wgAutoloadClasses['MapsGoogleMaps3'] = dirname( __FILE__ ) . '/Maps_GoogleMaps3.php';
3425
 26+$wgHooks['MappingServiceLoad'][] = 'MapsGoogleMaps3::initialize';
 27+
3528 /**
3629 * Class for Google Maps v3 initialization.
3730 *
@@ -43,9 +36,23 @@
4437 const SERVICE_NAME = 'googlemaps3';
4538
4639 public static function initialize() {
 40+ global $wgAutoloadClasses, $egMapsServices;
 41+
 42+ $wgAutoloadClasses['MapsGoogleMaps3DispMap'] = dirname( __FILE__ ) . '/Maps_GoogleMaps3DispMap.php';
 43+
 44+ $egMapsServices[self::SERVICE_NAME] = array(
 45+ 'aliases' => array( 'google3', 'googlemap3', 'gmap3', 'gmaps3' ),
 46+ 'features' => array(
 47+ 'display_map' => 'MapsGoogleMaps3DispMap',
 48+ )
 49+ );
 50+
4751 self::initializeParams();
 52+
4853 Validator::addOutputFormat( 'gmap3type', array( 'MapsGoogleMaps3', 'setGMapType' ) );
4954 Validator::addOutputFormat( 'gmap3types', array( 'MapsGoogleMaps3', 'setGMapTypes' ) );
 55+
 56+ return true;
5057 }
5158
5259 private static function initializeParams() {
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php
@@ -20,16 +20,10 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['openlayers'] = array(
25 - 'pf' => array(
26 - 'display_point' => array( 'class' => 'MapsOpenLayersDispPoint', 'file' => 'OpenLayers/Maps_OpenLayersDispPoint.php', 'local' => true ),
27 - 'display_map' => array( 'class' => 'MapsOpenLayersDispMap', 'file' => 'OpenLayers/Maps_OpenLayersDispMap.php', 'local' => true ),
28 - ),
29 - 'classes' => array(
30 - array( 'class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true )
31 - ),
32 - 'aliases' => array( 'layers', 'openlayer' ),
33 - );
 24+$wgAutoloadClasses['MapsOpenLayers'] = dirname( __FILE__ ) . '/Maps_OpenLayers.php';
 25+
 26+$wgHooks['MappingServiceLoad'][] = 'MapsOpenLayers::initialize';
 27+
3428 /**
3529 * Class for OpenLayers initialization.
3630 *
@@ -42,11 +36,26 @@
4337 const SERVICE_NAME = 'openlayers';
4438
4539 public static function initialize() {
 40+ global $wgAutoloadClasses, $egMapsServices, $egMapsOLLoadedLayers;
 41+
 42+ $egMapsOLLoadedLayers = array();
 43+
 44+ $wgAutoloadClasses['MapsOpenLayersDispMap'] = dirname( __FILE__ ) . '/Maps_OpenLayersDispMap.php';
 45+ $wgAutoloadClasses['MapsOpenLayersDispPoint'] = dirname( __FILE__ ) . '/Maps_OpenLayersDispPoint.php';
 46+
 47+ $egMapsServices[self::SERVICE_NAME] = array(
 48+ 'aliases' => array( 'layers', 'openlayer' ),
 49+ 'features' => array(
 50+ 'display_point' => 'MapsOpenLayersDispPoint',
 51+ 'display_map' => 'MapsOpenLayersDispMap',
 52+ )
 53+ );
 54+
4655 self::initializeParams();
 56+
4757 Validator::addOutputFormat( 'olgroups', array( __CLASS__, 'unpackLayerGroups' ) );
4858
49 - global $egMapsOLLoadedLayers;
50 - $egMapsOLLoadedLayers = array();
 59+ return true;
5160 }
5261
5362 private static function initializeParams() {
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php
@@ -19,7 +19,7 @@
2020 $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
2121 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
2222
23 -$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayPoint';
 23+$egMapsFeatures['pf'][] = 'MapsDisplayPoint::initialize';
2424
2525 /**
2626 * Adds the magic words for the parser functions.
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -37,7 +37,7 @@
3838 *
3939 * @return html
4040 */
41 - public final function displayMap( &$parser, array $params ) {
 41+ public final function displayMap( Parser &$parser, array $params ) {
4242 $this->setMapSettings();
4343
4444 $this->featureParameters = MapsDisplayPoint::$parameters;
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php
@@ -19,7 +19,7 @@
2020 $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
2121 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
2222
23 -$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayMap';
 23+$egMapsFeatures['pf'][] = 'MapsDisplayMap::initialize';
2424
2525 /**
2626 * Adds the magic words for the parser functions.
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -33,7 +33,7 @@
3434 *
3535 * @return html
3636 */
37 - public final function displayMap( &$parser, array $params ) {
 37+ public final function displayMap( Parser &$parser, array $params ) {
3838 $this->setMapSettings();
3939
4040 $this->featureParameters = MapsDisplayMap::$parameters;
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -22,21 +22,21 @@
2323 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions';
2424
2525 /**
26 - * Adds the magic words for the parser functions
 26+ * Adds the magic words for the parser functions.
2727 */
2828 function efMapsGeoFunctionMagic( &$magicWords, $langCode ) {
2929 $magicWords['geocode'] = array( 0, 'geocode' );
3030 $magicWords['geocodelat'] = array ( 0, 'geocodelat' );
3131 $magicWords['geocodelon'] = array ( 0, 'geocodelon', 'geocodelng' );
3232
33 - return true; // Unless we return true, other parser functions won't get loaded
 33+ return true; // Unless we return true, other parser functions won't get loaded.
3434 }
3535
3636 /**
37 - * Adds the parser function hooks
 37+ * Adds the parser function hooks.
3838 */
3939 function efMapsRegisterGeoFunctions( &$wgParser ) {
40 - // Hooks to enable the geocoding parser functions
 40+ // Hooks to enable the geocoding parser functions.
4141 $wgParser->setFunctionHook( 'geocode', array( 'MapsGeocodeFunctions', 'renderGeocoder' ) );
4242 $wgParser->setFunctionHook( 'geocodelat', array( 'MapsGeocodeFunctions', 'renderGeocoderLat' ) );
4343 $wgParser->setFunctionHook( 'geocodelon', array( 'MapsGeocodeFunctions', 'renderGeocoderLon' ) );
@@ -67,8 +67,8 @@
6868 *
6969 * @return string
7070 */
71 - public static function renderGeocoder( $parser, $coordsOrAddress, $service = '', $mappingService = '' ) {
72 - if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::attemptToGeocode( $coordsOrAddress, $service, $mappingService );
 71+ public static function renderGeocoder( Parser $parser, $coordsOrAddress, $service = '', $mappingService = '' ) {
 72+ if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::attemptToGeocodeToString( $coordsOrAddress, $service, $mappingService );
7373 return $geovalues ? $geovalues : '';
7474 }
7575
@@ -83,7 +83,7 @@
8484 *
8585 * @return string
8686 */
87 - public static function renderGeocoderLat( &$parser, $address, $service = '', $mappingService = '' ) {
 87+ public static function renderGeocoderLat( Parser &$parser, $address, $service = '', $mappingService = '' ) {
8888 if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService );
8989 return $geovalues ? $geovalues['lat'] : '';
9090 }
@@ -99,7 +99,7 @@
100100 *
101101 * @return string
102102 */
103 - public static function renderGeocoderLon( &$parser, $address, $service = '', $mappingService = '' ) {
 103+ public static function renderGeocoderLon( Parser &$parser, $address, $service = '', $mappingService = '' ) {
104104 if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService );
105105 return $geovalues ? $geovalues['lon'] : '';
106106 }
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -13,6 +13,10 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+$wgAutoloadClasses['MapsParserFunctions'] = __FILE__;
 18+
 19+$wgHooks['MappingFeatureLoad'][] = 'MapsParserFunctions::initialize';
 20+
1721 /**
1822 * A class that holds handlers for the mapping parser functions.
1923 *
@@ -27,30 +31,18 @@
2832 * and will load the required classes.
2933 */
3034 public static function initialize() {
31 - global $egMapsDir, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices;
 35+ global $egMapsDir, $IP, $wgAutoloadClasses, $egMapsFeatures, $egMapsServices;
3236
3337 include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php';
3438
3539 self::initializeParams();
3640
37 - foreach ( $egMapsServices as $serviceName => $serviceData ) {
38 - // Check if the service has parser function support
39 - $hasPFs = array_key_exists( 'pf', $serviceData );
40 -
41 - // If the service has no parser function support, skipt it and continue with the next one.
42 - if ( !$hasPFs ) continue;
43 -
44 - // Go through the parser functions supported by the mapping service, and load their classes.
45 - foreach ( $serviceData['pf'] as $parser_name => $parser_data ) {
46 - $file = array_key_exists( 'local', $parser_data ) && $parser_data['local'] ? $egMapsDir . $parser_data['file'] : $IP . '/extensions/' . $parser_data['file'];
47 - $wgAutoloadClasses[$parser_data['class']] = $file;
48 - }
 41+ // This runs a small hook that enables parser functions to run initialization code.
 42+ foreach ( $egMapsFeatures['pf'] as $hook ) {
 43+ call_user_func( $hook );
4944 }
5045
51 - // This runs a small hook that enables parser functions to run initialization code.
52 - foreach ( $egMapsAvailableFeatures['pf']['hooks'] as $hook ) {
53 - if ( method_exists( $hook, 'initialize' ) ) call_user_func( array( $hook, 'initialize' ) );
54 - }
 46+ return true;
5547 }
5648
5749 private static function initializeParams() {
@@ -60,7 +52,7 @@
6153 'service' => array(
6254 'criteria' => array(
6355 'in_array' => $egMapsAvailableServices
64 - ),
 56+ ),
6557 'default' => $egMapsDefaultServices['pf']
6658 ),
6759 'coordinates' => array(
@@ -93,9 +85,9 @@
9486 $coordFails = array();
9587
9688 $paramInfo = array_merge( MapsMapper::getMainParams(), self::$parameters );
 89+
 90+ $geoFails = self::changeAddressesToCoords( $params, $paramInfo, $parserFunction );
9791
98 - $geoFails = self::changeAddressesToCoords( $params, $paramInfo );
99 -
10092 // Go through all parameters, split their names and values, and put them in the $map array.
10193 foreach ( $params as $param ) {
10294 $split = explode( '=', $param );
@@ -107,7 +99,7 @@
108100 if ( self::inParamAliases( $paramName, 'coordinates', $paramInfo ) ) $coordFails = self::filterInvalidCoords( $map[$paramName] );
109101 }
110102 }
111 - else if ( count( $split ) == 1 ) { // Default parameter (without name)
 103+ else if ( count( $split ) == 1 ) { // Default parameter (without name).
112104 $split[0] = trim( $split[0] );
113105 if ( strlen( $split[0] ) > 0 ) $map['coordinates'] = $split[0];
114106 }
@@ -116,13 +108,9 @@
117109 $coords = self::getParamValue( 'coordinates', $map, $paramInfo );
118110
119111 if ( $coords ) {
120 - if ( ! self::paramIsPresent( 'service', $map, $paramInfo ) ) $map['service'] = '';
121 -
122 - $map['service'] = MapsMapper::getValidService( $map['service'], 'pf', $parserFunction );
123 -
124112 $mapClass = self::getParserClassInstance( $map['service'], $parserFunction );
125113
126 - // Call the function according to the map service to get the HTML output
 114+ // Call the function according to the map service to get the HTML output.
127115 $output = $mapClass->displayMap( $parser, $map );
128116
129117 if ( $egValidatorErrorLevel >= Validator_ERRORS_WARN ) {
@@ -185,12 +173,14 @@
186174 * Changes the values of the address or addresses parameter into coordinates
187175 * in the provided array. Returns an array containing the addresses that
188176 * could not be geocoded.
 177+ *
 178+ * Also ensures the service parameter is valid.
189179 *
190180 * @param array $params
191181 *
192182 * @return array
193183 */
194 - private static function changeAddressesToCoords( &$params, array $paramInfo ) {
 184+ private static function changeAddressesToCoords( &$params, array $paramInfo, $parserFunction ) {
195185 global $egMapsDefaultService;
196186
197187 $fails = array();
@@ -207,9 +197,13 @@
208198 }
209199
210200 // Make sure the service and geoservice are valid.
211 - $service = isset( $service ) ? MapsMapper::getValidService( $service, 'pf' ) : $egMapsDefaultService;
 201+ if ( !isset( $service ) ) $service = '';
 202+ $service = MapsMapper::getValidService( $service, $parserFunction );
 203+
212204 if ( ! isset( $geoservice ) ) $geoservice = '';
213205
 206+ $setService = false;
 207+
214208 // Go over all parameters.
215209 for ( $i = 0; $i < count( $params ); $i++ ) {
216210 $split = explode( '=', $params[$i] );
@@ -245,10 +239,16 @@
246240 // Add the geocoded result back to the parameter list.
247241 $params[$i] = implode( ';', $coordinates );
248242
 243+ } else if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) {
 244+ $params[$i] = "service=$service";
 245+ $setService = true;
249246 }
250 -
251247 }
252248
 249+ if ( !$setService ) {
 250+ $params[] = "service=$service";
 251+ }
 252+
253253 return $fails;
254254 }
255255
@@ -263,7 +263,7 @@
264264 */
265265 public static function getParserClassInstance( $service, $parserFunction ) {
266266 global $egMapsServices;
267 - return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
 267+ return new $egMapsServices[$service]['features'][$parserFunction]();
268268 }
269269
270270 /**
Index: trunk/extensions/Maps/Maps.php
@@ -33,7 +33,7 @@
3434 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>.';
3535 }
3636 else {
37 - define( 'Maps_VERSION', '0.6 a7' );
 37+ define( 'Maps_VERSION', '0.6 a8' );
3838
3939 // The different coordinate notations.
4040 define( 'Maps_COORDS_FLOAT', 'float' );
@@ -44,51 +44,54 @@
4545 // The symbols to use for degrees, minutes and seconds.
4646 define( 'Maps_GEO_DEG', '°' );
4747 define( 'Maps_GEO_MIN', "'" );
48 - define( 'Maps_GEO_SEC', '"' );
 48+ define( 'Maps_GEO_SEC', '"' );
4949
5050 $egMapsScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/Maps';
5151 $egMapsDir = dirname( __FILE__ ) . '/';
5252
53 - $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
 53+ $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
5454
5555 // Include the settings file.
5656 require_once( $egMapsDir . 'Maps_Settings.php' );
5757
 58+ $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
 59+
5860 // Register the initialization function of Maps.
5961 $wgExtensionFunctions[] = 'efMapsSetup';
60 -
61 - $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
62 -
 62+
6363 $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
64 -
65 - // Autoload the general classes
66 - $wgAutoloadClasses['MapsCoordinateParser'] = $egMapsDir . 'Maps_CoordinateParser.php';
67 - $wgAutoloadClasses['MapsMapFeature'] = $egMapsDir . 'Maps_MapFeature.php';
68 - $wgAutoloadClasses['MapsMapper'] = $egMapsDir . 'Maps_Mapper.php';
6964 }
7065
7166 /**
7267 * Initialization function for the Maps extension.
7368 */
7469 function efMapsSetup() {
75 - global $wgExtensionCredits, $wgLang, $wgAutoloadClasses, $IP;
76 - global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsDefaultGeoService;
77 - global $egMapsAvailableGeoServices, $egMapsDir, $egMapsAvailableFeatures, $egMapsUseMinJs, $egMapsJsExt;
78 -
 70+ global $wgExtensionCredits, $wgLang, $wgAutoloadClasses, $IP, $wgStyleVersion, $wgScriptPath, $wgJsMimeType, $wgExtensionAssetsPath;
 71+ global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsDefaultGeoService, $egMapsScriptPath;
 72+ global $egMapsAvailableGeoServices, $egMapsDir, $egMapsAvailableFeatures, $egMapsUseMinJs, $egMapsJsExt, $egMapsStyleVersion;
 73+
 74+ $egMapsFeatures = array();
 75+ $egMapsServices = array();
 76+
 77+ // Autoload the general classes
 78+ $wgAutoloadClasses['MapsCoordinateParser'] = $egMapsDir . 'Maps_CoordinateParser.php';
 79+ $wgAutoloadClasses['MapsMapFeature'] = $egMapsDir . 'Maps_MapFeature.php';
 80+ $wgAutoloadClasses['MapsMapper'] = $egMapsDir . 'Maps_Mapper.php';
 81+
 82+ wfLoadExtensionMessages( 'Maps' );
 83+
 84+ wfRunHooks( 'MappingFeatureLoad' );
 85+ wfRunHooks( 'MappingServiceLoad' );
 86+
7987 // Remove all hooked in services that should not be available.
8088 foreach ( $egMapsServices as $service => $data ) {
8189 if ( ! in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] );
8290 }
 91+ $egMapsAvailableServices = array_keys( $egMapsServices );
8392
84 - // Enure that the default service and geoservice are one of the enabled ones.
85 - $egMapsDefaultService = in_array( $egMapsDefaultService, $egMapsAvailableServices ) ? $egMapsDefaultService : $egMapsAvailableServices[0];
86 - if ( !in_array( $egMapsDefaultGeoService, $egMapsAvailableGeoServices ) ) {
87 - reset( $egMapsAvailableGeoServices );
88 - $egMapsDefaultGeoService = key( $egMapsAvailableGeoServices );
89 - }
 93+ // Enure that the default service is one of the enabled ones.
 94+ $egMapsDefaultService = in_array( $egMapsDefaultService, $egMapsAvailableServices ) ? $egMapsDefaultService : $egMapsAvailableServices[0];
9095
91 - wfLoadExtensionMessages( 'Maps' );
92 -
9396 // Creation of a list of internationalized service names.
9497 $services = array();
9598 foreach ( array_keys( $egMapsServices ) as $name ) $services[] = wfMsg( 'maps_' . $name );
@@ -104,42 +107,19 @@
105108 );
106109
107110 MapsMapper::initializeMainParams();
108 -
109 - // wfRunHooks( 'MappingFeatureLoad');
110 - // wfRunHooks( 'MappingServiceLoad');
111111
112 - // Loop through the available mapping features, load and initialize them.
113 - foreach ( $egMapsAvailableFeatures as $key => $values ) {
114 - // Load and optionally initizlize feature.
115 - if ( array_key_exists( 'class', $values ) && array_key_exists( 'file', $values ) ) {
116 - $wgAutoloadClasses[$values['class']] = array_key_exists( 'local', $values ) && $values['local'] ? $egMapsDir . $values['file'] : $IP . '/extensions/' . $values['file'];
117 - if ( method_exists( $values['class'], 'initialize' ) ) call_user_func( array( $values['class'], 'initialize' ) );
118 - }
119 - }
120 -
121 - // Loop through the available mapping services to load and initialize their general classes.
122 - foreach ( $egMapsServices as $serviceData ) {
123 - if ( array_key_exists( 'classes', $serviceData ) ) {
124 - foreach ( $serviceData['classes'] as $class ) {
125 - $file = array_key_exists( 'local', $class ) && $class['local'] ? $egMapsDir . $class['file'] : $IP . '/extensions/' . $class['file'];
126 - $wgAutoloadClasses[$class['class']] = $file;
127 - if ( method_exists( $class['class'], 'initialize' ) ) call_user_func( array( $class['class'], 'initialize' ) );
128 - }
129 - }
130 - }
131 -
132112 $egMapsJsExt = $egMapsUseMinJs ? '.min.js' : '.js';
133113
134114 return true;
135115 }
136116
137117 /**
138 - * Adds a link to Admin Links page
 118+ * Adds a link to Admin Links page.
139119 */
140120 function efMapsAddToAdminLinks( &$admin_links_tree ) {
141121 $displaying_data_section = $admin_links_tree->getSection( wfMsg( 'smw_adminlinks_displayingdata' ) );
142122
143 - // Escape if SMW hasn't added links
 123+ // Escape if SMW hasn't added links.
144124 if ( is_null( $displaying_data_section ) ) return true;
145125 $smw_docu_row = $displaying_data_section->getRow( 'smw' );
146126
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -72,33 +72,17 @@
7373 *
7474 * @return string
7575 */
76 - public static function getValidService( $service, $feature, $subfeature = '' ) {
77 - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultServices, $egMapsServices;
 76+ public static function getValidService( $service, $feature ) {
 77+ global $egMapsServices, $egMapsDefaultService, $egMapsDefaultServices, $shouldChange;
7878
7979 // Get rid of any aliases.
8080 $service = self::getMainServiceName( $service );
81 -
8281 // If the service is not loaded into maps, it should be changed.
8382 $shouldChange = ! array_key_exists( $service, $egMapsServices );
8483
85 - // If it should not be changed, ensure the service supports this feature, and when present, sub feature.
86 - // TODO: recursive checking for sub features would definitly be cooler.
 84+ // If it should not be changed, ensure the service supports this feature.
8785 if ( ! $shouldChange ) {
88 - if ( array_key_exists( $feature, $egMapsServices[$service] ) ) {
89 - if ( array_key_exists( 'class', $egMapsServices[$service][$feature] ) ) {
90 - // If the class key is set, the feature does not have sub features, so the service supports the feature.
91 - $shouldChange = false;
92 - }
93 - else
94 - {
95 - // The feature has sub features, so check if the current service has support for it.
96 - $shouldChange = !array_key_exists( $subfeature, $egMapsServices[$service][$feature] );
97 - }
98 - }
99 - else {
100 - // The service does not support this feature.
101 - $shouldChange = true;
102 - }
 86+ $shouldChange = !array_key_exists( $feature, $egMapsServices[$service]['features'] );
10387 }
10488
10589 // Change the service to the most specific default value available.
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -20,17 +20,10 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['googlemaps2'] = array(
25 - 'pf' => array(
26 - 'display_point' => array( 'class' => 'MapsGoogleMapsDispPoint', 'file' => 'GoogleMaps/Maps_GoogleMapsDispPoint.php', 'local' => true ),
27 - 'display_map' => array( 'class' => 'MapsGoogleMapsDispMap', 'file' => 'GoogleMaps/Maps_GoogleMapsDispMap.php', 'local' => true ),
28 - ),
29 - 'classes' => array(
30 - array( 'class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true )
31 - ),
32 - 'aliases' => array( 'googlemaps', 'google', 'googlemap', 'gmap', 'gmaps' ),
33 - );
 24+$wgAutoloadClasses['MapsGoogleMaps'] = dirname( __FILE__ ) . '/Maps_GoogleMaps.php';
3425
 26+$wgHooks['MappingServiceLoad'][] = 'MapsGoogleMaps::initialize';
 27+
3528 /**
3629 * Class for Google Maps initialization.
3730 *
@@ -43,10 +36,27 @@
4437 const SERVICE_NAME = 'googlemaps2';
4538
4639 public static function initialize() {
 40+ global $wgAutoloadClasses, $egMapsServices;
 41+
 42+ $wgAutoloadClasses['MapsGoogleMapsDispMap'] = dirname( __FILE__ ) . '/Maps_GoogleMapsDispMap.php';
 43+ $wgAutoloadClasses['MapsGoogleMapsDispPoint'] = dirname( __FILE__ ) . '/Maps_GoogleMapsDispPoint.php';
 44+
 45+ $egMapsServices[self::SERVICE_NAME] = array(
 46+ 'aliases' => array( 'googlemaps', 'google', 'googlemap', 'gmap', 'gmaps' ),
 47+ 'features' => array(
 48+ 'display_point' => 'MapsGoogleMapsDispPoint',
 49+ 'display_map' => 'MapsGoogleMapsDispMap',
 50+ )
 51+ );
 52+
4753 self::initializeParams();
 54+
4855 Validator::addOutputFormat( 'gmaptype', array( __CLASS__, 'setGMapType' ) );
4956 Validator::addOutputFormat( 'gmaptypes', array( __CLASS__, 'setGMapTypes' ) );
 57+
5058 Validator::addValidationFunction( 'is_google_overlay', array( __CLASS__, 'isGOverlay' ) );
 59+
 60+ return true;
5161 }
5262
5363 private static function initializeParams() {
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -20,16 +20,9 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['yahoomaps'] = array(
25 - 'pf' => array(
26 - 'display_point' => array( 'class' => 'MapsYahooMapsDispPoint', 'file' => 'YahooMaps/Maps_YahooMapsDispPoint.php', 'local' => true ),
27 - 'display_map' => array( 'class' => 'MapsYahooMapsDispMap', 'file' => 'YahooMaps/Maps_YahooMapsDispMap.php', 'local' => true ),
28 - ),
29 - 'classes' => array(
30 - array( 'class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true )
31 - ),
32 - 'aliases' => array( 'yahoo', 'yahoomap', 'ymap', 'ymaps' ),
33 - );
 24+$wgAutoloadClasses['MapsYahooMaps'] = dirname( __FILE__ ) . '/Maps_YahooMaps.php';
 25+
 26+$wgHooks['MappingServiceLoad'][] = 'MapsYahooMaps::initialize';
3427
3528 /**
3629 * Class for Yahoo! Maps initialization.
@@ -43,9 +36,25 @@
4437 const SERVICE_NAME = 'yahoomaps';
4538
4639 public static function initialize() {
 40+ global $wgAutoloadClasses, $egMapsServices;
 41+
 42+ $wgAutoloadClasses['MapsYahooMapsDispMap'] = dirname( __FILE__ ) . '/Maps_YahooMapsDispMap.php';
 43+ $wgAutoloadClasses['MapsYahooMapsDispPoint'] = dirname( __FILE__ ) . '/Maps_YahooMapsDispPoint.php';
 44+
 45+ $egMapsServices[self::SERVICE_NAME] = array(
 46+ 'aliases' => array( 'yahoo', 'yahoomap', 'ymap', 'ymaps' ),
 47+ 'features' => array(
 48+ 'display_point' => 'MapsYahooMapsDispPoint',
 49+ 'display_map' => 'MapsYahooMapsDispMap',
 50+ )
 51+ );
 52+
4753 self::initializeParams();
 54+
4855 Validator::addOutputFormat( 'ymaptype', array( __CLASS__, 'setYMapType' ) );
4956 Validator::addOutputFormat( 'ymaptypes', array( __CLASS__, 'setYMapTypes' ) );
 57+
 58+ return true;
5059 }
5160
5261 private static function initializeParams() {
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -26,26 +26,27 @@
2727 # (named) Array of String. This array contains the available features for Maps.
2828 # The array element name contains an abbriviation, used for code references,
2929 # and in the service data arrays, the value is the human readible version for displaying purpouses.
30 -if ( empty( $egMapsAvailableFeatures ) ) $egMapsAvailableFeatures = array();
3130
32 -$egMapsAvailableFeatures['geocode'] = array(
33 - 'name' => 'Geocoding',
34 - 'class' => 'Geocoders',
35 - 'file' => 'Geocoders/Maps_Geocoders.php',
36 - 'local' => true,
37 - );
 31+# Initialization of the mapping features array.
3832
39 -$egMapsAvailableFeatures['pf'] = array(
40 - 'name' => 'Parser Functions',
41 - 'class' => 'MapsParserFunctions',
42 - 'file' => 'ParserFunctions/Maps_ParserFunctions.php',
43 - 'local' => true,
44 - );
 33+include_once $egMapsDir . 'Geocoders/Maps_Geocoders.php'; // Geocoders
 34+include_once $egMapsDir . 'ParserFunctions/Maps_ParserFunctions.php'; // Parser functions
4535
4636
4737
4838
 39+# Geocoding services configuration
4940
 41+# Array of String. Array containing all the geocoding services that will be made available to the user.
 42+# Currently Maps provides the following services: geonames, google, yahoo
 43+$egMapsAvailableGeoServices = array('geonames', 'google', 'yahoo');
 44+
 45+# String. The default geocoding service, which will be used when no service is provided by the user.
 46+# This service needs to be enabled, if not, the first one from the available services will be taken.
 47+$egMapsDefaultGeoService = 'geonames';
 48+
 49+
 50+
5051 # Include the parser functions that should be loaded into Maps.
5152 # Commenting or removing a parser functions will cause Maps to completely ignore it, and so improve performance.
5253 include_once $egMapsDir . 'ParserFunctions/DisplayMap/Maps_DisplayMap.php'; // display_map
@@ -55,7 +56,6 @@
5657
5758
5859
59 -
6060 # Mapping services configuration
6161 # Note: You can not use aliases in the settings. Use the main service names.
6262
@@ -72,7 +72,7 @@
7373
7474 # Array of String. Array containing all the mapping services that will be made available to the user.
7575 # Currently Maps provides the following services: googlemaps, yahoomaps, openlayers
76 -$egMapsAvailableServices = array( 'googlemaps2', 'googlemaps3', 'yahoomaps', 'openlayers', 'osm' );
 76+$egMapsAvailableServices = array( 'googlemaps2', 'googlemaps3', 'yahoomaps', 'openlayers' );
7777
7878 # String. The default mapping service, which will be used when no default service is present in the
7979 # $egMapsDefaultServices array for a certain feature. A service that supports all features is recommended.
@@ -93,38 +93,10 @@
9494
9595
9696
97 -# Geocoding services configuration
9897
99 -# Array of String. Array containing all the geocoding services that will be made available to the user.
100 -# Currently Maps provides the following services: googlemaps, yahoomaps, openlayers
101 -$egMapsAvailableGeoServices = array(
102 - 'google' => array(
103 - 'class' => 'MapsGoogleGeocoder',
104 - 'file' => 'Geocoders/Maps_GoogleGeocoder.php',
105 - 'local' => true,
106 - 'overrides' => array( 'googlemaps2' ),
107 - ),
108 - 'yahoo' => array(
109 - 'class' => 'MapsYahooGeocoder',
110 - 'file' => 'Geocoders/Maps_YahooGeocoder.php',
111 - 'local' => true,
112 - 'overrides' => array( 'yahoomaps' ),
113 - ),
114 - 'geonames' => array(
115 - 'class' => 'MapsGeonamesGeocoder',
116 - 'file' => 'Geocoders/Maps_GeonamesGeocoder.php',
117 - 'local' => true,
118 - ),
119 - );
12098
121 -# String. The default geocoding service, which will be used when no service is provided by the user.
122 -# This service needs to be enabled, if not, the first one from the available services will be taken.
123 -$egMapsDefaultGeoService = 'geonames';
12499
125100
126 -
127 -
128 -
129101 # General configuration
130102
131103 # Boolean. Indicates if minified js files should be used where available.
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoders.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * Initialization file for geocoder functionality in the Maps extension
 5+ * Initialization file for geocoder functionality in the Maps extension.
66 *
77 * @file Maps_Geocoders.php
88 * @ingroup Maps
@@ -13,24 +13,52 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+$wgAutoloadClasses['MapsGeocoders'] = __FILE__;
 18+
 19+$wgHooks['MappingFeatureLoad'][] = 'MapsGeocoders::initialize';
 20+
1721 /**
1822 * Initialization class for geocoder functionality in the Maps extension.
1923 *
2024 * @author Jeroen De Dauw
2125 *
2226 */
23 -final class Geocoders {
 27+final class MapsGeocoders {
2428
2529 /**
2630 * Initialization function for Maps geocoder functionality.
2731 */
2832 public static function initialize() {
29 - global $wgAutoloadClasses, $egMapsDir, $egMapsGeoServices;
 33+ global $wgAutoloadClasses, $egMapsDir, $egMapsGeoServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsGeoOverrides;
3034
3135 $egMapsGeoServices = array();
 36+ $egMapsGeoOverrides = array();
3237
33 - $wgAutoloadClasses['MapsBaseGeocoder'] = $egMapsDir . 'Geocoders/Maps_BaseGeocoder.php';
34 - $wgAutoloadClasses['MapsGeocoder'] = $egMapsDir . 'Geocoders/Maps_Geocoder.php';
 38+ $wgAutoloadClasses['MapsBaseGeocoder'] = dirname( __FILE__ ) . '/Maps_BaseGeocoder.php';
 39+ $wgAutoloadClasses['MapsGeocoder'] = dirname( __FILE__ ) . '/Maps_Geocoder.php';
 40+
 41+ include_once dirname( __FILE__ ) . '/Maps_GoogleGeocoder.php'; // Google
 42+ include_once dirname( __FILE__ ) . '/Maps_YahooGeocoder.php'; // Yahoo!
 43+ include_once dirname( __FILE__ ) . '/Maps_GeonamesGeocoder.php'; // GeoNames
 44+
 45+ // Remove the supported geocoding services that are not in the $egMapsAvailableGeoServices array.
 46+ $supportedServices = array_keys($egMapsGeoServices);
 47+ foreach ($supportedServices as $supportedService) {
 48+ if ( !in_array($supportedService, $egMapsAvailableGeoServices) ) {
 49+ unset( $egMapsGeoServices[$supportedService] );
 50+ }
 51+ }
 52+
 53+ // Re-populate the $egMapsAvailableGeoServices with it's original services that are supported.
 54+ $egMapsAvailableGeoServices = array_keys($egMapsGeoServices);
 55+
 56+ // Enure that the default geoservice is one of the enabled ones.
 57+ if ( !in_array( $egMapsDefaultGeoService, $egMapsAvailableGeoServices ) ) {
 58+ reset( $egMapsAvailableGeoServices );
 59+ $egMapsDefaultGeoService = key( $egMapsAvailableGeoServices );
 60+ }
 61+
 62+ return true;
3563 }
3664
3765 }
\ No newline at end of file
Index: trunk/extensions/Maps/Geocoders/Maps_GoogleGeocoder.php
@@ -15,6 +15,10 @@
1616 die( 'Not an entry point.' );
1717 }
1818
 19+$wgAutoloadClasses['MapsGoogleGeocoder'] = __FILE__;
 20+$egMapsGeoServices['google'] = 'MapsGoogleGeocoder';
 21+$egMapsGeoOverrides['google'] = array( 'googlemaps2', 'googlemaps3' );
 22+
1923 final class MapsGoogleGeocoder extends MapsBaseGeocoder {
2024
2125 /**
@@ -25,7 +29,7 @@
2630 public static function geocode( $address ) {
2731 global $egGoogleMapsKey;
2832
29 - // In case the google maps api key is not set, return false
 33+ // In case the google maps api key is not set, return false0
3034 if ( empty( $egGoogleMapsKey ) ) return false;
3135
3236 // Create the request url
@@ -33,20 +37,18 @@
3438
3539 $result = self::GetResponse( $requestURL );
3640
37 - // Check the Google Geocoder API Response code to ensure success
 41+ // Check the Google Geocoder API Response code to ensure success0
3842 if ( substr( $result, 0, 3 ) == '200' ) {
3943 $result = explode( ',', $result );
4044
4145 // $precision = $result[1];
42 - $latitude = $result[2];
43 - $longitude = $result[3];
4446
4547 return array(
46 - 'lat' => $latitude,
47 - 'lon' => $longitude
 48+ 'lat' => $result[2],
 49+ 'lon' => $result[3]
4850 );
4951 }
50 - else { // When the request fails, return false
 52+ else { // When the request fails, return false0
5153 return false;
5254 }
5355 }
Index: trunk/extensions/Maps/Geocoders/Maps_GeonamesGeocoder.php
@@ -14,6 +14,9 @@
1515 die( 'Not an entry point.' );
1616 }
1717
 18+$wgAutoloadClasses['MapsGeonamesGeocoder'] = __FILE__;
 19+$egMapsGeoServices['geonames'] = 'MapsGeonamesGeocoder';
 20+
1821 final class MapsGeonamesGeocoder extends MapsBaseGeocoder {
1922
2023 /**
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php
@@ -83,7 +83,7 @@
8484 * @return array with coordinates or false
8585 */
8686 public static function geocode( $address, $service, $mappingService ) {
87 - global $egMapsAvailableGeoServices, $wgAutoloadClasses, $egMapsDir, $IP;
 87+ global $egMapsGeoServices, $wgAutoloadClasses, $egMapsDir, $IP;
8888
8989 // If the adress is already in the cache and the cache is enabled, return the coordinates.
9090 if ( self::$mEnableCache && array_key_exists( $address, MapsGeocoder::$mGeocoderCache ) ) {
@@ -92,12 +92,8 @@
9393
9494 $service = self::getValidGeoService( $service, $mappingService );
9595
96 - // Make sure the needed class is loaded.
97 - $file = $egMapsAvailableGeoServices[$service]['local'] ? $egMapsDir . $egMapsAvailableGeoServices[$service]['file'] : $IP . '/extensions/' . $egMapsAvailableGeoServices[$service]['file'];
98 - $wgAutoloadClasses[$egMapsAvailableGeoServices[$service]['class']] = $file;
99 -
10096 // Call the geocode function in the spesific geocoder class.
101 - $coordinates = call_user_func( array( $egMapsAvailableGeoServices[$service]['class'], 'geocode' ), $address );
 97+ $coordinates = call_user_func( array( $egMapsGeoServices[$service], 'geocode' ), $address );
10298
10399 // Add the obtained coordinates to the cache when there is a result and the cache is enabled.
104100 if ( self::$mEnableCache && $coordinates ) {
@@ -117,13 +113,13 @@
118114 * @return string
119115 */
120116 private static function getValidGeoService( $service, $mappingService ) {
121 - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 117+ global $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsGeoOverrides;
122118
123 - if ( strlen( $service ) < 1 ) {
 119+ if ( $service == '' ) {
124120 // If no service has been provided, check if there are overrides for the default.
125 - foreach ( $egMapsAvailableGeoServices as $geoService => $serviceData ) {
126 - if ( in_array( $mappingService, $serviceData ) ) {
127 - $service = $geoService; // Use the override
 121+ foreach ( $egMapsAvailableGeoServices as $geoService ) {
 122+ if ( array_key_exists( $geoService, $egMapsGeoOverrides ) && in_array( $mappingService, $egMapsGeoOverrides[$geoService] ) ) {
 123+ $service = $geoService; // Use the override.
128124 break;
129125 }
130126 }
Index: trunk/extensions/Maps/Geocoders/Maps_YahooGeocoder.php
@@ -14,6 +14,9 @@
1515 die( 'Not an entry point.' );
1616 }
1717
 18+$wgAutoloadClasses['MapsYahooGeocoder'] = __FILE__;
 19+$egMapsGeoServices['yahoo'] = 'MapsYahooGeocoder';
 20+
1821 final class MapsYahooGeocoder extends MapsBaseGeocoder {
1922
2023 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r64427Changes for 0.6 - follow up on r64422 - Fixed some issuesjeroendedauw07:11, 31 March 2010
r64428Changes for 0.6 - follow up on r64422jeroendedauw07:11, 31 March 2010

Status & tagging log