Completed
Pull Request — master (#131)
by None
10:16 queued 20s
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 35 and the first side effect is on line 15.

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