Completed
Push — independent-tests ( 271ef5 )
by Jeroen De
06:48
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 32 and the first side effect is on line 28.

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