1 | <?php |
||
29 | class MapsSetup { |
||
30 | |||
31 | private $mwGlobals; |
||
32 | |||
33 | public function __construct( array &$mwGlobals ) { |
||
34 | $this->mwGlobals = $mwGlobals; |
||
35 | } |
||
36 | |||
37 | public function setup() { |
||
38 | $this->defaultSettings(); |
||
39 | $this->registerAllTheThings(); |
||
40 | |||
41 | if ( !$this->mwGlobals['egMapsDisableSmwIntegration'] && defined( 'SMW_VERSION' ) ) { |
||
42 | SemanticMaps::newFromMediaWikiGlobals( $this->mwGlobals )->initExtension(); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | private function registerAllTheThings() { |
||
57 | |||
58 | private function defaultSettings() { |
||
59 | if ( $this->mwGlobals['egMapsGMaps3Language'] === '' ) { |
||
60 | $this->mwGlobals['egMapsGMaps3Language'] = $this->mwGlobals['wgLang']; |
||
61 | } |
||
62 | |||
63 | if ( in_array( 'googlemaps3', $this->mwGlobals['egMapsAvailableServices'] ) ) { |
||
64 | $this->mwGlobals['wgSpecialPages']['MapEditor'] = 'SpecialMapEditor'; |
||
65 | $this->mwGlobals['wgSpecialPageGroups']['MapEditor'] = 'Maps'; |
||
66 | } |
||
67 | |||
68 | if ( $this->mwGlobals['egMapsGMaps3ApiKey'] === '' && array_key_exists( 'egGoogleJsApiKey', $this->mwGlobals ) ) { |
||
69 | $this->mwGlobals['egMapsGMaps3ApiKey'] = $this->mwGlobals['egGoogleJsApiKey']; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | private function registerWebResources() { |
||
74 | $this->mwGlobals['wgResourceModules'] = array_merge( |
||
75 | $this->mwGlobals['wgResourceModules'], |
||
76 | include __DIR__ . '/../Maps.resources.php' |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | private function registerParserHooks() { |
||
81 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
82 | 26 | $instance = new MapsCoordinates(); |
|
83 | 26 | return $instance->init( $parser ); |
|
84 | }; |
||
85 | |||
86 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
87 | 26 | foreach ( [ 'display_map', 'display_point', 'display_points', 'display_line' ] as $hookName ) { |
|
88 | 26 | $parser->setFunctionHook( |
|
89 | 26 | $hookName, |
|
90 | 26 | function( Parser $parser, PPFrame $frame, array $arguments ) { |
|
91 | 17 | $hook = new MapsDisplayMap(); |
|
92 | |||
93 | 17 | $mapHtml = $hook->getMapHtmlForKeyValueStrings( |
|
94 | 17 | $parser, |
|
95 | 17 | array_map( |
|
96 | 17 | function( $argument ) use ( $frame ) { |
|
97 | 17 | return $frame->expand( $argument ); |
|
98 | 17 | }, |
|
99 | 17 | $arguments |
|
100 | ) |
||
101 | ); |
||
102 | |||
103 | return [ |
||
104 | 17 | $mapHtml, |
|
105 | 'noparse' => true, |
||
106 | 'isHTML' => true, |
||
107 | ]; |
||
108 | 26 | }, |
|
109 | 26 | Parser::SFH_OBJECT_ARGS |
|
110 | ); |
||
111 | |||
112 | 26 | $parser->setHook( |
|
113 | 26 | $hookName, |
|
114 | 26 | function( $text, array $arguments, Parser $parser ) { |
|
115 | 2 | if ( $text !== null ) { |
|
116 | 2 | $defaultParameters = MapsDisplayMap::getHookDefinition( "\n" )->getDefaultParameters(); |
|
117 | 2 | $defaultParam = array_shift( $defaultParameters ); |
|
118 | |||
119 | // If there is a first default parameter, set the tag contents as its value. |
||
120 | 2 | if ( $defaultParam !== null ) { |
|
121 | 2 | $arguments[$defaultParam] = $text; |
|
122 | } |
||
123 | } |
||
124 | |||
125 | 2 | return ( new MapsDisplayMap() )->getMapHtmlForParameterList( $parser, $arguments ); |
|
126 | 26 | } |
|
127 | ); |
||
128 | } |
||
129 | 26 | }; |
|
130 | |||
131 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
132 | 26 | return ( new MapsDistance() )->init( $parser ); |
|
133 | }; |
||
134 | |||
135 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
136 | 26 | return ( new MapsFinddestination() )->init( $parser ); |
|
137 | }; |
||
138 | |||
139 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
140 | 26 | return ( new MapsGeocode() )->init( $parser ); |
|
141 | }; |
||
142 | |||
143 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
144 | 26 | return ( new MapsGeodistance() )->init( $parser ); |
|
145 | }; |
||
146 | |||
147 | 26 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { |
|
148 | 26 | return ( new MapsMapsDoc() )->init( $parser ); |
|
149 | }; |
||
150 | } |
||
151 | |||
152 | private function registerMappingServices() { |
||
153 | include_once __DIR__ . '/../includes/services/GoogleMaps3/GoogleMaps3.php'; |
||
154 | |||
155 | MapsMappingServices::registerService( 'googlemaps3', MapsGoogleMaps3::class ); |
||
156 | |||
157 | $googleMaps = MapsMappingServices::getServiceInstance( 'googlemaps3' ); |
||
158 | $googleMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
||
159 | |||
160 | |||
161 | // OpenLayers API |
||
162 | include_once __DIR__ . '/../includes/services/OpenLayers/OpenLayers.php'; |
||
163 | |||
164 | MapsMappingServices::registerService( |
||
165 | 'openlayers', |
||
166 | MapsOpenLayers::class |
||
167 | ); |
||
168 | |||
169 | $openLayers = MapsMappingServices::getServiceInstance( 'openlayers' ); |
||
170 | $openLayers->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
||
171 | |||
172 | |||
173 | // Leaflet API |
||
174 | include_once __DIR__ . '/../includes/services/Leaflet/Leaflet.php'; |
||
175 | |||
176 | MapsMappingServices::registerService( 'leaflet', MapsLeaflet::class ); |
||
177 | $leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' ); |
||
178 | $leafletMaps->addFeature( 'display_map', MapsDisplayMapRenderer::class ); |
||
179 | } |
||
180 | |||
181 | private function registerPermissions() { |
||
191 | |||
192 | private function registerParameterTypes() { |
||
193 | $this->mwGlobals['wgParamDefinitions']['coordinate'] = [ |
||
194 | 'string-parser' => LatLongParser::class, |
||
195 | ]; |
||
196 | |||
197 | $this->mwGlobals['wgParamDefinitions']['mapslocation'] = [ |
||
233 | |||
234 | private function registerHooks() { |
||
238 | |||
239 | private function registerApiModules() { |
||
242 | |||
243 | } |
||
244 |