Completed
Push — geosetting ( 8287b4 )
by Jeroen De
04:01
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' , '5.0 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
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() {
162
		\Maps\Geocoders::registerGeocoder(
163
			'google',
164
			new \Maps\Geocoders\GoogleGeocoder(
165
				new SimpleFileFetcher(),
166
				$GLOBALS['egMapsGMaps3ApiKey'],
167
				$GLOBALS['egMapsGMaps3ApiVersion']
168
			)
169
		);
170
171
		return true;
172
	};
173
174
	// Registration of the OSM Nominatim service geocoder.
175
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() {
176
		\Maps\Geocoders::registerGeocoder(
177
			'nominatim',
178
			new \Maps\Geocoders\NominatimGeocoder( new SimpleFileFetcher() )
179
		);
180
		return true;
181
	};
182
183
184
185
	// Google Maps API v3
186
	if ( $GLOBALS['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $GLOBALS ) ) {
187
		$GLOBALS['egMapsGMaps3ApiKey'] = $GLOBALS['egGoogleJsApiKey'];
188
	}
189
190
	include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
191
192
	MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class );
193
194
	$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' );
195
	$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
196
197
198
199
	// OpenLayers API
200
	include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
201
202
	MapsMappingServices::registerService(
203
		'openlayers',
204
		MapsOpenLayers::class,
205
		[ 'display_map' => MapsDisplayMapRenderer::class ]
206
	);
207
208
209
210
	// Leaflet API
211
	include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
212
213
	MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class );
214
	$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
215
	$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
216
217
218
219
220
	$GLOBALS['wgAvailableRights'][] = 'geocode';
221
222
	// Users that can geocode. By default the same as those that can edit.
223
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
224
		if ( array_key_exists( 'edit' , $rights ) ) {
225
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
226
		}
227
	}
228
229
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
230
		'string-parser' => GeoCoordinateParser::class,
231
	];
232
233
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
234
		'definition'=> ServiceParam::class,
235
	];
236
237
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
238
		'string-parser' => LocationParser::class,
239
	];
240
241
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
242
		'string-parser' => LineParser::class,
243
	];
244
245
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
246
		'string-parser' => CircleParser::class,
247
	];
248
249
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
250
		'string-parser' => RectangleParser::class,
251
	];
252
253
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
254
		'string-parser' => PolygonParser::class,
255
	];
256
257
	$GLOBALS['wgParamDefinitions']['distance'] = [
258
		'string-parser' => DistanceParser::class,
259
	];
260
261
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
262
		'string-parser' => WmsOverlayParser::class,
263
	];
264
265
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
266
		'string-parser' => ImageOverlayParser::class,
267
	];
268
269
	if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) {
270
		SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension();
271
	}
272
273
	return true;
274
};
275
276