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