|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maps\SemanticMW\ResultPrinters; |
|
4
|
|
|
|
|
5
|
|
|
use MapsKMLFormatter; |
|
6
|
|
|
use ParamProcessor\ParamDefinition; |
|
7
|
|
|
use SMW\FileExportPrinter; |
|
8
|
|
|
use SMWQueryResult; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* SMWResultPrinter class for printing a query result as KML. |
|
12
|
|
|
* |
|
13
|
|
|
* @file SM_KMLPrinter.php |
|
14
|
|
|
* @ingroup SemanticMaps |
|
15
|
|
|
* |
|
16
|
|
|
* @licence GNU GPL v2+ |
|
17
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
18
|
|
|
*/ |
|
19
|
|
|
class KmlPrinter extends FileExportPrinter { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Handler of the print request. |
|
23
|
|
|
* |
|
24
|
|
|
* @param SMWQueryResult $res |
|
25
|
|
|
* @param $outputmode |
|
26
|
|
|
* |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getResultText( SMWQueryResult $res, $outputmode ) { |
|
30
|
|
|
if ( $outputmode == SMW_OUTPUT_FILE ) { |
|
31
|
|
|
return $this->getKML( $res, $outputmode ); |
|
32
|
|
|
} else { |
|
33
|
|
|
return $this->getKMLLink( $res, $outputmode ); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns the KML for the query result. |
|
39
|
|
|
* |
|
40
|
|
|
* @param SMWQueryResult $res |
|
41
|
|
|
* @param integer $outputmode |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
private function getKML( SMWQueryResult $res, $outputmode ) { |
|
46
|
|
|
$queryHandler = new QueryHandler( $res, $outputmode, $this->params['linkabsolute'] ); |
|
47
|
|
|
$queryHandler->setText( $this->params['text'] ); |
|
48
|
|
|
$queryHandler->setTitle( $this->params['title'] ); |
|
49
|
|
|
$queryHandler->setSubjectSeparator( '' ); |
|
50
|
|
|
$queryHandler->setPageLinkText( $this->params['pagelinktext'] ); |
|
51
|
|
|
|
|
52
|
|
|
$formatter = new MapsKMLFormatter( $this->params ); |
|
53
|
|
|
|
|
54
|
|
|
$shapes = $queryHandler->getShapes(); |
|
55
|
|
|
$formatter->addPlacemarks( $shapes['locations'] ); |
|
56
|
|
|
|
|
57
|
|
|
return $formatter->getKML(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns a link (HTML) pointing to a query that returns the actual KML file. |
|
62
|
|
|
* |
|
63
|
|
|
* @param SMWQueryResult $res |
|
64
|
|
|
* @param integer $outputmode |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private function getKMLLink( SMWQueryResult $res, $outputmode ) { |
|
69
|
|
|
$searchLabel = $this->getSearchLabel( $outputmode ); |
|
70
|
|
|
$link = $res->getQueryLink( |
|
71
|
|
|
$searchLabel ? $searchLabel : wfMessage( 'semanticmaps-kml-link' )->inContentLanguage()->text() |
|
72
|
|
|
); |
|
73
|
|
|
$link->setParameter( 'kml', 'format' ); |
|
74
|
|
|
$link->setParameter( $this->params['linkabsolute'] ? 'yes' : 'no', 'linkabsolute' ); |
|
75
|
|
|
$link->setParameter( $this->params['pagelinktext'], 'pagelinktext' ); |
|
76
|
|
|
|
|
77
|
|
|
if ( $this->params['title'] !== '' ) { |
|
78
|
|
|
$link->setParameter( $this->params['title'], 'title' ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if ( $this->params['text'] !== '' ) { |
|
82
|
|
|
$link->setParameter( $this->params['text'], 'text' ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// Fix for offset-error in getQueryLink() |
|
86
|
|
|
// (getQueryLink by default sets offset to point to the next |
|
87
|
|
|
// result set, fix by setting it to 0 if now explicitly set) |
|
88
|
|
|
if ( array_key_exists( 'offset', $this->params ) ) { |
|
89
|
|
|
$link->setParameter( $this->params['offset'], 'offset' ); |
|
90
|
|
|
} else { |
|
91
|
|
|
$link->setParameter( 0, 'offset' ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if ( array_key_exists( 'limit', $this->params ) ) { |
|
95
|
|
|
$link->setParameter( $this->params['limit'], 'limit' ); |
|
96
|
|
|
} else { // Use a reasonable default limit. |
|
97
|
|
|
$link->setParameter( 20, 'limit' ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); |
|
101
|
|
|
|
|
102
|
|
|
return $link->getText( $outputmode, $this->mLinker ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @see SMWResultPrinter::getParamDefinitions |
|
107
|
|
|
* |
|
108
|
|
|
* @param ParamDefinition[] $definitions |
|
109
|
|
|
* |
|
110
|
|
|
* @return array of ParamDefinition|array |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getParamDefinitions( array $definitions ) { |
|
113
|
|
|
global $egMapsDefaultLabel, $egMapsDefaultTitle; |
|
114
|
|
|
|
|
115
|
|
|
$params = parent::getParamDefinitions( $definitions ); |
|
116
|
|
|
|
|
117
|
|
|
$params['text'] = [ |
|
118
|
|
|
'message' => 'semanticmaps-kml-text', |
|
119
|
|
|
'default' => $egMapsDefaultLabel, |
|
120
|
|
|
]; |
|
121
|
|
|
|
|
122
|
|
|
$params['title'] = [ |
|
123
|
|
|
'message' => 'semanticmaps-kml-title', |
|
124
|
|
|
'default' => $egMapsDefaultTitle, |
|
125
|
|
|
]; |
|
126
|
|
|
|
|
127
|
|
|
$params['linkabsolute'] = [ |
|
128
|
|
|
'message' => 'semanticmaps-kml-linkabsolute', |
|
129
|
|
|
'type' => 'boolean', |
|
130
|
|
|
'default' => true, |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
$params['pagelinktext'] = [ |
|
134
|
|
|
'message' => 'semanticmaps-kml-pagelinktext', |
|
135
|
|
|
'default' => wfMessage( 'semanticmaps-default-kml-pagelink' )->text(), |
|
136
|
|
|
]; |
|
137
|
|
|
|
|
138
|
|
|
return $params; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @see SMWIExportPrinter::getMimeType |
|
143
|
|
|
* |
|
144
|
|
|
* @param SMWQueryResult $queryResult |
|
145
|
|
|
* |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getMimeType( SMWQueryResult $queryResult ) { |
|
149
|
|
|
return 'application/vnd.google-earth.kml+xml'; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @see SMWIExportPrinter::getFileName |
|
154
|
|
|
* |
|
155
|
|
|
* @param SMWQueryResult $queryResult |
|
156
|
|
|
* |
|
157
|
|
|
* @return string|boolean |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getFileName( SMWQueryResult $queryResult ) { |
|
160
|
|
|
return 'kml.kml'; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @see SMWResultPrinter::getName() |
|
165
|
|
|
*/ |
|
166
|
|
|
public final function getName() { |
|
167
|
|
|
return wfMessage( 'semanticmaps-kml' )->text(); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @see SMWResultPrinter::handleParameters |
|
172
|
|
|
* |
|
173
|
|
|
* @param array $params |
|
174
|
|
|
* @param $outputmode |
|
175
|
|
|
*/ |
|
176
|
|
|
protected function handleParameters( array $params, $outputmode ) { |
|
177
|
|
|
$this->params = $params; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|