forked from ProfessionalWiki/Maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maps.php
230 lines (177 loc) · 7.61 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
226
227
228
229
230
<?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 < [email protected] >
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'Not an entry point.' );
}
if ( defined( 'Maps_VERSION' ) ) {
// Do not initialize more than once.
return 1;
}
define( 'Maps_VERSION' , '3.6.0' );
// Include the composer autoloader if it is present.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once( __DIR__ . '/vendor/autoload.php' );
}
// 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.23c' , '<' ) ) {
throw new Exception(
'This version of Maps requires MediaWiki 1.23 or above; use Maps 3.5.x for older versions.'
. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
);
}
call_user_func( function() {
$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+'
];
// The different coordinate notations.
define( 'Maps_COORDS_FLOAT' , 'float' );
define( 'Maps_COORDS_DMS' , 'dms' );
define( 'Maps_COORDS_DM' , 'dm' );
define( 'Maps_COORDS_DD' , 'dd' );
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION;
// Internationalization
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
$GLOBALS['wgAPIModules']['geocode'] = 'Maps\Api\Geocode';
// Register the initialization function of Maps.
$GLOBALS['wgExtensionFunctions'][] = function () {
if ( $GLOBALS['egMapsGMaps3Language'] === '' ) {
$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang'];
}
Hooks::run( 'MappingServiceLoad' );
Hooks::run( 'MappingFeatureLoad' );
if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor';
$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps';
}
return true;
};
$GLOBALS['wgHooks']['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
$GLOBALS['wgHooks']['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
$GLOBALS['wgHooks']['CanonicalNamespaces'][] = 'MapsHooks::onCanonicalNamespaces'; $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates';
$GLOBALS['wgHooks']['ArticlePurge'][] = 'MapsHooks::onArticlePurge';
$GLOBALS['wgHooks']['LinksUpdateConstructed'][] = 'MapsHooks::onLinksUpdateConstructed';
$GLOBALS['wgHooks']['ParserAfterTidy'][] = 'MapsHooks::onParserAfterTidy';
$GLOBALS['wgHooks']['ParserClearState'][] = 'MapsHooks::onParserClearState';
// 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 );
};
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsLayerDefinition();
return $instance->init( $parser );
};
// Geocoders
// Registration of the GeoNames service geocoder.
$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
// Registration of the Google Geocoding (v2) service geocoder.
$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
// Registration of the geocoder.us service geocoder.
$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
// Layers
// Registration of the image layer type.
$GLOBALS['wgHooks']['MappingLayersInitialization'][] = 'MapsImageLayer::register';
// Mapping services
// Include the mapping services that should be loaded into Maps.
// Commenting or removing a mapping service will make Maps completely ignore it, and so improve performance.
// Google Maps API v3
// TODO: improve loading mechanism
include_once __DIR__ . '/includes/services/GoogleMaps3/GoogleMaps3.php';
// OpenLayers API
// TODO: improve loading mechanism
include_once __DIR__ . '/includes/services/OpenLayers/OpenLayers.php';
// Leaflet API
// TODO: improve loading mechanism
include_once __DIR__ . '/includes/services/Leaflet/Leaflet.php';
require_once __DIR__ . '/Maps_Settings.php';
define( 'Maps_NS_LAYER' , $GLOBALS['egMapsNamespaceIndex'] + 0 );
define( 'Maps_NS_LAYER_TALK' , $GLOBALS['egMapsNamespaceIndex'] + 1 );
$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' => 'DataValues\Geo\Parsers\GeoCoordinateParser',
];
$GLOBALS['wgParamDefinitions']['mappingservice'] = [
'definition'=> 'Maps\ServiceParam',
];
$GLOBALS['wgParamDefinitions']['mapslocation'] = [
'string-parser' => 'Maps\LocationParser',
];
$GLOBALS['wgParamDefinitions']['mapsline'] = [
'string-parser' => 'Maps\LineParser',
];
$GLOBALS['wgParamDefinitions']['mapscircle'] = [
'string-parser' => 'Maps\CircleParser',
];
$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [
'string-parser' => 'Maps\RectangleParser',
];
$GLOBALS['wgParamDefinitions']['mapspolygon'] = [
'string-parser' => 'Maps\PolygonParser',
];
$GLOBALS['wgParamDefinitions']['distance'] = [
'string-parser' => 'Maps\DistanceParser',
];
$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [
'string-parser' => 'Maps\WmsOverlayParser',
];
$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [
'string-parser' => 'Maps\ImageOverlayParser',
];
} );