Completed
Pull Request — master (#289)
by Jeroen De
05:11 queued 03:02
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.23c' , '<' ) ) {
67
		throw new Exception(
68
			'This version of Maps requires MediaWiki 1.23 or above; use Maps 3.5.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.0.3 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'][] = 'MapsGeonamesGeocoder::register';
151
152
	// Registration of the Google Geocoding (v2) service geocoder.
153
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
154
155
	// Registration of the geocoder.us service geocoder.
156
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
157
158
	// Registration of the OSM Nominatim service geocoder.
159
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = function() {
160
		\Maps\Geocoders::registerGeocoder(
161
			'nominatim',
162
			new \Maps\Geocoders\NominatimGeocoder( new SimpleFileFetcher() )
163
		);
164
		return true;
165
	};
166
167
168
169
	// Google Maps API v3
170
	if ( $GLOBALS['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $GLOBALS ) ) {
171
		$GLOBALS['egMapsGMaps3ApiKey'] = $GLOBALS['egGoogleJsApiKey'];
172
	}
173
174
	include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
175
176
	MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class );
177
178
	$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' );
179
	$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
180
181
182
183
	// OpenLayers API
184
	include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
185
186
	MapsMappingServices::registerService(
187
		'openlayers',
188
		MapsOpenLayers::class,
189
		[ 'display_map' => MapsDisplayMapRenderer::class ]
190
	);
191
192
193
194
	// Leaflet API
195
	include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
196
197
	MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class );
198
	$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
199
	$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
200
201
202
203
204
	$GLOBALS['wgAvailableRights'][] = 'geocode';
205
206
	// Users that can geocode. By default the same as those that can edit.
207
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
208
		if ( array_key_exists( 'edit' , $rights ) ) {
209
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
210
		}
211
	}
212
213
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
214
		'string-parser' => GeoCoordinateParser::class,
215
	];
216
217
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
218
		'definition'=> ServiceParam::class,
219
	];
220
221
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
222
		'string-parser' => LocationParser::class,
223
	];
224
225
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
226
		'string-parser' => LineParser::class,
227
	];
228
229
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
230
		'string-parser' => CircleParser::class,
231
	];
232
233
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
234
		'string-parser' => RectangleParser::class,
235
	];
236
237
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
238
		'string-parser' => PolygonParser::class,
239
	];
240
241
	$GLOBALS['wgParamDefinitions']['distance'] = [
242
		'string-parser' => DistanceParser::class,
243
	];
244
245
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
246
		'string-parser' => WmsOverlayParser::class,
247
	];
248
249
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
250
		'string-parser' => ImageOverlayParser::class,
251
	];
252
253
	if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) {
254
		SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension();
255
	}
256
257
	return true;
258
};
259
260