Completed
Push — shortarray ( 00b5d9 )
by Jeroen De
06:50
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 22 and the first side effect is on line 14.

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
 * Initialization file for the Maps extension.
4
 *
5
 * @links https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps Documentation
6
 * @links https://github.com/JeroenDeDauw/Maps/issues Support
7
 * @links https://github.com/JeroenDeDauw/Maps Source code
8
 *
9
 * @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
13
if ( !defined( 'MEDIAWIKI' ) ) {
14
	die( 'Not an entry point.' );
15
}
16
17
if ( defined( 'Maps_VERSION' ) ) {
18
	// Do not initialize more than once.
19
	return 1;
20
}
21
22
define( 'Maps_VERSION' , '3.6.0-alpha' );
23
24
// Include the composer autoloader if it is present.
25
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
26
	include_once( __DIR__ . '/vendor/autoload.php' );
27
}
28
29
// Only initialize the extension when all dependencies are present.
30
if ( !defined( 'Validator_VERSION' ) ) {
31
	throw new Exception( 'You need to have Validator installed in order to use Maps' );
32
}
33
34
if ( version_compare( $GLOBALS['wgVersion'], '1.23c' , '<' ) ) {
35
	throw new Exception(
36
		'This version of Maps requires MediaWiki 1.23 or above; use Maps 3.5.x for older versions.'
37
		. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
38
	);
39
}
40
41
call_user_func( function() {
42
	$GLOBALS['wgExtensionCredits']['parserhook'][] = [
43
		'path' => __FILE__ ,
44
		'name' => 'Maps' ,
45
		'version' => Maps_VERSION ,
46
		'author' => [
47
			'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
48
			'...'
49
		] ,
50
		'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps' ,
51
		'descriptionmsg' => 'maps-desc',
52
		'license-name' => 'GPL-2.0+'
53
	];
54
55
	// The different coordinate notations.
56
	define( 'Maps_COORDS_FLOAT' , 'float' );
57
	define( 'Maps_COORDS_DMS' , 'dms' );
58
	define( 'Maps_COORDS_DM' , 'dm' );
59
	define( 'Maps_COORDS_DD' , 'dd' );
60
61
	$mapsDir = __DIR__ . '/';
62
63
	$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
64
65
	$GLOBALS['wgMessagesDirs']['Maps']							= __DIR__ . '/i18n';
66
	$GLOBALS['wgExtensionMessagesFiles']['Maps'] 				= __DIR__ . '/Maps.i18n.php';
67
	$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] 			= __DIR__ . '/Maps.i18n.magic.php';
68
	$GLOBALS['wgExtensionMessagesFiles']['MapsNamespaces'] 		= __DIR__ . '/Maps.i18n.namespaces.php';
69
	$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] 			= __DIR__ . '/Maps.i18n.alias.php';
70
71
	$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
72
73
	$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
74
75
	// Register the initialization function of Maps.
76
	$GLOBALS['wgExtensionFunctions'][] = function () {
77
78
		if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
79
			$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
80
		}
81
82
		Hooks::run( 'MappingServiceLoad' );
83
		Hooks::run( 'MappingFeatureLoad' );
84
85
		if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
86
			$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
87
			$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
88
		}
89
90
		return true;
91
	};
92
93
	$GLOBALS['wgHooks']['AdminLinks'][]                = 'MapsHooks::addToAdminLinks';
94
	$GLOBALS['wgHooks']['ArticleFromTitle'][]          = 'MapsHooks::onArticleFromTitle';
95
	$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
96
	$GLOBALS['wgHooks']['CanonicalNamespaces'][]       = 'MapsHooks::onCanonicalNamespaces';	$GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates';
97
	$GLOBALS['wgHooks']['ArticlePurge'][]              = 'MapsHooks::onArticlePurge';
98
	$GLOBALS['wgHooks']['LinksUpdateConstructed'][]    = 'MapsHooks::onLinksUpdateConstructed';
99
	$GLOBALS['wgHooks']['ParserAfterTidy'][]           = 'MapsHooks::onParserAfterTidy';
100
	$GLOBALS['wgHooks']['ParserClearState'][]          = 'MapsHooks::onParserClearState';
101
102
	// Parser hooks
103
104
	// Required for #coordinates.
105
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
106
		$instance = new MapsCoordinates();
107
		return $instance->init( $parser );
108
	};
109
110
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
111
		$instance = new MapsDisplayMap();
112
		return $instance->init( $parser );
113
	};
114
115
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
116
		$instance = new MapsDistance();
117
		return $instance->init( $parser );
118
	};
119
120
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
121
		$instance = new MapsFinddestination();
122
		return $instance->init( $parser );
123
	};
124
125
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
126
		$instance = new MapsGeocode();
127
		return $instance->init( $parser );
128
	};
129
130
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
131
		$instance = new MapsGeodistance();
132
		return $instance->init( $parser );
133
	};
134
135
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
136
		$instance = new MapsMapsDoc();
137
		return $instance->init( $parser );
138
	};
139
140
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
141
		$instance = new MapsLayerDefinition();
142
		return $instance->init( $parser );
143
	};
144
145
	// Geocoders
146
147
	// Registration of the GeoNames service geocoder.
148
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
149
150
	// Registration of the Google Geocoding (v2) service geocoder.
151
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
152
153
	// Registration of the geocoder.us service geocoder.
154
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
155
156
	// Layers
157
158
	// Registration of the image layer type.
159
	$GLOBALS['wgHooks']['MappingLayersInitialization'][] = 'MapsImageLayer::register';
160
161
	// Mapping services
162
163
	// Include the mapping services that should be loaded into Maps.
164
	// Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance.
165
166
	// Google Maps API v3
167
	// TODO: improve loading mechanism
168
	include_once $mapsDir . 'includes/services/GoogleMaps3/GoogleMaps3.php';
169
170
	// OpenLayers API
171
	// TODO: improve loading mechanism
172
	include_once $mapsDir . 'includes/services/OpenLayers/OpenLayers.php';
173
174
	// Leaflet API
175
	// TODO: improve loading mechanism
176
	include_once $mapsDir . 'includes/services/Leaflet/Leaflet.php';
177
178
179
	require_once __DIR__ . '/Maps_Settings.php';
180
181
	define( 'Maps_NS_LAYER' , $GLOBALS['egMapsNamespaceIndex'] + 0 );
182
	define( 'Maps_NS_LAYER_TALK' , $GLOBALS['egMapsNamespaceIndex'] + 1 );
183
184
	$GLOBALS['wgAvailableRights'][] = 'geocode';
185
186
	// Users that can geocode. By default the same as those that can edit.
187
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
188
		if ( array_key_exists( 'edit' , $rights ) ) {
189
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
190
		}
191
	}
192
193
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
194
		'string-parser' => 'DataValues\Geo\Parsers\GeoCoordinateParser',
195
	];
196
197
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
198
		'definition'=> 'Maps\ServiceParam',
199
	];
200
201
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
202
		'string-parser' => 'Maps\LocationParser',
203
	];
204
205
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
206
		'string-parser' => 'Maps\LineParser',
207
	];
208
209
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
210
		'string-parser' => 'Maps\CircleParser',
211
	];
212
213
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
214
		'string-parser' => 'Maps\RectangleParser',
215
	];
216
217
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
218
		'string-parser' => 'Maps\PolygonParser',
219
	];
220
221
	$GLOBALS['wgParamDefinitions']['distance'] = [
222
		'string-parser' => 'Maps\DistanceParser',
223
	];
224
225
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
226
		'string-parser' => 'Maps\WmsOverlayParser',
227
	];
228
229
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
230
		'string-parser' => 'Maps\ImageOverlayParser',
231
	];
232
} );
233