Completed
Push — issue169 ( 58d03b )
by
unknown
02:48
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 25.

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