Completed
Push — geonames-geocoder ( 9fbfea...01e909 )
by Jeroen De
08:23 queued 03:14
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 33 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Initialization file for the Maps extension.
5
 *
6
 * @links https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps Documentation
7
 * @links https://github.com/JeroenDeDauw/Maps/issues Support
8
 * @links https://github.com/JeroenDeDauw/Maps Source code
9
 *
10
 * @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
14
use DataValues\Geo\Parsers\GeoCoordinateParser;
15
use FileFetcher\SimpleFileFetcher;
16
use Maps\CircleParser;
17
use Maps\DistanceParser;
18
use Maps\SemanticMaps;
19
use Maps\ImageOverlayParser;
20
use Maps\LineParser;
21
use Maps\LocationParser;
22
use Maps\PolygonParser;
23
use Maps\RectangleParser;
24
use Maps\ServiceParam;
25
use Maps\WmsOverlayParser;
26
27
if ( defined( 'Maps_COORDS_FLOAT' ) ) {
28
	// Do not initialize more than once.
29
	return 1;
30
}
31
32
// The different coordinate notations.
33
define( 'Maps_COORDS_FLOAT' , 'float' );
34
define( 'Maps_COORDS_DMS' , 'dms' );
35
define( 'Maps_COORDS_DM' , 'dm' );
36
define( 'Maps_COORDS_DD' , 'dd' );
37
38
require_once __DIR__ . '/Maps_Settings.php';
39
40
// Include the composer autoloader if it is present.
41
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
42
	include_once( __DIR__ . '/vendor/autoload.php' );
43
}
44
45
// Internationalization
46
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
47
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
48
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
49
50
51
$GLOBALS['wgExtensionFunctions'][] = function () {
52
	if ( $GLOBALS['egMapsDisableExtension'] ) {
53
		return true;
54
	}
55
56
	if ( defined( 'Maps_VERSION' ) ) {
57
		// Do not initialize more than once.
58
		return true;
59
	}
60
61
	// Only initialize the extension when all dependencies are present.
62
	if ( !defined( 'Validator_VERSION' ) ) {
63
		throw new Exception( 'You need to have Validator installed in order to use Maps' );
64
	}
65
66
	if ( version_compare( $GLOBALS['wgVersion'], '1.27c' , '<' ) ) {
67
		throw new Exception(
68
			'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
69
			. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
70
		);
71
	}
72
73
	define( 'Maps_VERSION' , '4.5 alpha' );
74
	define( 'SM_VERSION', Maps_VERSION );
75
76
	if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
77
		$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
78
	}
79
80
	if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
81
		$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
82
		$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
83
	}
84
85
	$GLOBALS['wgExtensionCredits']['parserhook'][] = [
86
		'path' => __FILE__ ,
87
		'name' => 'Maps' ,
88
		'version' => Maps_VERSION ,
89
		'author' => [
90
			'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
91
			'...'
92
		] ,
93
		'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps' ,
94
		'descriptionmsg' => 'maps-desc',
95
		'license-name' => 'GPL-2.0+'
96
	];
97
98
	$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
99
100
	$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
101
102
	$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
103
104
105
106
	$GLOBALS['wgHooks']['AdminLinks'][]                = 'MapsHooks::addToAdminLinks';
107
	$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
108
109
	// Parser hooks
110
111
	// Required for #coordinates.
112
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
113
		$instance = new MapsCoordinates();
114
		return $instance->init( $parser );
115
	};
116
117
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
118
		$instance = new MapsDisplayMap();
119
		return $instance->init( $parser );
120
	};
121
122
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
123
		$instance = new MapsDistance();
124
		return $instance->init( $parser );
125
	};
126
127
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
128
		$instance = new MapsFinddestination();
129
		return $instance->init( $parser );
130
	};
131
132
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
133
		$instance = new MapsGeocode();
134
		return $instance->init( $parser );
135
	};
136
137
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
138
		$instance = new MapsGeodistance();
139
		return $instance->init( $parser );
140
	};
141
142
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
143
		$instance = new MapsMapsDoc();
144
		return $instance->init( $parser );
145
	};
146
147
	// Geocoders
148
149
	// Registration of the GeoNames service geocoder.
150
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() {
151
		if ( $GLOBALS['egMapsGeoNamesUser'] !== '' ) {
152
			\Maps\Geocoders::registerGeocoder(
153
				'geonames',
154
				new \Maps\Geocoders\GeoNamesGeocoder( new SimpleFileFetcher(), $GLOBALS['egMapsGeoNamesUser'] )
155
			);
156
		}
157
158
		return true;
159
	};
160
161
	// Registration of the Google Geocoding (v2) service geocoder.
162
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
163
164
	// Registration of the geocoder.us service geocoder.
165
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
166
167
	// Registration of the OSM Nominatim service geocoder.
168
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() {
169
		\Maps\Geocoders::registerGeocoder(
170
			'nominatim',
171
			new \Maps\Geocoders\NominatimGeocoder( new SimpleFileFetcher() )
172
		);
173
		return true;
174
	};
175
176
177
178
	// Google Maps API v3
179
	if ( $GLOBALS['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $GLOBALS ) ) {
180
		$GLOBALS['egMapsGMaps3ApiKey'] = $GLOBALS['egGoogleJsApiKey'];
181
	}
182
183
	include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
184
185
	MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class );
186
187
	$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' );
188
	$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
189
190
191
192
	// OpenLayers API
193
	include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
194
195
	MapsMappingServices::registerService(
196
		'openlayers',
197
		MapsOpenLayers::class,
198
		[ 'display_map' => MapsDisplayMapRenderer::class ]
199
	);
200
201
202
203
	// Leaflet API
204
	include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
205
206
	MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class );
207
	$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
208
	$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
209
210
211
212
213
	$GLOBALS['wgAvailableRights'][] = 'geocode';
214
215
	// Users that can geocode. By default the same as those that can edit.
216
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
217
		if ( array_key_exists( 'edit' , $rights ) ) {
218
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
219
		}
220
	}
221
222
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
223
		'string-parser' => GeoCoordinateParser::class,
224
	];
225
226
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
227
		'definition'=> ServiceParam::class,
228
	];
229
230
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
231
		'string-parser' => LocationParser::class,
232
	];
233
234
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
235
		'string-parser' => LineParser::class,
236
	];
237
238
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
239
		'string-parser' => CircleParser::class,
240
	];
241
242
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
243
		'string-parser' => RectangleParser::class,
244
	];
245
246
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
247
		'string-parser' => PolygonParser::class,
248
	];
249
250
	$GLOBALS['wgParamDefinitions']['distance'] = [
251
		'string-parser' => DistanceParser::class,
252
	];
253
254
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
255
		'string-parser' => WmsOverlayParser::class,
256
	];
257
258
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
259
		'string-parser' => ImageOverlayParser::class,
260
	];
261
262
	if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) {
263
		SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension();
264
	}
265
266
	return true;
267
};
268
269