1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Static class for hooks handled by the Maps extension. |
5
|
|
|
* |
6
|
|
|
* @since 0.7 |
7
|
|
|
* |
8
|
|
|
* @licence GNU GPL v2+ |
9
|
|
|
* @author Jeroen De Dauw < [email protected] > |
10
|
|
|
*/ |
11
|
|
|
final class MapsHooks { |
12
|
|
|
|
13
|
|
|
public static function onExtensionCallback() { |
|
|
|
|
14
|
|
|
if ( defined( 'Maps_COORDS_FLOAT' ) ) { |
15
|
|
|
// Do not initialize more than once. |
16
|
|
|
return 1; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// The different coordinate notations. |
20
|
|
|
define( 'Maps_COORDS_FLOAT' , 'float' ); |
21
|
|
|
define( 'Maps_COORDS_DMS' , 'dms' ); |
22
|
|
|
define( 'Maps_COORDS_DM' , 'dm' ); |
23
|
|
|
define( 'Maps_COORDS_DD' , 'dd' ); |
24
|
|
|
|
25
|
|
|
require_once __DIR__ . '/Maps_Settings.php'; |
26
|
|
|
|
27
|
|
|
define( 'Maps_VERSION' , '4.2.1' ); |
28
|
|
|
define( 'SM_VERSION', Maps_VERSION ); |
29
|
|
|
|
30
|
|
|
// Only initialize the extension when all dependencies are present. |
31
|
|
|
if ( !defined( 'Validator_VERSION' ) ) { |
32
|
|
|
throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
39
|
|
|
if ( $GLOBALS['egMapsDisableExtension'] ) { |
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
if ( defined( 'Maps_VERSION' ) ) { |
43
|
|
|
// Do not initialize more than once. |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Only initialize the extension when all dependencies are present. |
48
|
|
|
if ( !defined( 'Validator_VERSION' ) ) { |
49
|
|
|
throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
define( 'Maps_VERSION' , '4.2.1' ); |
53
|
|
|
define( 'SM_VERSION', Maps_VERSION ); |
54
|
|
|
|
55
|
|
|
if ( $GLOBALS['egMapsGMaps3Language'] === '' ) { |
56
|
|
|
$GLOBALS['egMapsGMaps3Language'] = $GLOBALS['wgLang']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class ); |
60
|
|
|
|
61
|
|
|
$googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' ); |
62
|
|
|
$googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
63
|
|
|
|
64
|
|
|
MapsMappingServices::registerService( |
65
|
|
|
'openlayers', |
66
|
|
|
MapsOpenLayers::class, |
67
|
|
|
[ 'display_map' => MapsDisplayMapRenderer::class ] |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class ); |
71
|
|
|
$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' ); |
72
|
|
|
$leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
73
|
|
|
|
74
|
|
|
if ( in_array( 'googlemaps3', $GLOBALS['egMapsAvailableServices'] ) ) { |
75
|
|
|
$GLOBALS['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor'; |
76
|
|
|
$GLOBALS['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$GLOBALS['egMapsStyleVersion'] = $GLOBALS['wgStyleVersion'] . '-' . Maps_VERSION; |
80
|
|
|
|
81
|
|
|
// Users that can geocode. By default the same as those that can edit. |
82
|
|
|
foreach ( $GLOBALS['wgGroupPermissions'] as $group => $rights ) { |
83
|
|
|
if ( array_key_exists( 'edit' , $rights ) ) { |
84
|
|
|
$GLOBALS['wgGroupPermissions'][$group]['geocode'] = $GLOBALS['wgGroupPermissions'][$group]['edit']; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ( !$GLOBALS['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) { |
89
|
|
|
SemanticMaps::newFromMediaWikiGlobals( $GLOBALS )->initExtension(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public static function onParserFirstCallInit1( Parser &$parser ) { |
96
|
|
|
$instance = new MapsCoordinates(); |
97
|
|
|
return $instance->init( $parser ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function onParserFirstCallInit2( Parser &$parser ) { |
101
|
|
|
$instance = new MapsDisplayMap(); |
102
|
|
|
return $instance->init( $parser ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function onParserFirstCallInit3( Parser &$parser ) { |
106
|
|
|
$instance = new MapsDistance(); |
107
|
|
|
return $instance->init( $parser ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public static function onParserFirstCallInit4( Parser &$parser ) { |
111
|
|
|
$instance = new MapsFinddestination(); |
112
|
|
|
return $instance->init( $parser ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public static function onParserFirstCallInit5( Parser &$parser ) { |
116
|
|
|
$instance = new MapsGeocode(); |
117
|
|
|
return $instance->init( $parser ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public static function onParserFirstCallInit6( Parser &$parser ) { |
121
|
|
|
$instance = new MapsGeodistance(); |
122
|
|
|
return $instance->init( $parser ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public static function onParserFirstCallInit7( Parser &$parser ) { |
126
|
|
|
$instance = new MapsMapsDoc(); |
127
|
|
|
return $instance->init( $parser ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Adds a link to Admin Links page. |
132
|
|
|
* |
133
|
|
|
* @since 0.7 |
134
|
|
|
* |
135
|
|
|
* @param ALTree $admin_links_tree |
136
|
|
|
* |
137
|
|
|
* @return boolean |
138
|
|
|
*/ |
139
|
|
|
public static function addToAdminLinks( ALTree &$admin_links_tree ) { |
140
|
|
|
$displaying_data_section = $admin_links_tree->getSection( wfMessage( 'smw_adminlinks_displayingdata' )->text() ); |
141
|
|
|
|
142
|
|
|
// Escape if SMW hasn't added links. |
143
|
|
|
if ( is_null( $displaying_data_section ) ) { |
144
|
|
|
return true; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$smw_docu_row = $displaying_data_section->getRow( 'smw' ); |
148
|
|
|
|
149
|
|
|
$maps_docu_label = wfMessage( 'adminlinks_documentation', 'Maps' )->text(); |
150
|
|
|
$smw_docu_row->addItem( AlItem::newFromExternalLink( 'https://semantic-mediawiki.org/wiki/Maps', $maps_docu_label ) ); |
151
|
|
|
|
152
|
|
|
return true; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Adds global JavaScript variables. |
157
|
|
|
* |
158
|
|
|
* @since 1.0 |
159
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript |
160
|
|
|
* @param array &$vars Variables to be added into the output |
161
|
|
|
* @param OutputPage $outputPage OutputPage instance calling the hook |
162
|
|
|
* @return boolean true in all cases |
163
|
|
|
*/ |
164
|
|
|
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $outputPage ) { |
|
|
|
|
165
|
|
|
global $egMapsGlobalJSVars; |
166
|
|
|
|
167
|
|
|
$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS']; |
168
|
|
|
$vars[ 'egMapsAvailableServices' ] = $GLOBALS['egMapsAvailableServices']; |
169
|
|
|
|
170
|
|
|
$vars += $egMapsGlobalJSVars; |
171
|
|
|
|
172
|
|
|
return true; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
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: