1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use DataValues\Geo\Parsers\GeoCoordinateParser; |
4
|
|
|
use Maps\ServiceParam; |
5
|
|
|
use Maps\LocationParser; |
6
|
|
|
use Maps\LineParser; |
7
|
|
|
use Maps\CircleParser; |
8
|
|
|
use Maps\RectangleParser; |
9
|
|
|
use Maps\PolygonParser; |
10
|
|
|
use Maps\DistanceParser; |
11
|
|
|
use Maps\WmsOverlayParser; |
12
|
|
|
use Maps\ImageOverlayParser; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Static class for hooks handled by the Maps extension. |
16
|
|
|
* |
17
|
|
|
* @since 0.7 |
18
|
|
|
* |
19
|
|
|
* @licence GNU GPL v2+ |
20
|
|
|
* @author Jeroen De Dauw < [email protected] > |
21
|
|
|
*/ |
22
|
|
|
final class MapsHooks { |
23
|
|
|
|
24
|
|
|
public static function onExtensionCallback() { |
|
|
|
|
25
|
|
|
if ( defined( 'Maps_COORDS_FLOAT' ) ) { |
26
|
|
|
// Do not initialize more than once. |
27
|
|
|
return 1; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// The different coordinate notations. |
31
|
|
|
define( 'Maps_COORDS_FLOAT' , 'float' ); |
32
|
|
|
define( 'Maps_COORDS_DMS' , 'dms' ); |
33
|
|
|
define( 'Maps_COORDS_DM' , 'dm' ); |
34
|
|
|
define( 'Maps_COORDS_DD' , 'dd' ); |
35
|
|
|
|
36
|
|
|
require_once __DIR__ . '/Maps_Settings.php'; |
37
|
|
|
|
38
|
|
|
define( 'Maps_VERSION' , '4.2.1' ); |
39
|
|
|
define( 'SM_VERSION', Maps_VERSION ); |
40
|
|
|
|
41
|
|
|
// Only initialize the extension when all dependencies are present. |
42
|
|
|
if ( !defined( 'Validator_VERSION' ) ) { |
43
|
|
|
throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
47
|
|
|
|
48
|
|
|
$GLOBALS['wgParamDefinitions']['coordinate'] = [ |
49
|
|
|
'string-parser' => GeoCoordinateParser::class, |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
$GLOBALS['wgParamDefinitions']['mappingservice'] = [ |
53
|
|
|
'definition'=> ServiceParam::class, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$GLOBALS['wgParamDefinitions']['mapslocation'] = [ |
57
|
|
|
'string-parser' => LocationParser::class, |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
$GLOBALS['wgParamDefinitions']['mapsline'] = [ |
61
|
|
|
'string-parser' => LineParser::class, |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$GLOBALS['wgParamDefinitions']['mapscircle'] = [ |
65
|
|
|
'string-parser' => CircleParser::class, |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
$GLOBALS['wgParamDefinitions']['mapsrectangle'] = [ |
69
|
|
|
'string-parser' => RectangleParser::class, |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
$GLOBALS['wgParamDefinitions']['mapspolygon'] = [ |
73
|
|
|
'string-parser' => PolygonParser::class, |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$GLOBALS['wgParamDefinitions']['distance'] = [ |
77
|
|
|
'string-parser' => DistanceParser::class, |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$GLOBALS['wgParamDefinitions']['wmsoverlay'] = [ |
81
|
|
|
'string-parser' => WmsOverlayParser::class, |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
$GLOBALS['wgParamDefinitions']['mapsimageoverlay'] = [ |
85
|
|
|
'string-parser' => ImageOverlayParser::class, |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
90
|
|
|
if ( $GLOBALS['egMapsDisableExtension'] ) { |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
if ( defined( 'Maps_VERSION' ) ) { |
94
|
|
|
// Do not initialize more than once. |
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Only initialize the extension when all dependencies are present. |
99
|
|
|
if ( !defined( 'Validator_VERSION' ) ) { |
100
|
|
|
throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
define( 'Maps_VERSION' , '4.2.1' ); |
104
|
|
|
define( 'SM_VERSION', Maps_VERSION ); |
105
|
|
|
|
106
|
|
|
if ( $GLOBALS['egMapsGMaps3Language'] === '' ) { |
107
|
|
|
$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang']; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class ); |
111
|
|
|
|
112
|
|
|
$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' ); |
113
|
|
|
$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
114
|
|
|
|
115
|
|
|
MapsMappingServices::registerService( |
116
|
|
|
'openlayers', |
117
|
|
|
MapsOpenLayers::class, |
118
|
|
|
[ 'display_map' => MapsDisplayMapRenderer::class ] |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class ); |
122
|
|
|
$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' ); |
123
|
|
|
$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
124
|
|
|
|
125
|
|
|
if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) { |
126
|
|
|
$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor'; |
127
|
|
|
$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
131
|
|
|
|
132
|
|
|
// Users that can geocode. By default the same as those that can edit. |
133
|
|
|
foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) { |
134
|
|
|
if ( array_key_exists( 'edit' , $rights ) ) { |
135
|
|
|
$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit']; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) { |
140
|
|
|
SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return true; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public static function onParserFirstCallInit1( Parser &$parser ) { |
147
|
|
|
$instance = new MapsCoordinates(); |
148
|
|
|
return $instance->init( $parser ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public static function onParserFirstCallInit2( Parser &$parser ) { |
152
|
|
|
$instance = new MapsDisplayMap(); |
153
|
|
|
return $instance->init( $parser ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public static function onParserFirstCallInit3( Parser &$parser ) { |
157
|
|
|
$instance = new MapsDistance(); |
158
|
|
|
return $instance->init( $parser ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public static function onParserFirstCallInit4( Parser &$parser ) { |
162
|
|
|
$instance = new MapsFinddestination(); |
163
|
|
|
return $instance->init( $parser ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public static function onParserFirstCallInit5( Parser &$parser ) { |
167
|
|
|
$instance = new MapsGeocode(); |
168
|
|
|
return $instance->init( $parser ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public static function onParserFirstCallInit6( Parser &$parser ) { |
172
|
|
|
$instance = new MapsGeodistance(); |
173
|
|
|
return $instance->init( $parser ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public static function onParserFirstCallInit7( Parser &$parser ) { |
177
|
|
|
$instance = new MapsMapsDoc(); |
178
|
|
|
return $instance->init( $parser ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Adds a link to Admin Links page. |
183
|
|
|
* |
184
|
|
|
* @since 0.7 |
185
|
|
|
* |
186
|
|
|
* @param ALTree $admin_links_tree |
187
|
|
|
* |
188
|
|
|
* @return boolean |
189
|
|
|
*/ |
190
|
|
|
public static function addToAdminLinks( ALTree &$admin_links_tree ) { |
191
|
|
|
$displaying_data_section = $admin_links_tree->getSection( wfMessage( 'smw_adminlinks_displayingdata' )->text() ); |
192
|
|
|
|
193
|
|
|
// Escape if SMW hasn't added links. |
194
|
|
|
if ( is_null( $displaying_data_section ) ) { |
195
|
|
|
return true; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
$smw_docu_row = $displaying_data_section->getRow( 'smw' ); |
199
|
|
|
|
200
|
|
|
$maps_docu_label = wfMessage( 'adminlinks_documentation', 'Maps' )->text(); |
201
|
|
|
$smw_docu_row->addItem( AlItem::newFromExternalLink( 'https://semantic-mediawiki.org/wiki/Maps', $maps_docu_label ) ); |
202
|
|
|
|
203
|
|
|
return true; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Adds global JavaScript variables. |
208
|
|
|
* |
209
|
|
|
* @since 1.0 |
210
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript |
211
|
|
|
* @param array &$vars Variables to be added into the output |
212
|
|
|
* @param OutputPage $outputPage OutputPage instance calling the hook |
213
|
|
|
* @return boolean true in all cases |
214
|
|
|
*/ |
215
|
|
|
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $outputPage ) { |
|
|
|
|
216
|
|
|
global $egMapsGlobalJSVars; |
217
|
|
|
|
218
|
|
|
$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS']; |
219
|
|
|
$vars[ 'egMapsAvailableServices' ] = $GLOBALS['egMapsAvailableServices']; |
220
|
|
|
|
221
|
|
|
$vars += $egMapsGlobalJSVars; |
222
|
|
|
|
223
|
|
|
return true; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: