|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maps; |
|
4
|
|
|
|
|
5
|
|
|
use FileFetcher\FileFetcher; |
|
6
|
|
|
use Jeroen\SimpleGeocoder\Geocoder; |
|
7
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\Decorators\CoordinateFriendlyGeocoder; |
|
8
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\FileFetchers\GeoNamesGeocoder; |
|
9
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\FileFetchers\GoogleGeocoder; |
|
10
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\FileFetchers\NominatimGeocoder; |
|
11
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\NullGeocoder; |
|
12
|
|
|
use Maps\Geocoders\CachingGeocoder; |
|
13
|
|
|
use MediaWiki\MediaWikiServices; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @licence GNU GPL v2+ |
|
17
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
18
|
|
|
*/ |
|
19
|
|
|
class MapsFactory { |
|
20
|
|
|
|
|
21
|
|
|
private $settings; |
|
22
|
26 |
|
private $mediaWikiServices; |
|
23
|
26 |
|
|
|
24
|
26 |
|
private function __construct( array $settings, MediaWikiServices $mediaWikiServices ) { |
|
25
|
|
|
$this->settings = $settings; |
|
26
|
26 |
|
$this->mediaWikiServices = $mediaWikiServices; |
|
27
|
26 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
public static function newDefault() { |
|
30
|
19 |
|
return new self( $GLOBALS, MediaWikiServices::getInstance() ); |
|
31
|
19 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function newLocationParser(): LocationParser { |
|
34
|
26 |
|
return LocationParser::newInstance( $this->newGeocoder() ); |
|
35
|
26 |
|
} |
|
36
|
|
|
|
|
37
|
26 |
|
public function newGeocoder(): Geocoder { |
|
38
|
26 |
|
$geocoder = new CoordinateFriendlyGeocoder( $this->newCoreGeocoder() ); |
|
39
|
26 |
|
|
|
40
|
26 |
|
if ( $this->settings['egMapsEnableGeoCache'] ) { |
|
41
|
26 |
|
return new CachingGeocoder( |
|
42
|
|
|
$geocoder, |
|
43
|
|
|
$this->getMediaWikiCache(), |
|
44
|
|
|
$this->settings['egMapsGeoCacheTtl'] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
26 |
|
return $geocoder; |
|
49
|
26 |
|
} |
|
50
|
26 |
|
|
|
51
|
|
|
private function newCoreGeocoder(): Geocoder { |
|
52
|
|
|
switch ( $this->settings['egMapsDefaultGeoService'] ) { |
|
53
|
|
|
case 'geonames': |
|
54
|
|
|
if ( $this->settings['egMapsGeoNamesUser'] === '' ) { |
|
55
|
|
|
return $this->newGoogleGeocoder(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return new GeoNamesGeocoder( |
|
59
|
26 |
|
$this->newFileFetcher(), |
|
60
|
|
|
$this->settings['egMapsGeoNamesUser'] |
|
61
|
26 |
|
); |
|
62
|
26 |
|
case 'google': |
|
63
|
26 |
|
return $this->newGoogleGeocoder(); |
|
64
|
|
|
case 'nominatim': |
|
65
|
|
|
return new NominatimGeocoder( |
|
66
|
|
|
$this->newFileFetcher() |
|
67
|
|
|
); |
|
68
|
|
|
default: |
|
69
|
|
|
return new NullGeocoder(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function newGoogleGeocoder(): Geocoder { |
|
74
|
|
|
return new GoogleGeocoder( |
|
75
|
|
|
$this->newFileFetcher(), |
|
76
|
|
|
$this->settings['egMapsGMaps3ApiKey'], |
|
77
|
|
|
$this->settings['egMapsGMaps3ApiVersion'] |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getFileFetcher(): FileFetcher { |
|
82
|
26 |
|
return $this->newFileFetcher(); |
|
83
|
26 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function newFileFetcher(): FileFetcher { |
|
86
|
26 |
|
return new MapsFileFetcher(); |
|
87
|
26 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
private function getMediaWikiCache(): \BagOStuff { |
|
90
|
|
|
return wfGetCache( CACHE_ANYTHING ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getPageContentFetcher(): PageContentFetcher { |
|
94
|
|
|
return new PageContentFetcher( |
|
95
|
|
|
$this->mediaWikiServices->getTitleParser(), |
|
96
|
|
|
$this->mediaWikiServices->getRevisionLookup() |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|