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