Completed
Push — oldjunk ( e9510e )
by Jeroen De
08:00
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 31 and the first side effect is on line 27.

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