Completed
Pull Request — master (#131)
by None
09:21
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 58 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
28
if ( version_compare( $GLOBALS['wgVersion'], '1.23c' , '<' ) ) {
29
	throw new Exception(
30
		'This version of Maps requires MediaWiki 1.23 or above; use Maps 3.5.x for older versions.'
31
		. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
32
	);
33
}
34
35
if ( version_compare( $GLOBALS['wgVersion'], '1.28c', '>' ) ) {
36
	if ( function_exists( 'wfLoadExtension' ) ) {
37
		wfLoadExtension( 'Maps' );
38
		// Keep i18n globals so mergeMessageFileList.php doesn't break
39
		$GLOBALS['wgMessagesDirs']['Maps']							= __DIR__ . '/i18n';
40
		$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] 			= __DIR__ . '/Maps.i18n.magic.php';
41
		$GLOBALS['wgExtensionMessagesFiles']['MapsNamespaces'] 		= __DIR__ . '/Maps.i18n.namespaces.php';
42
		$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] 			= __DIR__ . '/Maps.i18n.alias.php';
43
		/* wfWarn(
44
			'Deprecated PHP entry point used for Maps extension. ' .
45
			'Please use wfLoadExtension instead, ' .
46
			'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
47
		); */
48
		return;
49
	}
50
}
51
52
if ( defined( 'Maps_COORDS_FLOAT' ) ) {
53
	// Do not initialize more than once.
54
	return 1;
55
}
56
57
// The different coordinate notations.
58
define( 'Maps_COORDS_FLOAT' , 'float' );
59
define( 'Maps_COORDS_DMS' , 'dms' );
60
define( 'Maps_COORDS_DM' , 'dm' );
61
define( 'Maps_COORDS_DD' , 'dd' );
62
63
require_once __DIR__ . '/Maps_Settings.php';
64
65
// Include the composer autoloader if it is present.
66
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
67
	include_once( __DIR__ . '/vendor/autoload.php' );
68
}
69
70
// Internationalization
71
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
72
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
73
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
74
75
76
$GLOBALS['wgExtensionFunctions'][] = function () {
77
	if ( $GLOBALS['egMapsDisableExtension'] ) {
78
		return true;
79
	}
80
81
	if ( defined( 'Maps_VERSION' ) ) {
82
		// Do not initialize more than once.
83
		return true;
84
	}
85
86
	// Only initialize the extension when all dependencies are present.
87
	if ( !defined( 'Validator_VERSION' ) ) {
88
		throw new Exception( 'You need to have Validator installed in order to use Maps' );
89
	}
90
91
	define( 'Maps_VERSION' , '4.2.1' );
92
	define( 'SM_VERSION', Maps_VERSION );
93
94
	if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
95
		$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
96
	}
97
98
	if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
99
		$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
100
		$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
101
	}
102
103
	$GLOBALS['wgExtensionCredits']['parserhook'][] = [
104
		'path' => __FILE__ ,
105
		'name' => 'Maps' ,
106
		'version' => Maps_VERSION ,
107
		'author' => [
108
			'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
109
			'...'
110
		] ,
111
		'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps' ,
112
		'descriptionmsg' => 'maps-desc',
113
		'license-name' => 'GPL-2.0+'
114
	];
115
116
	$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
117
118
	$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
119
120
	$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
121
122
123
124
	$GLOBALS['wgHooks']['AdminLinks'][]                = 'MapsHooks::addToAdminLinks';
125
	$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
126
127
	// Parser hooks
128
129
	// Required for #coordinates.
130
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit1';
131
132
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit2';
133
134
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit3';
135
136
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit4';
137
138
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit5';
139
140
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit6';
141
142
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'MapsHooks::onParserFirstCallInit7';
143
144
	// Geocoders
145
146
	// Registration of the GeoNames service geocoder.
147
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
148
149
	// Registration of the Google Geocoding (v2) service geocoder.
150
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
151
152
	// Registration of the geocoder.us service geocoder.
153
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
154
155
	// Registration of the OSM Nominatim service geocoder.
156
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsHooks::onMapsGeocodersNominatimGeocoder';
157
158
159
160
	// Google Maps API v3
161
	if ( $GLOBALS['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $GLOBALS ) ) {
162
		$GLOBALS['egMapsGMaps3ApiKey'] = $GLOBALS['egGoogleJsApiKey'];
163
	}
164
165
	include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
166
167
	MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class );
168
169
	$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' );
170
	$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
171
172
173
174
	// OpenLayers API
175
	include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
176
177
	MapsMappingServices::registerService(
178
		'openlayers',
179
		MapsOpenLayers::class,
180
		[ 'display_map' => MapsDisplayMapRenderer::class ]
181
	);
182
183
184
185
	// Leaflet API
186
	include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
187
188
	MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class );
189
	$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
190
	$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
191
192
193
194
195
	$GLOBALS['wgAvailableRights'][] = 'geocode';
196
197
	// Users that can geocode. By default the same as those that can edit.
198
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
199
		if ( array_key_exists( 'edit' , $rights ) ) {
200
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
201
		}
202
	}
203
204
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
205
		'string-parser' => GeoCoordinateParser::class,
206
	];
207
208
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
209
		'definition'=> ServiceParam::class,
210
	];
211
212
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
213
		'string-parser' => LocationParser::class,
214
	];
215
216
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
217
		'string-parser' => LineParser::class,
218
	];
219
220
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
221
		'string-parser' => CircleParser::class,
222
	];
223
224
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
225
		'string-parser' => RectangleParser::class,
226
	];
227
228
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
229
		'string-parser' => PolygonParser::class,
230
	];
231
232
	$GLOBALS['wgParamDefinitions']['distance'] = [
233
		'string-parser' => DistanceParser::class,
234
	];
235
236
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
237
		'string-parser' => WmsOverlayParser::class,
238
	];
239
240
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
241
		'string-parser' => ImageOverlayParser::class,
242
	];
243
244
	if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) {
245
		SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension();
246
	}
247
248
	return true;
249
};
250
251