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