1 | <?php |
||
33 | class MapsSetup { |
||
34 | |||
35 | private $mwGlobals; |
||
36 | |||
37 | public function __construct( array &$mwGlobals ) { |
||
40 | |||
41 | public function setup() { |
||
42 | $this->defaultSettings(); |
||
43 | $this->registerAllTheThings(); |
||
44 | |||
45 | if ( MapsFactory::globalInstance()->smwIntegrationIsEnabled() ) { |
||
46 | MapsFactory::globalInstance()->newSemanticMapsSetup( $this->mwGlobals )->initExtension(); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | private function defaultSettings() { |
||
67 | |||
68 | private function registerAllTheThings() { |
||
76 | |||
77 | 56 | private function registerParserHooks() { |
|
78 | if ( $this->mwGlobals['egMapsEnableCoordinateFunction'] ) { |
||
79 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
80 | 56 | return ( new CoordinatesFunction() )->init( $parser ); |
|
81 | }; |
||
82 | } |
||
83 | |||
84 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
85 | 56 | foreach ( [ 'display_map', 'display_point', 'display_points', 'display_line' ] as $hookName ) { |
|
86 | 56 | $parser->setFunctionHook( |
|
87 | 56 | $hookName, |
|
88 | 56 | function ( Parser $parser, PPFrame $frame, array $arguments ) { |
|
89 | 25 | $mapHtml = MapsFactory::globalInstance()->getDisplayMapFunction()->getMapHtmlForKeyValueStrings( |
|
90 | 25 | $parser, |
|
91 | 25 | array_map( |
|
92 | 25 | function ( $argument ) use ( $frame ) { |
|
93 | 25 | return $frame->expand( $argument ); |
|
94 | 25 | }, |
|
95 | $arguments |
||
96 | ) |
||
97 | ); |
||
98 | |||
99 | return [ |
||
100 | 25 | $mapHtml, |
|
101 | 'noparse' => true, |
||
102 | 'isHTML' => true, |
||
103 | ]; |
||
104 | 56 | }, |
|
105 | 56 | Parser::SFH_OBJECT_ARGS |
|
106 | ); |
||
107 | |||
108 | 56 | $parser->setHook( |
|
109 | 56 | $hookName, |
|
110 | 56 | function ( $text, array $arguments, Parser $parser ) { |
|
111 | 2 | if ( $text !== null ) { |
|
112 | 2 | $arguments[DisplayMapFunction::getDefaultParameters()[0]] = $text; |
|
113 | } |
||
114 | |||
115 | 2 | return MapsFactory::globalInstance()->getDisplayMapFunction()->getMapHtmlForParameterList( $parser, $arguments ); |
|
116 | 56 | } |
|
117 | ); |
||
118 | } |
||
119 | 56 | }; |
|
120 | |||
121 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
122 | 56 | return ( new DistanceFunction() )->init( $parser ); |
|
123 | }; |
||
124 | |||
125 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
126 | 56 | return ( new FindDestinationFunction() )->init( $parser ); |
|
127 | }; |
||
128 | |||
129 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
130 | 56 | return ( new GeocodeFunction() )->init( $parser ); |
|
131 | }; |
||
132 | |||
133 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
134 | 56 | return ( new GeoDistanceFunction() )->init( $parser ); |
|
135 | }; |
||
136 | |||
137 | 56 | $this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser &$parser ) { |
|
138 | 56 | return ( new MapsDocFunction() )->init( $parser ); |
|
139 | }; |
||
140 | } |
||
141 | |||
142 | private function registerPermissions() { |
||
143 | $this->mwGlobals['wgAvailableRights'][] = 'geocode'; |
||
144 | |||
145 | // Users that can geocode. By default the same as those that can edit. |
||
146 | foreach ( $this->mwGlobals['wgGroupPermissions'] as $group => $rights ) { |
||
147 | if ( array_key_exists( 'edit', $rights ) ) { |
||
148 | $this->mwGlobals['wgGroupPermissions'][$group]['geocode'] = $this->mwGlobals['wgGroupPermissions'][$group]['edit']; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | private function registerParameterTypes() { |
||
154 | $this->mwGlobals['wgParamDefinitions']['coordinate'] = [ |
||
155 | 'string-parser' => LatLongParser::class, |
||
156 | ]; |
||
157 | |||
158 | $this->mwGlobals['wgParamDefinitions']['mapslocation'] = [ |
||
159 | 'string-parser' => LocationParser::class, |
||
160 | ]; |
||
161 | |||
162 | $this->mwGlobals['wgParamDefinitions']['mapsline'] = [ |
||
163 | 'string-parser' => LineParser::class, |
||
164 | ]; |
||
165 | |||
166 | $this->mwGlobals['wgParamDefinitions']['mapscircle'] = [ |
||
167 | 'string-parser' => CircleParser::class, |
||
168 | ]; |
||
169 | |||
170 | $this->mwGlobals['wgParamDefinitions']['mapsrectangle'] = [ |
||
171 | 'string-parser' => RectangleParser::class, |
||
172 | ]; |
||
173 | |||
174 | $this->mwGlobals['wgParamDefinitions']['mapspolygon'] = [ |
||
175 | 'string-parser' => PolygonParser::class, |
||
176 | ]; |
||
177 | |||
178 | $this->mwGlobals['wgParamDefinitions']['distance'] = [ |
||
179 | 'string-parser' => DistanceParser::class, |
||
180 | ]; |
||
181 | |||
182 | $this->mwGlobals['wgParamDefinitions']['wmsoverlay'] = [ |
||
183 | 'string-parser' => WmsOverlayParser::class, |
||
184 | ]; |
||
185 | |||
186 | $this->mwGlobals['wgParamDefinitions']['mapsimageoverlay'] = [ |
||
187 | 'string-parser' => ImageOverlayParser::class, |
||
188 | ]; |
||
189 | } |
||
190 | |||
191 | private function registerHooks() { |
||
192 | $this->mwGlobals['wgHooks']['AdminLinks'][] = 'Maps\MediaWiki\MapsHooks::addToAdminLinks'; |
||
193 | $this->mwGlobals['wgHooks']['MakeGlobalVariablesScript'][] = 'Maps\MediaWiki\MapsHooks::onMakeGlobalVariablesScript'; |
||
194 | $this->mwGlobals['wgHooks']['SkinTemplateNavigation'][] = 'Maps\MediaWiki\MapsHooks::onSkinTemplateNavigation'; |
||
195 | $this->mwGlobals['wgHooks']['BeforeDisplayNoArticleText'][] = 'Maps\MediaWiki\MapsHooks::onBeforeDisplayNoArticleText'; |
||
196 | $this->mwGlobals['wgHooks']['ShowMissingArticle'][] = 'Maps\MediaWiki\MapsHooks::onShowMissingArticle'; |
||
197 | $this->mwGlobals['wgHooks']['ListDefinedTags'][] = 'Maps\MediaWiki\MapsHooks::onRegisterTags'; |
||
198 | $this->mwGlobals['wgHooks']['ChangeTagsListActive'][] = 'Maps\MediaWiki\MapsHooks::onRegisterTags'; |
||
199 | $this->mwGlobals['wgHooks']['ChangeTagsAllowedAdd'][] = 'Maps\MediaWiki\MapsHooks::onChangeTagsAllowedAdd'; |
||
200 | $this->mwGlobals['wgHooks']['ResourceLoaderTestModules'][] = 'Maps\MediaWiki\MapsHooks::onResourceLoaderTestModules'; |
||
201 | |||
202 | $this->mwGlobals['wgHooks']['CargoSetFormatClasses'][] = function( array &$formatClasses ) { |
||
203 | $formatClasses['map'] = CargoFormat::class; |
||
204 | }; |
||
205 | } |
||
206 | |||
207 | private function registerGeoJsonContentModel() { |
||
210 | |||
211 | private function registerEditApiModuleFallbacks() { |
||
212 | // mediawiki.api.edit is present in 1.31 but not 1.32 |
||
213 | // Once Maps requires MW 1.32+, this can be removed after replacing usage of mediawiki.api.edit |
||
214 | if ( version_compare( $this->mwGlobals['wgVersion'], '1.32', '>=' ) ) { |
||
215 | $this->mwGlobals['wgResourceModules']['mediawiki.api.edit'] = [ |
||
254 | |||
255 | } |
||
256 |