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