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