1 | <?php |
||
19 | class SMMapPrinter extends SMW\ResultPrinter { |
||
20 | |||
21 | /** |
||
22 | * @since 0.6 |
||
23 | * |
||
24 | * @var iMappingService |
||
25 | */ |
||
26 | protected $service; |
||
27 | |||
28 | /** |
||
29 | * @since 1.0 |
||
30 | * |
||
31 | * @var string|boolean false |
||
32 | */ |
||
33 | protected $fatalErrorMsg = false; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param $format String |
||
39 | * @param $inline |
||
40 | */ |
||
41 | 2 | public function __construct( $format, $inline = true ) { |
|
46 | |||
47 | /** |
||
48 | * Returns an array containing the parameter info. |
||
49 | * |
||
50 | * @since 1.0 |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | protected function getParameterInfo() { |
||
55 | global $smgQPShowTitle, $smgQPTemplate, $smgQPHideNamespace; |
||
56 | |||
57 | $params = ParamDefinition::getCleanDefinitions( MapsMapper::getCommonParameters() ); |
||
58 | |||
59 | $this->service->addParameterInfo( $params ); |
||
60 | |||
61 | $params['staticlocations'] = [ |
||
62 | 'type' => 'mapslocation', |
||
63 | 'aliases' => [ 'locations', 'points' ], |
||
64 | 'default' => [], |
||
65 | 'islist' => true, |
||
66 | 'delimiter' => ';', |
||
67 | 'message' => 'semanticmaps-par-staticlocations', |
||
68 | ]; |
||
69 | |||
70 | $params['showtitle'] = [ |
||
71 | 'type' => 'boolean', |
||
72 | 'aliases' => 'show title', |
||
73 | 'default' => $smgQPShowTitle, |
||
74 | ]; |
||
75 | |||
76 | $params['hidenamespace'] = [ |
||
77 | 'type' => 'boolean', |
||
78 | 'aliases' => 'hide namespace', |
||
79 | 'default' => $smgQPHideNamespace, |
||
80 | ]; |
||
81 | |||
82 | $params['template'] = [ |
||
83 | 'default' => $smgQPTemplate, |
||
84 | ]; |
||
85 | |||
86 | $params['userparam'] = [ |
||
87 | 'default' => '', |
||
88 | ]; |
||
89 | |||
90 | $params['activeicon'] = [ |
||
91 | 'type' => 'string', |
||
92 | 'default' => '', |
||
93 | ]; |
||
94 | |||
95 | $params['pagelabel'] = [ |
||
96 | 'type' => 'boolean', |
||
97 | 'default' => false, |
||
98 | ]; |
||
99 | |||
100 | $params['ajaxcoordproperty'] = array( |
||
101 | 'default' => 'Has coordinates', |
||
102 | ); |
||
103 | |||
104 | $params['ajaxquery'] = array( |
||
105 | 'default' => '', |
||
106 | 'type' => 'string' |
||
107 | ); |
||
108 | |||
109 | // Messages: |
||
110 | // semanticmaps-par-staticlocations, semanticmaps-par-showtitle, semanticmaps-par-hidenamespace, |
||
111 | // semanticmaps-par-template, semanticmaps-par-userparam, semanticmaps-par-activeicon, |
||
112 | // semanticmaps-par-pagelabel, semanticmaps-par-ajaxcoordproperty semanticmaps-par-ajaxquery |
||
113 | foreach ( $params as $name => &$data ) { |
||
114 | if ( is_array( $data ) && !array_key_exists( 'message', $data ) ) { |
||
115 | $data['message'] = 'semanticmaps-par-' . $name; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | $params = array_merge( $params, MapsDisplayMap::getCommonMapParams() ); |
||
120 | |||
121 | return $params; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Builds up and returns the HTML for the map, with the queried coordinate data on it. |
||
126 | * |
||
127 | * @param SMWQueryResult $res |
||
128 | * @param $outputmode |
||
129 | * |
||
130 | * @return array or string |
||
131 | */ |
||
132 | public final function getResultText( SMWQueryResult $res, $outputmode ) { |
||
133 | if ( $this->fatalErrorMsg !== false ) { |
||
134 | return $this->fatalErrorMsg; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @var Parser $wgParser |
||
139 | */ |
||
140 | global $wgParser; |
||
141 | |||
142 | if ( $GLOBALS['egMapsEnableCategory'] && $wgParser->getOutput() !== null ) { |
||
143 | $wgParser->addTrackingCategory( 'maps-tracking-category' ); |
||
144 | } |
||
145 | |||
146 | $params = $this->params; |
||
147 | |||
148 | $queryHandler = new SMQueryHandler( $res, $outputmode ); |
||
149 | $queryHandler->setLinkStyle($params['link']); |
||
150 | $queryHandler->setHeaderStyle($params['headers']); |
||
151 | $queryHandler->setShowSubject( $params['showtitle'] ); |
||
152 | $queryHandler->setTemplate( $params['template'] ); |
||
153 | $queryHandler->setUserParam( $params['userparam'] ); |
||
154 | $queryHandler->setHideNamespace( $params['hidenamespace'] ); |
||
155 | $queryHandler->setActiveIcon( $params['activeicon'] ); |
||
156 | |||
157 | $this->handleMarkerData( $params, $queryHandler ); |
||
158 | $locationAmount = count( $params['locations'] ); |
||
159 | |||
160 | $params['ajaxquery'] = urlencode( $params['ajaxquery'] ); |
||
161 | |||
162 | if ( $locationAmount > 0 ) { |
||
163 | // We can only take care of the zoom defaulting here, |
||
164 | // as not all locations are available in whats passed to Validator. |
||
165 | if ( $this->fullParams['zoom']->wasSetToDefault() && $locationAmount > 1 ) { |
||
166 | $params['zoom'] = false; |
||
167 | } |
||
168 | |||
169 | $mapName = $this->service->getMapId(); |
||
170 | |||
171 | SMWOutputs::requireHeadItem( |
||
172 | $mapName, |
||
173 | $this->service->getDependencyHtml() . |
||
174 | $configVars = Skin::makeVariablesScript( $this->service->getConfigVariables() ) |
||
175 | ); |
||
176 | |||
177 | foreach ( $this->service->getResourceModules() as $resourceModule ) { |
||
178 | SMWOutputs::requireResource( $resourceModule ); |
||
179 | } |
||
180 | |||
181 | if ( array_key_exists( 'source', $params ) ) { |
||
182 | unset( $params['source'] ); |
||
183 | } |
||
184 | |||
185 | return $this->getMapHTML( $params, $wgParser, $mapName ); |
||
186 | } |
||
187 | else { |
||
188 | return $params['default']; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Returns the HTML to display the map. |
||
194 | * |
||
195 | * @since 1.1 |
||
196 | * |
||
197 | * @param array $params |
||
198 | * @param Parser $parser |
||
199 | * @param string $mapName |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function getMapHTML( array $params, Parser $parser, $mapName ) { |
||
219 | |||
220 | /** |
||
221 | * Returns a PHP object to encode to JSON with the map data. |
||
222 | * |
||
223 | * @since 1.1 |
||
224 | * |
||
225 | * @param array $params |
||
226 | * @param Parser $parser |
||
227 | * |
||
228 | * @return mixed |
||
229 | */ |
||
230 | protected function getJSONObject( array $params, Parser $parser ) { |
||
233 | |||
234 | /** |
||
235 | * Converts the data in the coordinates parameter to JSON-ready objects. |
||
236 | * These get stored in the locations parameter, and the coordinates on gets deleted. |
||
237 | * |
||
238 | * @since 1.0 |
||
239 | * |
||
240 | * @param array &$params |
||
241 | * @param SMQueryHandler $queryHandler |
||
242 | */ |
||
243 | protected function handleMarkerData( array &$params, SMQueryHandler $queryHandler ) { |
||
266 | |||
267 | protected function getJsonForStaticLocations( array $staticLocations, array $params, $iconUrl, $visitedIconUrl ) { |
||
289 | |||
290 | protected function getJsonForStaticLocation( Location $location, array $params, $iconUrl, $visitedIconUrl, Parser $parser ) { |
||
306 | |||
307 | /** |
||
308 | * @param Element[] $queryShapes |
||
309 | * @param array $params |
||
310 | * @param string $iconUrl |
||
311 | * @param string $visitedIconUrl |
||
312 | */ |
||
313 | protected function addShapeData( array $queryShapes, array &$params, $iconUrl, $visitedIconUrl ) { |
||
327 | |||
328 | /** |
||
329 | * @param Location[] $locations |
||
330 | * @param array $params |
||
331 | * @param string $iconUrl |
||
332 | * @param string $visitedIconUrl |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | protected function getJsonForLocations( array $locations, array $params, $iconUrl, $visitedIconUrl ) { |
||
349 | |||
350 | /** |
||
351 | * @param BaseElement[] $elements |
||
352 | * @param array $params |
||
353 | * |
||
354 | * @return array |
||
355 | */ |
||
356 | protected function getElementJsonArray( array $elements, array $params ) { |
||
366 | |||
367 | /** |
||
368 | * Returns the internationalized name of the mapping service. |
||
369 | * |
||
370 | * @return string |
||
371 | */ |
||
372 | public final function getName() { |
||
375 | |||
376 | /** |
||
377 | * Returns a list of parameter information, for usage by Special:Ask and others. |
||
378 | * |
||
379 | * @return array |
||
380 | */ |
||
381 | public function getParameters() { |
||
393 | } |
||
394 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: