1 | <?php |
||
35 | class MapsSetup { |
||
36 | |||
37 | private $mwGlobals; |
||
38 | |||
39 | public function __construct( array &$mwGlobals ) { |
||
42 | |||
43 | public function setup() { |
||
51 | |||
52 | private function registerAllTheThings() { |
||
63 | |||
64 | private function defaultSettings() { |
||
81 | |||
82 | private function registerWebResources() { |
||
88 | |||
89 | 49 | private function registerParserHooks() { |
|
90 | if ( $this->mwGlobals['egMapsEnableCoordinateFunction'] ) { |
||
91 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
92 | 49 | return ( new CoordinatesFunction() )->init( $parser ); |
|
93 | }; |
||
94 | } |
||
95 | |||
96 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
97 | 49 | foreach ( [ 'display_map', 'display_point', 'display_points', 'display_line' ] as $hookName ) { |
|
98 | 49 | $parser->setFunctionHook( |
|
99 | 49 | $hookName, |
|
100 | 49 | function ( Parser $parser, PPFrame $frame, array $arguments ) { |
|
101 | 18 | $mapHtml = MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForKeyValueStrings( |
|
102 | 18 | $parser, |
|
103 | 18 | array_map( |
|
104 | 18 | function ( $argument ) use ( $frame ) { |
|
105 | 18 | return $frame->expand( $argument ); |
|
106 | 18 | }, |
|
107 | 18 | $arguments |
|
108 | ) |
||
109 | ); |
||
110 | |||
111 | return [ |
||
112 | 18 | $mapHtml, |
|
113 | 'noparse' => true, |
||
114 | 'isHTML' => true, |
||
115 | ]; |
||
116 | 49 | }, |
|
117 | 49 | Parser::SFH_OBJECT_ARGS |
|
118 | ); |
||
119 | |||
120 | 49 | $parser->setHook( |
|
121 | 49 | $hookName, |
|
122 | 49 | function ( $text, array $arguments, Parser $parser ) { |
|
123 | 2 | if ( $text !== null ) { |
|
124 | 2 | $defaultParameters = DisplayMapFunction::getHookDefinition( "\n" )->getDefaultParameters(); |
|
125 | 2 | $defaultParam = array_shift( $defaultParameters ); |
|
126 | |||
127 | // If there is a first default parameter, set the tag contents as its value. |
||
128 | 2 | if ( $defaultParam !== null ) { |
|
129 | 2 | $arguments[$defaultParam] = $text; |
|
130 | } |
||
131 | } |
||
132 | |||
133 | 2 | return MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForParameterList( $parser, $arguments ); |
|
134 | 49 | } |
|
135 | ); |
||
136 | } |
||
137 | 49 | }; |
|
138 | |||
139 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
140 | 49 | return ( new DistanceFunction() )->init( $parser ); |
|
141 | }; |
||
142 | |||
143 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
144 | 49 | return ( new FindDestinationFunction() )->init( $parser ); |
|
145 | }; |
||
146 | |||
147 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
148 | 49 | return ( new GeocodeFunction() )->init( $parser ); |
|
149 | }; |
||
150 | |||
151 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
152 | 49 | return ( new GeoDistanceFunction() )->init( $parser ); |
|
153 | }; |
||
154 | |||
155 | 49 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
156 | 49 | return ( new MapsDocFunction() )->init( $parser ); |
|
157 | }; |
||
158 | } |
||
159 | |||
160 | private function registerMappingServices() { |
||
161 | $localBasePath = __DIR__ . '/../resources'; |
||
162 | $remoteExtPath = 'Maps/resources'; |
||
163 | |||
164 | $this->registerGoogleMapsModules( $localBasePath, $remoteExtPath ); |
||
165 | |||
166 | $this->registerLeafletModules( $localBasePath, $remoteExtPath ); |
||
167 | } |
||
168 | |||
169 | private function registerGoogleMapsModules( string $localBasePath, string $remoteExtPath ) { |
||
170 | global $wgResourceModules; |
||
171 | |||
172 | $localBasePath = $localBasePath . '/GoogleMaps'; |
||
173 | $remoteExtPath = $remoteExtPath . '/GoogleMaps'; |
||
174 | |||
175 | $wgResourceModules['ext.maps.googlemaps3'] = [ |
||
176 | 'dependencies' => [ 'ext.maps.common' ], |
||
177 | 'localBasePath' => $localBasePath, |
||
178 | 'remoteExtPath' => $remoteExtPath, |
||
179 | 'group' => 'ext.maps', |
||
180 | 'targets' => [ |
||
181 | 'mobile', |
||
182 | 'desktop' |
||
183 | ], |
||
184 | 'scripts' => [ |
||
185 | 'jquery.googlemap.js', |
||
186 | 'ext.maps.googlemaps3.js' |
||
187 | ], |
||
188 | 'messages' => [ |
||
189 | 'maps-googlemaps3-incompatbrowser', |
||
190 | 'maps-copycoords-prompt', |
||
191 | 'maps-searchmarkers-text', |
||
192 | 'maps-fullscreen-button', |
||
193 | 'maps-fullscreen-button-tooltip', |
||
194 | ] |
||
195 | ]; |
||
196 | |||
197 | $wgResourceModules['ext.maps.gm3.markercluster'] = [ |
||
198 | 'localBasePath' => $localBasePath . '/gm3-util-library', |
||
199 | 'remoteExtPath' => $remoteExtPath . '/gm3-util-library', |
||
200 | 'group' => 'ext.maps', |
||
201 | 'targets' => [ |
||
202 | 'mobile', |
||
203 | 'desktop' |
||
204 | ], |
||
205 | 'scripts' => [ |
||
206 | 'markerclusterer.js', |
||
207 | ], |
||
208 | ]; |
||
209 | |||
210 | $wgResourceModules['ext.maps.gm3.markerwithlabel'] = [ |
||
211 | 'localBasePath' => $localBasePath . '/gm3-util-library', |
||
212 | 'remoteExtPath' => $remoteExtPath . '/gm3-util-library', |
||
213 | 'group' => 'ext.maps', |
||
214 | 'targets' => [ |
||
215 | 'mobile', |
||
216 | 'desktop' |
||
217 | ], |
||
218 | 'scripts' => [ |
||
219 | 'markerwithlabel.js', |
||
220 | ], |
||
221 | 'styles' => [ |
||
222 | 'markerwithlabel.css', |
||
223 | ], |
||
224 | ]; |
||
225 | |||
226 | $wgResourceModules['ext.maps.gm3.geoxml'] = [ |
||
227 | 'localBasePath' => $localBasePath . '/geoxml3', |
||
228 | 'remoteExtPath' => $remoteExtPath, |
||
229 | 'group' => 'ext.maps' . '/geoxml3', |
||
230 | 'targets' => [ |
||
231 | 'mobile', |
||
232 | 'desktop' |
||
233 | ], |
||
234 | 'scripts' => [ |
||
235 | 'geoxml3.js', |
||
236 | 'ZipFile.complete.js', //kmz handling |
||
237 | 'ProjectedOverlay.js', //Overlay handling |
||
238 | ], |
||
239 | ]; |
||
240 | |||
241 | $wgResourceModules['ext.maps.gm3.earth'] = [ |
||
242 | 'localBasePath' => $localBasePath . '/gm3-util-library', |
||
243 | 'remoteExtPath' => $remoteExtPath . '/gm3-util-library', |
||
244 | 'group' => 'ext.maps', |
||
245 | 'targets' => [ |
||
246 | 'mobile', |
||
247 | 'desktop' |
||
248 | ], |
||
249 | 'scripts' => [ |
||
250 | 'googleearth-compiled.js', |
||
251 | ], |
||
252 | ]; |
||
253 | |||
254 | $wgResourceModules['ext.sm.googlemaps3ajax'] = [ |
||
255 | 'localBasePath' => $localBasePath, |
||
256 | 'remoteExtPath' => $remoteExtPath, |
||
257 | 'group' => 'ext.semanticmaps', |
||
258 | 'dependencies' => [ |
||
259 | 'ext.maps.googlemaps3', |
||
260 | 'ext.sm.common' |
||
261 | ], |
||
262 | 'scripts' => [ |
||
263 | 'ext.sm.googlemaps3ajax.js' |
||
264 | ] |
||
265 | ]; |
||
266 | } |
||
267 | |||
268 | private function registerLeafletModules( string $localBasePath, string $remoteExtPath ) { |
||
393 | |||
394 | private function registerPermissions() { |
||
404 | |||
405 | private function registerParameterTypes() { |
||
446 | |||
447 | private function registerHooks() { |
||
451 | |||
452 | private function registerApiModules() { |
||
455 | |||
456 | } |
||
457 |