Completed
Push — leaflet-layers ( df0997...51607c )
by Peter
08:52
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 25.

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