1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps; |
6
|
|
|
|
7
|
|
|
use DataValues\Geo\Parsers\LatLongParser; |
8
|
|
|
use Maps\GeoJsonPages\GeoJsonContent; |
9
|
|
|
use Maps\GeoJsonPages\GeoJsonContentHandler; |
10
|
|
|
use Maps\LegacyMapEditor\SpecialMapEditor; |
11
|
|
|
use Maps\Map\CargoFormat\CargoFormat; |
12
|
|
|
use Maps\WikitextParsers\CircleParser; |
13
|
|
|
use Maps\WikitextParsers\DistanceParser; |
14
|
|
|
use Maps\WikitextParsers\ImageOverlayParser; |
15
|
|
|
use Maps\WikitextParsers\LineParser; |
16
|
|
|
use Maps\WikitextParsers\LocationParser; |
17
|
|
|
use Maps\WikitextParsers\PolygonParser; |
18
|
|
|
use Maps\WikitextParsers\RectangleParser; |
19
|
|
|
use Maps\WikitextParsers\WmsOverlayParser; |
20
|
|
|
use Parser; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @licence GNU GPL v2+ |
24
|
|
|
* @author Jeroen De Dauw < [email protected] > |
25
|
|
|
*/ |
26
|
|
|
class MapsSetup { |
27
|
|
|
|
28
|
|
|
private $mwGlobals; |
29
|
|
|
|
30
|
|
|
public function __construct( array &$mwGlobals ) { |
31
|
|
|
$this->mwGlobals = $mwGlobals; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function setup() { |
35
|
|
|
$this->defaultSettings(); |
36
|
|
|
$this->registerAllTheThings(); |
37
|
|
|
|
38
|
|
|
if ( MapsFactory::globalInstance()->smwIntegrationIsEnabled() ) { |
39
|
|
|
MapsFactory::globalInstance()->newSemanticMapsSetup( $this->mwGlobals )->initExtension(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function defaultSettings() { |
44
|
|
|
if ( $this->mwGlobals['egMapsGMaps3Language'] === '' ) { |
45
|
|
|
$this->mwGlobals['egMapsGMaps3Language'] = $this->mwGlobals['wgLang']; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ( in_array( 'googlemaps3', $this->mwGlobals['egMapsAvailableServices'] ) ) { |
49
|
|
|
$this->mwGlobals['wgSpecialPages']['MapEditor'] = SpecialMapEditor::class; |
50
|
|
|
$this->mwGlobals['wgSpecialPageGroups']['MapEditor'] = 'maps'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ( $this->mwGlobals['egMapsGMaps3ApiKey'] === '' && array_key_exists( |
54
|
|
|
'egGoogleJsApiKey', |
55
|
|
|
$this->mwGlobals |
56
|
|
|
) ) { |
57
|
|
|
$this->mwGlobals['egMapsGMaps3ApiKey'] = $this->mwGlobals['egGoogleJsApiKey']; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function registerAllTheThings() { |
62
|
|
|
$this->registerParserHooks(); |
63
|
|
|
$this->registerParameterTypes(); |
64
|
|
|
$this->registerHooks(); |
65
|
|
|
$this->registerGeoJsonContentModel(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function registerParserHooks() { |
69
|
|
|
$this->mwGlobals['wgHooks']['ParserFirstCallInit'][] = function ( Parser $parser ) { |
70
|
|
|
MapsFactory::globalInstance()->newParserHookSetup( $parser )->registerParserHooks(); |
71
|
|
|
}; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function registerParameterTypes() { |
75
|
|
|
$this->mwGlobals['wgParamDefinitions']['coordinate'] = [ |
76
|
|
|
'string-parser' => LatLongParser::class, |
77
|
|
|
]; |
78
|
|
|
|
79
|
1 |
|
$this->mwGlobals['wgParamDefinitions']['mapslocation'] = [ |
80
|
1 |
|
'string-parser' => LocationParser::class, |
81
|
1 |
|
]; |
82
|
|
|
|
83
|
|
|
$this->mwGlobals['wgParamDefinitions']['mapsline'] = [ |
84
|
|
|
'string-parser' => LineParser::class, |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
$this->mwGlobals['wgParamDefinitions']['mapscircle'] = [ |
88
|
|
|
'string-parser' => CircleParser::class, |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
$this->mwGlobals['wgParamDefinitions']['mapsrectangle'] = [ |
92
|
|
|
'string-parser' => RectangleParser::class, |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
$this->mwGlobals['wgParamDefinitions']['mapspolygon'] = [ |
96
|
|
|
'string-parser' => PolygonParser::class, |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$this->mwGlobals['wgParamDefinitions']['distance'] = [ |
100
|
|
|
'string-parser' => DistanceParser::class, |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
$this->mwGlobals['wgParamDefinitions']['wmsoverlay'] = [ |
104
|
|
|
'string-parser' => WmsOverlayParser::class, |
105
|
|
|
]; |
106
|
|
|
|
107
|
|
|
$this->mwGlobals['wgParamDefinitions']['mapsimageoverlay'] = [ |
108
|
|
|
'string-parser' => ImageOverlayParser::class, |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private function registerHooks() { |
113
|
|
|
$this->mwGlobals['wgHooks']['AdminLinks'][] = 'Maps\MapsHooks::addToAdminLinks'; |
114
|
|
|
$this->mwGlobals['wgHooks']['MakeGlobalVariablesScript'][] = 'Maps\MapsHooks::onMakeGlobalVariablesScript'; |
115
|
|
|
$this->mwGlobals['wgHooks']['SkinTemplateNavigation'][] = 'Maps\MapsHooks::onSkinTemplateNavigation'; |
116
|
|
|
$this->mwGlobals['wgHooks']['BeforeDisplayNoArticleText'][] = 'Maps\MapsHooks::onBeforeDisplayNoArticleText'; |
117
|
|
|
$this->mwGlobals['wgHooks']['ShowMissingArticle'][] = 'Maps\MapsHooks::onShowMissingArticle'; |
118
|
|
|
$this->mwGlobals['wgHooks']['ListDefinedTags'][] = 'Maps\MapsHooks::onRegisterTags'; |
119
|
|
|
$this->mwGlobals['wgHooks']['ChangeTagsListActive'][] = 'Maps\MapsHooks::onRegisterTags'; |
120
|
|
|
$this->mwGlobals['wgHooks']['ChangeTagsAllowedAdd'][] = 'Maps\MapsHooks::onChangeTagsAllowedAdd'; |
121
|
|
|
$this->mwGlobals['wgHooks']['ResourceLoaderTestModules'][] = 'Maps\MapsHooks::onResourceLoaderTestModules'; |
122
|
|
|
|
123
|
|
|
$this->mwGlobals['wgHooks']['CargoSetFormatClasses'][] = function( array &$formatClasses ) { |
124
|
|
|
$formatClasses['map'] = CargoFormat::class; |
125
|
|
|
}; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
private function registerGeoJsonContentModel() { |
129
|
|
|
$this->mwGlobals['wgContentHandlers'][GeoJsonContent::CONTENT_MODEL_ID] = GeoJsonContentHandler::class; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|