1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps; |
6
|
|
|
|
7
|
|
|
use Maps\SemanticMW\DataValues\CoordinateValue; |
8
|
|
|
use Maps\SemanticMW\ResultPrinters\KmlPrinter; |
9
|
|
|
use Maps\SemanticMW\ResultPrinters\MapPrinter; |
10
|
|
|
use SMW\DataTypeRegistry; |
11
|
|
|
use SMWDataItem; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class SemanticMapsSetup { |
18
|
|
|
|
19
|
|
|
private $mwGlobals; |
20
|
|
|
private $mappingServices; |
21
|
|
|
|
22
|
|
|
private function __construct( array &$mwGlobals, MappingServices $mappingServices ) { |
23
|
|
|
$this->mwGlobals =& $mwGlobals; |
24
|
|
|
$this->mappingServices = $mappingServices; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static function newFromMediaWikiGlobals( array &$mwGlobals, MappingServices $mappingServices ) { |
28
|
|
|
return new self( $mwGlobals, $mappingServices ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function initExtension() { |
32
|
|
|
// Hook for initializing the Geographical Data types. |
33
|
|
|
$this->mwGlobals['wgHooks']['SMW::DataType::initTypes'][] = function() { |
34
|
|
|
DataTypeRegistry::getInstance()->registerDatatype( |
35
|
|
|
'_geo', |
36
|
|
|
CoordinateValue::class, |
37
|
|
|
SMWDataItem::TYPE_GEO |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
return true; |
41
|
|
|
}; |
42
|
|
|
|
43
|
|
|
// Hook for defining the default query printer for queries that ask for geographical coordinates. |
44
|
|
|
$this->mwGlobals['wgHooks']['SMWResultFormat'][] = 'Maps\MediaWiki\MapsHooks::addGeoCoordsDefaultFormat'; |
45
|
|
|
|
46
|
|
|
$this->registerGoogleMaps(); |
47
|
|
|
$this->registerLeaflet(); |
48
|
|
|
|
49
|
|
|
$this->mwGlobals['smwgResultFormats']['kml'] = KmlPrinter::class; |
50
|
|
|
|
51
|
|
|
$this->mwGlobals['smwgResultAliases'][$this->mwGlobals['egMapsDefaultService']][] = 'map'; |
52
|
|
|
MapPrinter::registerDefaultService( $this->mwGlobals['egMapsDefaultService'] ); |
53
|
|
|
|
54
|
|
|
// Internationalization |
55
|
|
|
$this->mwGlobals['wgMessagesDirs']['SemanticMaps'] = __DIR__ . '/i18n'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function registerGoogleMaps() { |
59
|
|
|
if ( $this->mappingServices->nameIsKnown( 'googlemaps3' ) ) { |
60
|
|
|
$googleMaps = $this->mappingServices->getService( 'googlemaps3' ); |
61
|
|
|
|
62
|
|
|
MapPrinter::registerService( $googleMaps ); |
63
|
|
|
|
64
|
|
|
$this->mwGlobals['smwgResultFormats'][$googleMaps->getName()] = MapPrinter::class; |
65
|
|
|
$this->mwGlobals['smwgResultAliases'][$googleMaps->getName()] = $googleMaps->getAliases(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function registerLeaflet() { |
70
|
|
|
if ( $this->mappingServices->nameIsKnown( 'leaflet' ) ) { |
71
|
|
|
$leaflet = $this->mappingServices->getService( 'leaflet' ); |
72
|
|
|
|
73
|
|
|
MapPrinter::registerService( $leaflet ); |
74
|
|
|
|
75
|
|
|
$this->mwGlobals['smwgResultFormats'][$leaflet->getName()] = MapPrinter::class; |
76
|
|
|
$this->mwGlobals['smwgResultAliases'][$leaflet->getName()] = $leaflet->getAliases(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|