1 | <?php |
||
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 ) { |
||
150 | |||
151 | public static function onParserFirstCallInit2( Parser &$parser ) { |
||
155 | |||
156 | public static function onParserFirstCallInit3( Parser &$parser ) { |
||
160 | |||
161 | public static function onParserFirstCallInit4( Parser &$parser ) { |
||
165 | |||
166 | public static function onParserFirstCallInit5( Parser &$parser ) { |
||
170 | |||
171 | public static function onParserFirstCallInit6( Parser &$parser ) { |
||
175 | |||
176 | public static function onParserFirstCallInit7( Parser &$parser ) { |
||
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 ) { |
||
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 ) { |
||
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: