forked from ProfessionalWiki/Maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maps.php
226 lines (172 loc) · 7.19 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
<?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 http://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.1 alpha' );
// 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.18c' , '<' ) ) {
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.' );
}
call_user_func( function() {
global $wgExtensionCredits;
global $wgResourceModules, $wgGroupPermissions, $egMapsNamespaceIndex, $wgStyleVersion;
global $egMapsStyleVersion, $wgHooks, $wgExtensionMessagesFiles, $wgMessagesDirs;
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__ ,
'name' => 'Maps' ,
'version' => Maps_VERSION ,
'author' => array(
'[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'
);
// The different coordinate notations.
define( 'Maps_COORDS_FLOAT' , 'float' );
define( 'Maps_COORDS_DMS' , 'dms' );
define( 'Maps_COORDS_DM' , 'dm' );
define( 'Maps_COORDS_DD' , 'dd' );
$egMapsDir = __DIR__ . '/';
$egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
$wgMessagesDirs['Maps'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['Maps'] = __DIR__ . '/Maps.i18n.php';
$wgExtensionMessagesFiles['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
$wgExtensionMessagesFiles['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php';
$wgExtensionMessagesFiles['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';
$wgResourceModules = array_merge( $wgResourceModules, include 'Maps.resources.php' );
$wgAPIModules['geocode'] = 'Maps\Api\Geocode';
// Register the initialization function of Maps.
$GLOBALS['wgExtensionFunctions'][] = function () {
wfRunHooks( 'MappingServiceLoad' );
wfRunHooks( 'MappingFeatureLoad' );
if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) {
global $wgSpecialPages, $wgSpecialPageGroups;
$wgSpecialPages['MapEditor'] = 'SpecialMapEditor';
$wgSpecialPageGroups['MapEditor'] = 'maps';
}
return true;
};
$wgHooks['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
$wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
$wgHooks['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
$wgHooks['CanonicalNamespaces'][] = 'MapsHooks::onCanonicalNamespaces'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates';
$wgHooks['ArticlePurge'][] = 'MapsHooks::onArticlePurge';
$wgHooks['LinksUpdateConstructed'][] = 'MapsHooks::onLinksUpdateConstructed';
$wgHooks['ParserAfterTidy'][] = 'MapsHooks::onParserAfterTidy';
$wgHooks['ParserClearState'][] = 'MapsHooks::onParserClearState';
// Parser hooks
// Required for #coordinates.
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsCoordinates();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsDisplayMap();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsDistance();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsFinddestination();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsGeocode();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsGeodistance();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsMapsDoc();
return $instance->init( $parser );
};
$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsLayerDefinition();
return $instance->init( $parser );
};
// Geocoders
// Registration of the GeoNames service geocoder.
$wgHooks['GeocoderFirstCallInit'][] = 'MapsGeonamesGeocoder::register';
// Registration of the Google Geocoding (v2) service geocoder.
$wgHooks['GeocoderFirstCallInit'][] = 'MapsGoogleGeocoder::register';
// Registration of the geocoder.us service geocoder.
$wgHooks['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';
// Layers
// Registration of the image layer type.
$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 $egMapsDir . 'includes/services/GoogleMaps3/GoogleMaps3.php';
// OpenLayers API
// TODO: improve loading mechanism
include_once $egMapsDir . 'includes/services/OpenLayers/OpenLayers.php';
// Leaflet API
// TODO: improve loading mechanism
include_once $egMapsDir . 'includes/services/Leaflet/Leaflet.php';
require_once __DIR__ . '/Maps_Settings.php';
define( 'Maps_NS_LAYER' , $egMapsNamespaceIndex + 0 );
define( 'Maps_NS_LAYER_TALK' , $egMapsNamespaceIndex + 1 );
$wgAvailableRights[] = 'geocode';
// Users that can geocode. By default the same as those that can edit.
foreach ( $wgGroupPermissions as $group => $rights ) {
if ( array_key_exists( 'edit' , $rights ) ) {
$wgGroupPermissions[$group]['geocode'] = $wgGroupPermissions[$group]['edit'];
}
}
global $wgParamDefinitions;
$wgParamDefinitions['mappingservice'] = array(
'definition'=> 'Maps\ServiceParam',
);
$wgParamDefinitions['mapslocation'] = array(
'string-parser' => 'Maps\LocationParser',
);
$wgParamDefinitions['mapsline'] = array(
'string-parser' => 'Maps\LineParser',
);
$wgParamDefinitions['mapscircle'] = array(
'string-parser' => 'Maps\CircleParser',
);
$wgParamDefinitions['mapsrectangle'] = array(
'string-parser' => 'Maps\RectangleParser',
);
$wgParamDefinitions['mapspolygon'] = array(
'string-parser' => 'Maps\PolygonParser',
);
$wgParamDefinitions['distance'] = array(
'string-parser' => 'Maps\DistanceParser',
);
$wgParamDefinitions['wmsoverlay'] = array(
'string-parser' => 'Maps\WmsOverlayParser',
);
$wgParamDefinitions['mapsimageoverlay'] = array(
'string-parser' => 'Maps\ImageOverlayParser',
);
} );