Completed
Pull Request — master (#54)
by Peter
07:18
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' );
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
	$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
62
63
	// Internationalization
64
	$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
65
	$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
66
	$GLOBALS['wgExtensionMessagesFiles']['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php';
67
	$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
68
69
	$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
70
71
	$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
72
73
	// Register the initialization function of Maps.
74
	$GLOBALS['wgExtensionFunctions'][] = function () {
75
76
		if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
77
			$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
78
		}
79
80
		Hooks::run( 'MappingServiceLoad' );
81
		Hooks::run( 'MappingFeatureLoad' );
82
83
		if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
84
			$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
85
			$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
86
		}
87
88
		return true;
89
	};
90
91
	$GLOBALS['wgHooks']['AdminLinks'][]                = 'MapsHooks::addToAdminLinks';
92
	$GLOBALS['wgHooks']['ArticleFromTitle'][]          = 'MapsHooks::onArticleFromTitle';
93
	$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
94
	$GLOBALS['wgHooks']['CanonicalNamespaces'][]       = 'MapsHooks::onCanonicalNamespaces';	$GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates';
95
	$GLOBALS['wgHooks']['ArticlePurge'][]              = 'MapsHooks::onArticlePurge';
96
	$GLOBALS['wgHooks']['LinksUpdateConstructed'][]    = 'MapsHooks::onLinksUpdateConstructed';
97
	$GLOBALS['wgHooks']['ParserAfterTidy'][]           = 'MapsHooks::onParserAfterTidy';
98
	$GLOBALS['wgHooks']['ParserClearState'][]          = 'MapsHooks::onParserClearState';
99
100
	// Parser hooks
101
102
	// Required for #coordinates.
103
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
104
		$instance = new MapsCoordinates();
105
		return $instance->init( $parser );
106
	};
107
108
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
109
		$instance = new MapsDisplayMap();
110
		return $instance->init( $parser );
111
	};
112
113
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
114
		$instance = new MapsDistance();
115
		return $instance->init( $parser );
116
	};
117
118
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
119
		$instance = new MapsFinddestination();
120
		return $instance->init( $parser );
121
	};
122
123
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
124
		$instance = new MapsGeocode();
125
		return $instance->init( $parser );
126
	};
127
128
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
129
		$instance = new MapsGeodistance();
130
		return $instance->init( $parser );
131
	};
132
133
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
134
		$instance = new MapsMapsDoc();
135
		return $instance->init( $parser );
136
	};
137
138
	$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
139
		$instance = new MapsLayerDefinition();
140
		return $instance->init( $parser );
141
	};
142
143
	// Geocoders
144
145
	// Registration of the GeoNames service geocoder.
146
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
147
148
	// Registration of the Google Geocoding (v2) service geocoder.
149
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
150
151
	// Registration of the geocoder.us service geocoder.
152
	$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
153
154
	// Layers
155
156
	// Registration of the image layer type.
157
	$GLOBALS['wgHooks']['MappingLayersInitialization'][] = 'MapsImageLayer::register';
158
159
	// Mapping services
160
161
	// Include the mapping services that should be loaded into Maps.
162
	// Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance.
163
164
	// Google Maps API v3
165
	// TODO: improve loading mechanism
166
	include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
167
168
	// OpenLayers API
169
	// TODO: improve loading mechanism
170
	include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
171
172
	// Leaflet API
173
	// TODO: improve loading mechanism
174
	include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
175
176
177
	require_once __DIR__ . '/Maps_Settings.php';
178
179
	define( 'Maps_NS_LAYER' , $GLOBALS['egMapsNamespaceIndex'] + 0 );
180
	define( 'Maps_NS_LAYER_TALK' , $GLOBALS['egMapsNamespaceIndex'] + 1 );
181
182
	$GLOBALS['wgAvailableRights'][] = 'geocode';
183
184
	// Users that can geocode. By default the same as those that can edit.
185
	foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
186
		if ( array_key_exists( 'edit' , $rights ) ) {
187
			$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
188
		}
189
	}
190
191
	$GLOBALS['wgParamDefinitions']['coordinate'] = [
192
		'string-parser' => 'DataValues\Geo\Parsers\GeoCoordinateParser',
193
	];
194
195
	$GLOBALS['wgParamDefinitions']['mappingservice'] = [
196
		'definition'=> 'Maps\ServiceParam',
197
	];
198
199
	$GLOBALS['wgParamDefinitions']['mapslocation'] = [
200
		'string-parser' => 'Maps\LocationParser',
201
	];
202
203
	$GLOBALS['wgParamDefinitions']['mapsline'] = [
204
		'string-parser' => 'Maps\LineParser',
205
	];
206
207
	$GLOBALS['wgParamDefinitions']['mapscircle'] = [
208
		'string-parser' => 'Maps\CircleParser',
209
	];
210
211
	$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
212
		'string-parser' => 'Maps\RectangleParser',
213
	];
214
215
	$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
216
		'string-parser' => 'Maps\PolygonParser',
217
	];
218
219
	$GLOBALS['wgParamDefinitions']['distance'] = [
220
		'string-parser' => 'Maps\DistanceParser',
221
	];
222
223
	$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
224
		'string-parser' => 'Maps\WmsOverlayParser',
225
	];
226
227
	$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
228
		'string-parser' => 'Maps\ImageOverlayParser',
229
	];
230
} );
231