Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3.php |
— | — | @@ -20,17 +20,10 @@ |
21 | 21 | die( 'Not an entry point.' ); |
22 | 22 | } |
23 | 23 | |
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'; |
34 | 25 | |
| 26 | +$wgHooks['MappingServiceLoad'][] = 'MapsGoogleMaps3::initialize'; |
| 27 | + |
35 | 28 | /** |
36 | 29 | * Class for Google Maps v3 initialization. |
37 | 30 | * |
— | — | @@ -43,9 +36,23 @@ |
44 | 37 | const SERVICE_NAME = 'googlemaps3'; |
45 | 38 | |
46 | 39 | 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 | + |
47 | 51 | self::initializeParams(); |
| 52 | + |
48 | 53 | Validator::addOutputFormat( 'gmap3type', array( 'MapsGoogleMaps3', 'setGMapType' ) ); |
49 | 54 | Validator::addOutputFormat( 'gmap3types', array( 'MapsGoogleMaps3', 'setGMapTypes' ) ); |
| 55 | + |
| 56 | + return true; |
50 | 57 | } |
51 | 58 | |
52 | 59 | private static function initializeParams() { |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php |
— | — | @@ -20,16 +20,10 @@ |
21 | 21 | die( 'Not an entry point.' ); |
22 | 22 | } |
23 | 23 | |
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 | + |
34 | 28 | /** |
35 | 29 | * Class for OpenLayers initialization. |
36 | 30 | * |
— | — | @@ -42,11 +36,26 @@ |
43 | 37 | const SERVICE_NAME = 'openlayers'; |
44 | 38 | |
45 | 39 | 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 | + |
46 | 55 | self::initializeParams(); |
| 56 | + |
47 | 57 | Validator::addOutputFormat( 'olgroups', array( __CLASS__, 'unpackLayerGroups' ) ); |
48 | 58 | |
49 | | - global $egMapsOLLoadedLayers; |
50 | | - $egMapsOLLoadedLayers = array(); |
| 59 | + return true; |
51 | 60 | } |
52 | 61 | |
53 | 62 | private static function initializeParams() { |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
21 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
22 | 22 | |
23 | | -$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayPoint'; |
| 23 | +$egMapsFeatures['pf'][] = 'MapsDisplayPoint::initialize'; |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Adds the magic words for the parser functions. |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | * |
39 | 39 | * @return html |
40 | 40 | */ |
41 | | - public final function displayMap( &$parser, array $params ) { |
| 41 | + public final function displayMap( Parser &$parser, array $params ) { |
42 | 42 | $this->setMapSettings(); |
43 | 43 | |
44 | 44 | $this->featureParameters = MapsDisplayPoint::$parameters; |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
21 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
22 | 22 | |
23 | | -$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayMap'; |
| 23 | +$egMapsFeatures['pf'][] = 'MapsDisplayMap::initialize'; |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Adds the magic words for the parser functions. |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | * |
35 | 35 | * @return html |
36 | 36 | */ |
37 | | - public final function displayMap( &$parser, array $params ) { |
| 37 | + public final function displayMap( Parser &$parser, array $params ) { |
38 | 38 | $this->setMapSettings(); |
39 | 39 | |
40 | 40 | $this->featureParameters = MapsDisplayMap::$parameters; |
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php |
— | — | @@ -22,21 +22,21 @@ |
23 | 23 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions'; |
24 | 24 | |
25 | 25 | /** |
26 | | - * Adds the magic words for the parser functions |
| 26 | + * Adds the magic words for the parser functions. |
27 | 27 | */ |
28 | 28 | function efMapsGeoFunctionMagic( &$magicWords, $langCode ) { |
29 | 29 | $magicWords['geocode'] = array( 0, 'geocode' ); |
30 | 30 | $magicWords['geocodelat'] = array ( 0, 'geocodelat' ); |
31 | 31 | $magicWords['geocodelon'] = array ( 0, 'geocodelon', 'geocodelng' ); |
32 | 32 | |
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. |
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | | - * Adds the parser function hooks |
| 37 | + * Adds the parser function hooks. |
38 | 38 | */ |
39 | 39 | function efMapsRegisterGeoFunctions( &$wgParser ) { |
40 | | - // Hooks to enable the geocoding parser functions |
| 40 | + // Hooks to enable the geocoding parser functions. |
41 | 41 | $wgParser->setFunctionHook( 'geocode', array( 'MapsGeocodeFunctions', 'renderGeocoder' ) ); |
42 | 42 | $wgParser->setFunctionHook( 'geocodelat', array( 'MapsGeocodeFunctions', 'renderGeocoderLat' ) ); |
43 | 43 | $wgParser->setFunctionHook( 'geocodelon', array( 'MapsGeocodeFunctions', 'renderGeocoderLon' ) ); |
— | — | @@ -67,8 +67,8 @@ |
68 | 68 | * |
69 | 69 | * @return string |
70 | 70 | */ |
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 ); |
73 | 73 | return $geovalues ? $geovalues : ''; |
74 | 74 | } |
75 | 75 | |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | * |
85 | 85 | * @return string |
86 | 86 | */ |
87 | | - public static function renderGeocoderLat( &$parser, $address, $service = '', $mappingService = '' ) { |
| 87 | + public static function renderGeocoderLat( Parser &$parser, $address, $service = '', $mappingService = '' ) { |
88 | 88 | if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
89 | 89 | return $geovalues ? $geovalues['lat'] : ''; |
90 | 90 | } |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | * |
101 | 101 | * @return string |
102 | 102 | */ |
103 | | - public static function renderGeocoderLon( &$parser, $address, $service = '', $mappingService = '' ) { |
| 103 | + public static function renderGeocoderLon( Parser &$parser, $address, $service = '', $mappingService = '' ) { |
104 | 104 | if ( self::geocoderIsAvailable() ) $geovalues = MapsGeocoder::geocode( $address, $service, $mappingService ); |
105 | 105 | return $geovalues ? $geovalues['lon'] : ''; |
106 | 106 | } |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | +$wgAutoloadClasses['MapsParserFunctions'] = __FILE__; |
| 18 | + |
| 19 | +$wgHooks['MappingFeatureLoad'][] = 'MapsParserFunctions::initialize'; |
| 20 | + |
17 | 21 | /** |
18 | 22 | * A class that holds handlers for the mapping parser functions. |
19 | 23 | * |
— | — | @@ -27,30 +31,18 @@ |
28 | 32 | * and will load the required classes. |
29 | 33 | */ |
30 | 34 | public static function initialize() { |
31 | | - global $egMapsDir, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices; |
| 35 | + global $egMapsDir, $IP, $wgAutoloadClasses, $egMapsFeatures, $egMapsServices; |
32 | 36 | |
33 | 37 | include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php'; |
34 | 38 | |
35 | 39 | self::initializeParams(); |
36 | 40 | |
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 ); |
49 | 44 | } |
50 | 45 | |
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; |
55 | 47 | } |
56 | 48 | |
57 | 49 | private static function initializeParams() { |
— | — | @@ -60,7 +52,7 @@ |
61 | 53 | 'service' => array( |
62 | 54 | 'criteria' => array( |
63 | 55 | 'in_array' => $egMapsAvailableServices |
64 | | - ), |
| 56 | + ), |
65 | 57 | 'default' => $egMapsDefaultServices['pf'] |
66 | 58 | ), |
67 | 59 | 'coordinates' => array( |
— | — | @@ -93,9 +85,9 @@ |
94 | 86 | $coordFails = array(); |
95 | 87 | |
96 | 88 | $paramInfo = array_merge( MapsMapper::getMainParams(), self::$parameters ); |
| 89 | + |
| 90 | + $geoFails = self::changeAddressesToCoords( $params, $paramInfo, $parserFunction ); |
97 | 91 | |
98 | | - $geoFails = self::changeAddressesToCoords( $params, $paramInfo ); |
99 | | - |
100 | 92 | // Go through all parameters, split their names and values, and put them in the $map array. |
101 | 93 | foreach ( $params as $param ) { |
102 | 94 | $split = explode( '=', $param ); |
— | — | @@ -107,7 +99,7 @@ |
108 | 100 | if ( self::inParamAliases( $paramName, 'coordinates', $paramInfo ) ) $coordFails = self::filterInvalidCoords( $map[$paramName] ); |
109 | 101 | } |
110 | 102 | } |
111 | | - else if ( count( $split ) == 1 ) { // Default parameter (without name) |
| 103 | + else if ( count( $split ) == 1 ) { // Default parameter (without name). |
112 | 104 | $split[0] = trim( $split[0] ); |
113 | 105 | if ( strlen( $split[0] ) > 0 ) $map['coordinates'] = $split[0]; |
114 | 106 | } |
— | — | @@ -116,13 +108,9 @@ |
117 | 109 | $coords = self::getParamValue( 'coordinates', $map, $paramInfo ); |
118 | 110 | |
119 | 111 | if ( $coords ) { |
120 | | - if ( ! self::paramIsPresent( 'service', $map, $paramInfo ) ) $map['service'] = ''; |
121 | | - |
122 | | - $map['service'] = MapsMapper::getValidService( $map['service'], 'pf', $parserFunction ); |
123 | | - |
124 | 112 | $mapClass = self::getParserClassInstance( $map['service'], $parserFunction ); |
125 | 113 | |
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. |
127 | 115 | $output = $mapClass->displayMap( $parser, $map ); |
128 | 116 | |
129 | 117 | if ( $egValidatorErrorLevel >= Validator_ERRORS_WARN ) { |
— | — | @@ -185,12 +173,14 @@ |
186 | 174 | * Changes the values of the address or addresses parameter into coordinates |
187 | 175 | * in the provided array. Returns an array containing the addresses that |
188 | 176 | * could not be geocoded. |
| 177 | + * |
| 178 | + * Also ensures the service parameter is valid. |
189 | 179 | * |
190 | 180 | * @param array $params |
191 | 181 | * |
192 | 182 | * @return array |
193 | 183 | */ |
194 | | - private static function changeAddressesToCoords( &$params, array $paramInfo ) { |
| 184 | + private static function changeAddressesToCoords( &$params, array $paramInfo, $parserFunction ) { |
195 | 185 | global $egMapsDefaultService; |
196 | 186 | |
197 | 187 | $fails = array(); |
— | — | @@ -207,9 +197,13 @@ |
208 | 198 | } |
209 | 199 | |
210 | 200 | // 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 | + |
212 | 204 | if ( ! isset( $geoservice ) ) $geoservice = ''; |
213 | 205 | |
| 206 | + $setService = false; |
| 207 | + |
214 | 208 | // Go over all parameters. |
215 | 209 | for ( $i = 0; $i < count( $params ); $i++ ) { |
216 | 210 | $split = explode( '=', $params[$i] ); |
— | — | @@ -245,10 +239,16 @@ |
246 | 240 | // Add the geocoded result back to the parameter list. |
247 | 241 | $params[$i] = implode( ';', $coordinates ); |
248 | 242 | |
| 243 | + } else if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) { |
| 244 | + $params[$i] = "service=$service"; |
| 245 | + $setService = true; |
249 | 246 | } |
250 | | - |
251 | 247 | } |
252 | 248 | |
| 249 | + if ( !$setService ) { |
| 250 | + $params[] = "service=$service"; |
| 251 | + } |
| 252 | + |
253 | 253 | return $fails; |
254 | 254 | } |
255 | 255 | |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | */ |
265 | 265 | public static function getParserClassInstance( $service, $parserFunction ) { |
266 | 266 | global $egMapsServices; |
267 | | - return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
| 267 | + return new $egMapsServices[$service]['features'][$parserFunction](); |
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | 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>.'; |
35 | 35 | } |
36 | 36 | else { |
37 | | - define( 'Maps_VERSION', '0.6 a7' ); |
| 37 | + define( 'Maps_VERSION', '0.6 a8' ); |
38 | 38 | |
39 | 39 | // The different coordinate notations. |
40 | 40 | define( 'Maps_COORDS_FLOAT', 'float' ); |
— | — | @@ -44,51 +44,54 @@ |
45 | 45 | // The symbols to use for degrees, minutes and seconds. |
46 | 46 | define( 'Maps_GEO_DEG', '°' ); |
47 | 47 | define( 'Maps_GEO_MIN', "'" ); |
48 | | - define( 'Maps_GEO_SEC', '"' ); |
| 48 | + define( 'Maps_GEO_SEC', '"' ); |
49 | 49 | |
50 | 50 | $egMapsScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/Maps'; |
51 | 51 | $egMapsDir = dirname( __FILE__ ) . '/'; |
52 | 52 | |
53 | | - $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION; |
| 53 | + $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION; |
54 | 54 | |
55 | 55 | // Include the settings file. |
56 | 56 | require_once( $egMapsDir . 'Maps_Settings.php' ); |
57 | 57 | |
| 58 | + $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php'; |
| 59 | + |
58 | 60 | // Register the initialization function of Maps. |
59 | 61 | $wgExtensionFunctions[] = 'efMapsSetup'; |
60 | | - |
61 | | - $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php'; |
62 | | - |
| 62 | + |
63 | 63 | $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'; |
69 | 64 | } |
70 | 65 | |
71 | 66 | /** |
72 | 67 | * Initialization function for the Maps extension. |
73 | 68 | */ |
74 | 69 | 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 | + |
79 | 87 | // Remove all hooked in services that should not be available. |
80 | 88 | foreach ( $egMapsServices as $service => $data ) { |
81 | 89 | if ( ! in_array( $service, $egMapsAvailableServices ) ) unset( $egMapsServices[$service] ); |
82 | 90 | } |
| 91 | + $egMapsAvailableServices = array_keys( $egMapsServices ); |
83 | 92 | |
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]; |
90 | 95 | |
91 | | - wfLoadExtensionMessages( 'Maps' ); |
92 | | - |
93 | 96 | // Creation of a list of internationalized service names. |
94 | 97 | $services = array(); |
95 | 98 | foreach ( array_keys( $egMapsServices ) as $name ) $services[] = wfMsg( 'maps_' . $name ); |
— | — | @@ -104,42 +107,19 @@ |
105 | 108 | ); |
106 | 109 | |
107 | 110 | MapsMapper::initializeMainParams(); |
108 | | - |
109 | | - // wfRunHooks( 'MappingFeatureLoad'); |
110 | | - // wfRunHooks( 'MappingServiceLoad'); |
111 | 111 | |
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 | | - |
132 | 112 | $egMapsJsExt = $egMapsUseMinJs ? '.min.js' : '.js'; |
133 | 113 | |
134 | 114 | return true; |
135 | 115 | } |
136 | 116 | |
137 | 117 | /** |
138 | | - * Adds a link to Admin Links page |
| 118 | + * Adds a link to Admin Links page. |
139 | 119 | */ |
140 | 120 | function efMapsAddToAdminLinks( &$admin_links_tree ) { |
141 | 121 | $displaying_data_section = $admin_links_tree->getSection( wfMsg( 'smw_adminlinks_displayingdata' ) ); |
142 | 122 | |
143 | | - // Escape if SMW hasn't added links |
| 123 | + // Escape if SMW hasn't added links. |
144 | 124 | if ( is_null( $displaying_data_section ) ) return true; |
145 | 125 | $smw_docu_row = $displaying_data_section->getRow( 'smw' ); |
146 | 126 | |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -72,33 +72,17 @@ |
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
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; |
78 | 78 | |
79 | 79 | // Get rid of any aliases. |
80 | 80 | $service = self::getMainServiceName( $service ); |
81 | | - |
82 | 81 | // If the service is not loaded into maps, it should be changed. |
83 | 82 | $shouldChange = ! array_key_exists( $service, $egMapsServices ); |
84 | 83 | |
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. |
87 | 85 | 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'] ); |
103 | 87 | } |
104 | 88 | |
105 | 89 | // Change the service to the most specific default value available. |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -20,17 +20,10 @@ |
21 | 21 | die( 'Not an entry point.' ); |
22 | 22 | } |
23 | 23 | |
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'; |
34 | 25 | |
| 26 | +$wgHooks['MappingServiceLoad'][] = 'MapsGoogleMaps::initialize'; |
| 27 | + |
35 | 28 | /** |
36 | 29 | * Class for Google Maps initialization. |
37 | 30 | * |
— | — | @@ -43,10 +36,27 @@ |
44 | 37 | const SERVICE_NAME = 'googlemaps2'; |
45 | 38 | |
46 | 39 | 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 | + |
47 | 53 | self::initializeParams(); |
| 54 | + |
48 | 55 | Validator::addOutputFormat( 'gmaptype', array( __CLASS__, 'setGMapType' ) ); |
49 | 56 | Validator::addOutputFormat( 'gmaptypes', array( __CLASS__, 'setGMapTypes' ) ); |
| 57 | + |
50 | 58 | Validator::addValidationFunction( 'is_google_overlay', array( __CLASS__, 'isGOverlay' ) ); |
| 59 | + |
| 60 | + return true; |
51 | 61 | } |
52 | 62 | |
53 | 63 | private static function initializeParams() { |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php |
— | — | @@ -20,16 +20,9 @@ |
21 | 21 | die( 'Not an entry point.' ); |
22 | 22 | } |
23 | 23 | |
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'; |
34 | 27 | |
35 | 28 | /** |
36 | 29 | * Class for Yahoo! Maps initialization. |
— | — | @@ -43,9 +36,25 @@ |
44 | 37 | const SERVICE_NAME = 'yahoomaps'; |
45 | 38 | |
46 | 39 | 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 | + |
47 | 53 | self::initializeParams(); |
| 54 | + |
48 | 55 | Validator::addOutputFormat( 'ymaptype', array( __CLASS__, 'setYMapType' ) ); |
49 | 56 | Validator::addOutputFormat( 'ymaptypes', array( __CLASS__, 'setYMapTypes' ) ); |
| 57 | + |
| 58 | + return true; |
50 | 59 | } |
51 | 60 | |
52 | 61 | private static function initializeParams() { |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -26,26 +26,27 @@ |
27 | 27 | # (named) Array of String. This array contains the available features for Maps. |
28 | 28 | # The array element name contains an abbriviation, used for code references, |
29 | 29 | # and in the service data arrays, the value is the human readible version for displaying purpouses. |
30 | | -if ( empty( $egMapsAvailableFeatures ) ) $egMapsAvailableFeatures = array(); |
31 | 30 | |
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. |
38 | 32 | |
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 |
45 | 35 | |
46 | 36 | |
47 | 37 | |
48 | 38 | |
| 39 | +# Geocoding services configuration |
49 | 40 | |
| 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 | + |
50 | 51 | # Include the parser functions that should be loaded into Maps. |
51 | 52 | # Commenting or removing a parser functions will cause Maps to completely ignore it, and so improve performance. |
52 | 53 | include_once $egMapsDir . 'ParserFunctions/DisplayMap/Maps_DisplayMap.php'; // display_map |
— | — | @@ -55,7 +56,6 @@ |
56 | 57 | |
57 | 58 | |
58 | 59 | |
59 | | - |
60 | 60 | # Mapping services configuration |
61 | 61 | # Note: You can not use aliases in the settings. Use the main service names. |
62 | 62 | |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | |
74 | 74 | # Array of String. Array containing all the mapping services that will be made available to the user. |
75 | 75 | # Currently Maps provides the following services: googlemaps, yahoomaps, openlayers |
76 | | -$egMapsAvailableServices = array( 'googlemaps2', 'googlemaps3', 'yahoomaps', 'openlayers', 'osm' ); |
| 76 | +$egMapsAvailableServices = array( 'googlemaps2', 'googlemaps3', 'yahoomaps', 'openlayers' ); |
77 | 77 | |
78 | 78 | # String. The default mapping service, which will be used when no default service is present in the |
79 | 79 | # $egMapsDefaultServices array for a certain feature. A service that supports all features is recommended. |
— | — | @@ -93,38 +93,10 @@ |
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | | -# Geocoding services configuration |
98 | 97 | |
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 | | - ); |
120 | 98 | |
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'; |
124 | 99 | |
125 | 100 | |
126 | | - |
127 | | - |
128 | | - |
129 | 101 | # General configuration |
130 | 102 | |
131 | 103 | # Boolean. Indicates if minified js files should be used where available. |
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoders.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Initialization file for geocoder functionality in the Maps extension |
| 5 | + * Initialization file for geocoder functionality in the Maps extension. |
6 | 6 | * |
7 | 7 | * @file Maps_Geocoders.php |
8 | 8 | * @ingroup Maps |
— | — | @@ -13,24 +13,52 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
| 17 | +$wgAutoloadClasses['MapsGeocoders'] = __FILE__; |
| 18 | + |
| 19 | +$wgHooks['MappingFeatureLoad'][] = 'MapsGeocoders::initialize'; |
| 20 | + |
17 | 21 | /** |
18 | 22 | * Initialization class for geocoder functionality in the Maps extension. |
19 | 23 | * |
20 | 24 | * @author Jeroen De Dauw |
21 | 25 | * |
22 | 26 | */ |
23 | | -final class Geocoders { |
| 27 | +final class MapsGeocoders { |
24 | 28 | |
25 | 29 | /** |
26 | 30 | * Initialization function for Maps geocoder functionality. |
27 | 31 | */ |
28 | 32 | public static function initialize() { |
29 | | - global $wgAutoloadClasses, $egMapsDir, $egMapsGeoServices; |
| 33 | + global $wgAutoloadClasses, $egMapsDir, $egMapsGeoServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsGeoOverrides; |
30 | 34 | |
31 | 35 | $egMapsGeoServices = array(); |
| 36 | + $egMapsGeoOverrides = array(); |
32 | 37 | |
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; |
35 | 63 | } |
36 | 64 | |
37 | 65 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Geocoders/Maps_GoogleGeocoder.php |
— | — | @@ -15,6 +15,10 @@ |
16 | 16 | die( 'Not an entry point.' ); |
17 | 17 | } |
18 | 18 | |
| 19 | +$wgAutoloadClasses['MapsGoogleGeocoder'] = __FILE__; |
| 20 | +$egMapsGeoServices['google'] = 'MapsGoogleGeocoder'; |
| 21 | +$egMapsGeoOverrides['google'] = array( 'googlemaps2', 'googlemaps3' ); |
| 22 | + |
19 | 23 | final class MapsGoogleGeocoder extends MapsBaseGeocoder { |
20 | 24 | |
21 | 25 | /** |
— | — | @@ -25,7 +29,7 @@ |
26 | 30 | public static function geocode( $address ) { |
27 | 31 | global $egGoogleMapsKey; |
28 | 32 | |
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 |
30 | 34 | if ( empty( $egGoogleMapsKey ) ) return false; |
31 | 35 | |
32 | 36 | // Create the request url |
— | — | @@ -33,20 +37,18 @@ |
34 | 38 | |
35 | 39 | $result = self::GetResponse( $requestURL ); |
36 | 40 | |
37 | | - // Check the Google Geocoder API Response code to ensure success |
| 41 | + // Check the Google Geocoder API Response code to ensure success0 |
38 | 42 | if ( substr( $result, 0, 3 ) == '200' ) { |
39 | 43 | $result = explode( ',', $result ); |
40 | 44 | |
41 | 45 | // $precision = $result[1]; |
42 | | - $latitude = $result[2]; |
43 | | - $longitude = $result[3]; |
44 | 46 | |
45 | 47 | return array( |
46 | | - 'lat' => $latitude, |
47 | | - 'lon' => $longitude |
| 48 | + 'lat' => $result[2], |
| 49 | + 'lon' => $result[3] |
48 | 50 | ); |
49 | 51 | } |
50 | | - else { // When the request fails, return false |
| 52 | + else { // When the request fails, return false0 |
51 | 53 | return false; |
52 | 54 | } |
53 | 55 | } |
Index: trunk/extensions/Maps/Geocoders/Maps_GeonamesGeocoder.php |
— | — | @@ -14,6 +14,9 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | } |
17 | 17 | |
| 18 | +$wgAutoloadClasses['MapsGeonamesGeocoder'] = __FILE__; |
| 19 | +$egMapsGeoServices['geonames'] = 'MapsGeonamesGeocoder'; |
| 20 | + |
18 | 21 | final class MapsGeonamesGeocoder extends MapsBaseGeocoder { |
19 | 22 | |
20 | 23 | /** |
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | * @return array with coordinates or false |
85 | 85 | */ |
86 | 86 | public static function geocode( $address, $service, $mappingService ) { |
87 | | - global $egMapsAvailableGeoServices, $wgAutoloadClasses, $egMapsDir, $IP; |
| 87 | + global $egMapsGeoServices, $wgAutoloadClasses, $egMapsDir, $IP; |
88 | 88 | |
89 | 89 | // If the adress is already in the cache and the cache is enabled, return the coordinates. |
90 | 90 | if ( self::$mEnableCache && array_key_exists( $address, MapsGeocoder::$mGeocoderCache ) ) { |
— | — | @@ -92,12 +92,8 @@ |
93 | 93 | |
94 | 94 | $service = self::getValidGeoService( $service, $mappingService ); |
95 | 95 | |
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 | | - |
100 | 96 | // 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 ); |
102 | 98 | |
103 | 99 | // Add the obtained coordinates to the cache when there is a result and the cache is enabled. |
104 | 100 | if ( self::$mEnableCache && $coordinates ) { |
— | — | @@ -117,13 +113,13 @@ |
118 | 114 | * @return string |
119 | 115 | */ |
120 | 116 | private static function getValidGeoService( $service, $mappingService ) { |
121 | | - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 117 | + global $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsGeoOverrides; |
122 | 118 | |
123 | | - if ( strlen( $service ) < 1 ) { |
| 119 | + if ( $service == '' ) { |
124 | 120 | // 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. |
128 | 124 | break; |
129 | 125 | } |
130 | 126 | } |
Index: trunk/extensions/Maps/Geocoders/Maps_YahooGeocoder.php |
— | — | @@ -14,6 +14,9 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | } |
17 | 17 | |
| 18 | +$wgAutoloadClasses['MapsYahooGeocoder'] = __FILE__; |
| 19 | +$egMapsGeoServices['yahoo'] = 'MapsYahooGeocoder'; |
| 20 | + |
18 | 21 | final class MapsYahooGeocoder extends MapsBaseGeocoder { |
19 | 22 | |
20 | 23 | /** |