forked from ProfessionalWiki/Maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaps.php
226 lines (176 loc) · 6.86 KB
/
Maps.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
/**
* Initialization file for the Maps extension.
*
* @links https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps Documentation
* @links https://github.com/JeroenDeDauw/Maps/issues Support
* @links https://github.com/JeroenDeDauw/Maps Source code
*
* @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
use DataValues\Geo\Parsers\GeoCoordinateParser;
use Maps\CircleParser;
use Maps\DistanceParser;
use Maps\ImageOverlayParser;
use Maps\LineParser;
use Maps\LocationParser;
use Maps\PolygonParser;
use Maps\RectangleParser;
use Maps\SemanticMaps;
use Maps\ServiceParam;
use Maps\WmsOverlayParser;
if ( defined( 'Maps_COORDS_FLOAT' ) ) {
// Do not initialize more than once.
return 1;
}
// The different coordinate notations.
define( 'Maps_COORDS_FLOAT', 'float' );
define( 'Maps_COORDS_DMS', 'dms' );
define( 'Maps_COORDS_DM', 'dm' );
define( 'Maps_COORDS_DD', 'dd' );
require_once __DIR__ . '/Maps_Settings.php';
// Include the composer autoloader if it is present.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once( __DIR__ . '/vendor/autoload.php' );
}
// Internationalization
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
$GLOBALS['wgExtensionFunctions'][] = function() {
if ( $GLOBALS['egMapsDisableExtension'] ) {
return true;
}
if ( defined( 'Maps_VERSION' ) ) {
// Do not initialize more than once.
return true;
}
// Only initialize the extension when all dependencies are present.
if ( !defined( 'Validator_VERSION' ) ) {
throw new Exception( 'You need to have Validator installed in order to use Maps' );
}
if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) {
throw new Exception(
'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
);
}
define( 'Maps_VERSION', '5.3.0 alpha' );
define( 'SM_VERSION', Maps_VERSION );
if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
}
if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
}
$GLOBALS['wgExtensionCredits']['parserhook'][] = [
'path' => __FILE__,
'name' => 'Maps',
'version' => Maps_VERSION,
'author' => [
'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
'...'
],
'url' => 'https://github.com/JeroenDeDauw/Maps/blob/master/README.md#maps',
'descriptionmsg' => 'maps-desc',
'license-name' => 'GPL-2.0-or-later'
];
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
$GLOBALS['wgHooks']['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
// Parser hooks
// Required for #coordinates.
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsCoordinates();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsDisplayMap();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsDistance();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsFinddestination();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsGeocode();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsGeodistance();
return $instance->init( $parser );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsMapsDoc();
return $instance->init( $parser );
};
// Google Maps API v3
if ( $GLOBALS['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $GLOBALS ) ) {
$GLOBALS['egMapsGMaps3ApiKey'] = $GLOBALS['egGoogleJsApiKey'];
}
include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class );
$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' );
$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
// OpenLayers API
include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
MapsMappingServices::registerService(
'openlayers',
MapsOpenLayers::class,
[ 'display_map' => MapsDisplayMapRenderer::class ]
);
// Leaflet API
include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class );
$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class );
$GLOBALS['wgAvailableRights'][] = 'geocode';
// Users that can geocode. By default the same as those that can edit.
foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) {
if ( array_key_exists( 'edit', $rights ) ) {
$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit'];
}
}
$GLOBALS['wgParamDefinitions']['coordinate'] = [
'string-parser' => GeoCoordinateParser::class,
];
$GLOBALS['wgParamDefinitions']['mappingservice'] = [
'definition' => ServiceParam::class,
];
$GLOBALS['wgParamDefinitions']['mapslocation'] = [
'string-parser' => LocationParser::class,
];
$GLOBALS['wgParamDefinitions']['mapsline'] = [
'string-parser' => LineParser::class,
];
$GLOBALS['wgParamDefinitions']['mapscircle'] = [
'string-parser' => CircleParser::class,
];
$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
'string-parser' => RectangleParser::class,
];
$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
'string-parser' => PolygonParser::class,
];
$GLOBALS['wgParamDefinitions']['distance'] = [
'string-parser' => DistanceParser::class,
];
$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
'string-parser' => WmsOverlayParser::class,
];
$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
'string-parser' => ImageOverlayParser::class,
];
if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) {
SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension();
}
return true;
};