Index: branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.old.php |
— | — | @@ -1,512 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Abstract class that provides the common functionality for all map query printers. |
6 | | - * |
7 | | - * TODO: make use of SMQueryHandler |
8 | | - * TODO: make use of new-style Validator parameter handling |
9 | | - * |
10 | | - * @file SM_MapPrinter.php |
11 | | - * @ingroup SemanticMaps |
12 | | - * |
13 | | - * @author Jeroen De Dauw |
14 | | - * @author Robert Buzink |
15 | | - * @author Yaron Koren |
16 | | - */ |
17 | | -abstract class SMMapPrinter extends SMWResultPrinter implements iMappingFeature { |
18 | | - |
19 | | - /** |
20 | | - * Returns the name of the service to get the correct mapping service object. |
21 | | - * |
22 | | - * @since 0.6.3 |
23 | | - * |
24 | | - * @return string |
25 | | - */ |
26 | | - protected abstract function getServiceName(); |
27 | | - |
28 | | - /** |
29 | | - * @var iMappingService |
30 | | - */ |
31 | | - protected $service; |
32 | | - |
33 | | - /** |
34 | | - * @var array |
35 | | - */ |
36 | | - protected $locations = array(); |
37 | | - |
38 | | - /** |
39 | | - * @var string |
40 | | - */ |
41 | | - protected $markerJs; |
42 | | - |
43 | | - /** |
44 | | - * @var string |
45 | | - */ |
46 | | - protected $centreLat; |
47 | | - |
48 | | - /** |
49 | | - * @var string |
50 | | - */ |
51 | | - protected $centreLon; |
52 | | - |
53 | | - /** |
54 | | - * @var string |
55 | | - */ |
56 | | - protected $output = ''; |
57 | | - |
58 | | - /** |
59 | | - * @var array or false |
60 | | - */ |
61 | | - protected $specificParameters = false; |
62 | | - |
63 | | - /** |
64 | | - * Indicates if the zoom paramter was set to it's default. |
65 | | - * |
66 | | - * @since 0.7 |
67 | | - * |
68 | | - * @var boolean |
69 | | - */ |
70 | | - protected $zoomDefaulted; |
71 | | - |
72 | | - /** |
73 | | - * Constructor. |
74 | | - * |
75 | | - * @param $format String |
76 | | - * @param $inline |
77 | | - * @param $service iMappingService |
78 | | - */ |
79 | | - public function __construct( $format, $inline, /* iMappingService */ $service = null ) { |
80 | | - // TODO: this is a hack since I can't find a way to pass along the service object here when the QP is created in SMW. |
81 | | - if ( $service == null ) { |
82 | | - $service = MapsMappingServices::getServiceInstance( $this->getServiceName() ); |
83 | | - } |
84 | | - |
85 | | - $this->service = $service; |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * Returns the specific parameters by first checking if they have been initialized yet, |
90 | | - * doing to work if this is not the case, and then returning them. |
91 | | - * |
92 | | - * @since 0.6.5 |
93 | | - * |
94 | | - * @return array |
95 | | - */ |
96 | | - public final function getSpecificParameterInfo() { |
97 | | - if ( $this->specificParameters === false ) { |
98 | | - $this->specificParameters = array(); |
99 | | - $this->initSpecificParamInfo( $this->specificParameters ); |
100 | | - } |
101 | | - |
102 | | - return $this->specificParameters; |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Initializes the specific parameters. |
107 | | - * |
108 | | - * Override this method to set parameters specific to a feature service comibination in |
109 | | - * the inheriting class. |
110 | | - * |
111 | | - * @since 0.6.5 |
112 | | - * |
113 | | - * @param array $parameters |
114 | | - */ |
115 | | - protected function initSpecificParamInfo( array &$parameters ) { |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Builds up and returns the HTML for the map, with the queried coordinate data on it. |
120 | | - * |
121 | | - * @param SMWQueryResult $res |
122 | | - * @param $outputmode |
123 | | - * |
124 | | - * @return array |
125 | | - */ |
126 | | - public final function getResultText( /* SMWQueryResult */ $res, $outputmode ) { |
127 | | - if ( self::manageMapProperties( $this->m_params ) ) { |
128 | | - $this->formatResultData( $res, $outputmode ); |
129 | | - |
130 | | - // Only create a map when there is at least one result. |
131 | | - if ( count( $this->locations ) > 0 || $this->forceshow ) { |
132 | | - $this->setZoom(); |
133 | | - |
134 | | - $this->setCentre(); |
135 | | - |
136 | | - $this->markerJs = $this->service->createMarkersJs( $this->locations ); |
137 | | - |
138 | | - $this->addSpecificMapHTML(); |
139 | | - |
140 | | - $dependencies = $this->service->getDependencyHtml(); |
141 | | - $hash = md5( $dependencies ); |
142 | | - SMWOutputs::requireHeadItem( $hash, $dependencies ); |
143 | | - } |
144 | | - else { |
145 | | - // TODO: add warning when level high enough and append to error list? |
146 | | - } |
147 | | - } |
148 | | - |
149 | | - return array( $this->output, 'noparse' => true, 'isHTML' => true ); |
150 | | - } |
151 | | - |
152 | | - /** |
153 | | - * Validates and corrects the provided map properties, and the sets them as class fields. |
154 | | - * |
155 | | - * @param array $mapProperties |
156 | | - * |
157 | | - * @return boolean Indicates whether the map should be shown or not. |
158 | | - */ |
159 | | - protected final function manageMapProperties( array $mapProperties ) { |
160 | | - |
161 | | - /* |
162 | | - * Assembliy of the allowed parameters and their information. |
163 | | - * The main parameters (the ones that are shared by everything) are overidden |
164 | | - * by the feature parameters (the ones specific to a feature). The result is then |
165 | | - * again overidden by the service parameters (the ones specific to the service), |
166 | | - * and finally by the specific parameters (the ones specific to a service-feature combination). |
167 | | - */ |
168 | | - $parameterInfo = SMQueryPrinters::getParameterInfo(); |
169 | | - $this->service->addParameterInfo( $parameterInfo ); |
170 | | - |
171 | | - // TODO |
172 | | - $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() ); |
173 | | - |
174 | | - $validator = new Validator( $this->getName(), false ); |
175 | | - |
176 | | - $validator->setParameters( $mapProperties, $parameterInfo ); |
177 | | - |
178 | | - $validator->validateParameters(); |
179 | | - |
180 | | - $fatalError = $validator->hasFatalError(); |
181 | | - |
182 | | - if ( $fatalError === false ) { |
183 | | - $this->zoomDefaulted = $validator->getParameter( 'zoom' )->wasSetToDefault(); |
184 | | - $this->setMapProperties( $validator->getParameterValues() ); |
185 | | - } |
186 | | - else { |
187 | | - $this->output = '<span class="errorbox">' . |
188 | | - htmlspecialchars( wfMsgExt( 'validator-fatal-error', 'parsemag', $fatalError->getMessage() ) ) . |
189 | | - '</span>'; |
190 | | - } |
191 | | - |
192 | | - return !$fatalError; |
193 | | - } |
194 | | - |
195 | | - /** |
196 | | - * Sets the map properties as class fields. |
197 | | - * |
198 | | - * @param array $mapProperties |
199 | | - */ |
200 | | - private function setMapProperties( array $mapProperties ) { |
201 | | - foreach ( $mapProperties as $paramName => $paramValue ) { |
202 | | - if ( !property_exists( __CLASS__, $paramName ) ) { |
203 | | - $this-> { $paramName } = $paramValue; |
204 | | - } |
205 | | - else { |
206 | | - throw new Exception( 'Attempt to override a class field during map propertie assignment. Field name: ' . $paramName ); |
207 | | - } |
208 | | - } |
209 | | - } |
210 | | - |
211 | | - /** |
212 | | - * Reads the parameters and gets the query printers output. |
213 | | - * |
214 | | - * @param SMWQueryResult $results |
215 | | - * @param array $params |
216 | | - * @param $outputmode |
217 | | - * |
218 | | - * @return array |
219 | | - */ |
220 | | - public final function getResult( /* SMWQueryResult */ $results, /* array */ $params, $outputmode ) { |
221 | | - // Skip checks, results with 0 entries are normal. |
222 | | - $this->readParameters( $params, $outputmode ); |
223 | | - |
224 | | - return $this->getResultText( $results, SMW_OUTPUT_HTML ); |
225 | | - } |
226 | | - |
227 | | - /** |
228 | | - * Loops over the rows in the result and adds them via addResultRow. |
229 | | - * |
230 | | - * @param SMWQueryResult $res |
231 | | - * @param $outputmode |
232 | | - */ |
233 | | - protected function formatResultData( SMWQueryResult $res, $outputmode ) { |
234 | | - $this->addStaticLocations(); |
235 | | - |
236 | | - while ( ( $row = $res->getNext() ) !== false ) { |
237 | | - $this->addResultRow( $outputmode, $row ); |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - /** |
242 | | - * Adds the static locations (specified via the staticlocations parameter) to the map. |
243 | | - * |
244 | | - * @since 0.7 |
245 | | - */ |
246 | | - protected function addStaticLocations() { |
247 | | - global $wgTitle; |
248 | | - |
249 | | - // New parser object to render popup contents with. |
250 | | - $parser = new Parser(); |
251 | | - |
252 | | - $this->title = $parser->parse( $this->title, $wgTitle, new ParserOptions() )->getText(); |
253 | | - $this->label = $parser->parse( $this->label, $wgTitle, new ParserOptions() )->getText(); |
254 | | - |
255 | | - // Each $location is an array containg the coordinate set as first element, possibly followed by meta data. |
256 | | - foreach ( $this->staticlocations as $location ) { |
257 | | - $markerData = MapsCoordinateParser::parseCoordinates( array_shift( $location ) ); |
258 | | - |
259 | | - if ( !$markerData ) continue; |
260 | | - |
261 | | - $markerData = array( $markerData['lat'], $markerData['lon'] ); |
262 | | - |
263 | | - if ( count( $location ) > 0 ) { |
264 | | - // Parse and add the point specific title if it's present. |
265 | | - $markerData['title'] = $parser->parse( $location[0], $wgTitle, new ParserOptions() )->getText(); |
266 | | - |
267 | | - if ( count( $location ) > 1 ) { |
268 | | - // Parse and add the point specific label if it's present. |
269 | | - $markerData['label'] = $parser->parse( $location[1], $wgTitle, new ParserOptions() )->getText(); |
270 | | - |
271 | | - if ( count( $location ) > 2 ) { |
272 | | - // Add the point specific icon if it's present. |
273 | | - $markerData['icon'] = $location[2]; |
274 | | - } |
275 | | - } |
276 | | - } |
277 | | - |
278 | | - // If there is no point specific icon, use the general icon parameter when available. |
279 | | - if ( !array_key_exists( 'icon', $markerData ) ) { |
280 | | - $markerData['icon'] = $this->icon; |
281 | | - } |
282 | | - |
283 | | - if ( $markerData['icon'] != '' ) { |
284 | | - $markerData['icon'] = MapsMapper::getImageUrl( $markerData['icon'] ); |
285 | | - } |
286 | | - |
287 | | - // Temporary fix, will refactor away later |
288 | | - // TODO |
289 | | - $markerData = array_values( $markerData ); |
290 | | - if ( count( $markerData ) < 5 ) { |
291 | | - if ( count( $markerData ) < 4 ) { |
292 | | - $markerData[] = ''; |
293 | | - } |
294 | | - $markerData[] = ''; |
295 | | - } |
296 | | - |
297 | | - $this->locations[] = $markerData; |
298 | | - } |
299 | | - } |
300 | | - |
301 | | - /** |
302 | | - * This function will loop through all properties (fields) of one record (row), |
303 | | - * and add the location data, title, label and icon to the m_locations array. |
304 | | - * |
305 | | - * TODO: this doesn't qualify as a megamoth just yet, but some splitting up would be nice |
306 | | - * |
307 | | - * @param $outputmode |
308 | | - * @param array $row The record you want to add data from |
309 | | - */ |
310 | | - protected function addResultRow( $outputmode, array $row ) { |
311 | | - global $wgUser, $smgUseSpatialExtensions, $wgTitle; |
312 | | - |
313 | | - $skin = $wgUser->getSkin(); |
314 | | - |
315 | | - $title = ''; |
316 | | - $titleForTemplate = ''; |
317 | | - $text = ''; |
318 | | - $lat = ''; |
319 | | - $lon = ''; |
320 | | - |
321 | | - $coords = array(); |
322 | | - $label = array(); |
323 | | - |
324 | | - // Loop throught all fields of the record. |
325 | | - foreach ( $row as $i => $field ) { |
326 | | - $pr = $field->getPrintRequest(); |
327 | | - |
328 | | - // Loop throught all the parts of the field value. |
329 | | - while ( ( $object = $field->getNextObject() ) !== false ) { |
330 | | - if ( $object->getTypeID() == '_wpg' && $i == 0 ) { |
331 | | - if ( $this->showtitle ) $title = $object->getLongText( $outputmode, $skin ); |
332 | | - if ( $this->template ) $titleForTemplate = $object->getLongText( $outputmode, NULL ); |
333 | | - } |
334 | | - |
335 | | - if ( $object->getTypeID() != '_geo' && $i != 0 ) { |
336 | | - if ( $this->template ) { |
337 | | - if ( $object instanceof SMWWikiPageValue ) { |
338 | | - $label[] = $object->getTitle()->getPrefixedText(); |
339 | | - } else { |
340 | | - $label[] = $object->getLongText( $outputmode, $skin ); |
341 | | - } |
342 | | - } |
343 | | - else { |
344 | | - $propertyName = $pr->getHTMLText( $skin ); |
345 | | - if ( $propertyName != '' ) $propertyName .= ': '; |
346 | | - $text .= $propertyName . $object->getLongText( $outputmode, $skin ) . '<br />'; |
347 | | - } |
348 | | - } |
349 | | - |
350 | | - if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_geo' ) { |
351 | | - $coords[] = $object->getDBkeys(); |
352 | | - } |
353 | | - } |
354 | | - } |
355 | | - |
356 | | - if ( $this->template ) { |
357 | | - // New parser object to render the templates with. |
358 | | - $parser = new Parser(); |
359 | | - } |
360 | | - |
361 | | - foreach ( $coords as $coord ) { |
362 | | - if ( count( $coord ) >= 2 ) { |
363 | | - if ( $smgUseSpatialExtensions ) { |
364 | | - // TODO |
365 | | - } |
366 | | - else { |
367 | | - list( $lat, $lon ) = $coord; |
368 | | - } |
369 | | - |
370 | | - if ( $lat != '' && $lon != '' ) { |
371 | | - $icon = $this->getLocationIcon( $row ); |
372 | | - |
373 | | - if ( $this->template ) { |
374 | | - $segments = array_merge( |
375 | | - array( $this->template, 'title=' . $titleForTemplate, 'latitude=' . $lat, 'longitude=' . $lon ), |
376 | | - $label |
377 | | - ); |
378 | | - |
379 | | - $text = $parser->parse( '{{' . implode( '|', $segments ) . '}}', $wgTitle, new ParserOptions() )->getText(); |
380 | | - } |
381 | | - |
382 | | - $this->locations[] = array( |
383 | | - $lat, |
384 | | - $lon, |
385 | | - $title, |
386 | | - $text, |
387 | | - $icon |
388 | | - ); |
389 | | - } |
390 | | - } |
391 | | - } |
392 | | - } |
393 | | - |
394 | | - /** |
395 | | - * Get the icon for a row. |
396 | | - * |
397 | | - * @param array $row |
398 | | - * |
399 | | - * @return string |
400 | | - */ |
401 | | - private function getLocationIcon( array $row ) { |
402 | | - $icon = ''; |
403 | | - $legend_labels = array(); |
404 | | - |
405 | | - // Look for display_options field, which can be set by Semantic Compound Queries |
406 | | - // the location of this field changed in SMW 1.5 |
407 | | - $display_location = method_exists( $row[0], 'getResultSubject' ) ? $row[0]->getResultSubject() : $row[0]; |
408 | | - |
409 | | - if ( property_exists( $display_location, 'display_options' ) && is_array( $display_location->display_options ) ) { |
410 | | - $display_options = $display_location->display_options; |
411 | | - if ( array_key_exists( 'icon', $display_options ) ) { |
412 | | - $icon = $display_options['icon']; |
413 | | - |
414 | | - // This is somewhat of a hack - if a legend label has been set, we're getting it for every point, instead of just once per icon |
415 | | - if ( array_key_exists( 'legend label', $display_options ) ) { |
416 | | - |
417 | | - $legend_label = $display_options['legend label']; |
418 | | - |
419 | | - if ( ! array_key_exists( $icon, $legend_labels ) ) { |
420 | | - $legend_labels[$icon] = $legend_label; |
421 | | - } |
422 | | - } |
423 | | - } |
424 | | - } // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here |
425 | | - elseif ( $this->icon != '' ) { |
426 | | - $icon = MapsMapper::getImageUrl( $this->icon ); |
427 | | - } |
428 | | - |
429 | | - return $icon; |
430 | | - } |
431 | | - |
432 | | - /** |
433 | | - * Sets the zoom level to the provided value, or when not set, to the default. |
434 | | - */ |
435 | | - protected function setZoom() { |
436 | | - if ( $this->zoomDefaulted ) { |
437 | | - if ( count( $this->locations ) > 1 ) { |
438 | | - $this->zoom = 'null'; |
439 | | - } |
440 | | - } |
441 | | - } |
442 | | - |
443 | | - /** |
444 | | - * Sets the $centre_lat and $centre_lon fields. |
445 | | - * Note: this needs to be done AFTRE the maker coordinates are set. |
446 | | - */ |
447 | | - protected function setCentre() { |
448 | | - // If a centre value is set, use it. |
449 | | - if ( $this->centre != '' ) { |
450 | | - // Geocode and convert if required. |
451 | | - $centre = MapsGeocoders::attemptToGeocode( $this->centre, $this->geoservice, $this->service->getName() ); |
452 | | - |
453 | | - if ( $centre ) { |
454 | | - $this->centreLat = $centre['lat']; |
455 | | - $this->centreLon = $centre['lon']; |
456 | | - } |
457 | | - else { |
458 | | - $this->setCentreDefault(); |
459 | | - } |
460 | | - } |
461 | | - else { |
462 | | - $this->setCentreDefault(); |
463 | | - } |
464 | | - } |
465 | | - |
466 | | - /** |
467 | | - * Figures out the default value for the centre. |
468 | | - */ |
469 | | - private function setCentreDefault() { |
470 | | - if ( count( $this->locations ) > 1 ) { |
471 | | - // If centre is not set, and there are multiple points, set the values to null, to be auto determined by the JS of the mapping API. |
472 | | - $this->centreLat = 'null'; |
473 | | - $this->centreLon = 'null'; |
474 | | - } |
475 | | - elseif ( count( $this->locations ) == 1 ) { |
476 | | - // If centre is not set and there is exactelly one marker, use it's coordinates. |
477 | | - $this->centreLat = Xml::escapeJsString( $this->locations[0][0] ); |
478 | | - $this->centreLon = Xml::escapeJsString( $this->locations[0][1] ); |
479 | | - } |
480 | | - else { |
481 | | - // If centre is not set and there are no results, centre on the default coordinates. |
482 | | - global $egMapsDefaultMapCentre; |
483 | | - // TODO |
484 | | - } |
485 | | - } |
486 | | - |
487 | | - /** |
488 | | - * Returns the internationalized name of the mapping service. |
489 | | - * |
490 | | - * @return string |
491 | | - */ |
492 | | - public final function getName() { |
493 | | - return wfMsg( 'maps_' . $this->service->getName() ); |
494 | | - } |
495 | | - |
496 | | - /** |
497 | | - * Returns a list of parameter information, for usage by Special:Ask and others. |
498 | | - * |
499 | | - * @return array |
500 | | - */ |
501 | | - public function getParameters() { |
502 | | - global $egMapsMapWidth, $egMapsMapHeight; |
503 | | - |
504 | | - $params = parent::exportFormatParameters(); |
505 | | - |
506 | | - $params[] = array( 'name' => 'zoom', 'type' => 'int', 'description' => wfMsg( 'semanticmaps_paramdesc_zoom' ) ); |
507 | | - $params[] = array( 'name' => 'width', 'type' => 'int', 'description' => wfMsgExt( 'semanticmaps_paramdesc_width', 'parsemag', $egMapsMapWidth ) ); |
508 | | - $params[] = array( 'name' => 'height', 'type' => 'int', 'description' => wfMsgExt( 'semanticmaps_paramdesc_height', 'parsemag', $egMapsMapHeight ) ); |
509 | | - |
510 | | - return $params; |
511 | | - } |
512 | | - |
513 | | -} |
\ No newline at end of file |
Index: branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php |
— | — | @@ -20,12 +20,24 @@ |
21 | 21 | protected abstract function getServiceName(); |
22 | 22 | |
23 | 23 | /** |
| 24 | + * @since 0.6 |
| 25 | + * |
24 | 26 | * @var iMappingService |
25 | 27 | */ |
26 | 28 | protected $service; |
27 | 29 | |
| 30 | + /** |
| 31 | + * @since 0.8 |
| 32 | + * |
| 33 | + * @var false or string |
| 34 | + */ |
28 | 35 | protected $fatalErrorMsg = false; |
29 | 36 | |
| 37 | + /** |
| 38 | + * @since 0.8 |
| 39 | + * |
| 40 | + * @var array |
| 41 | + */ |
30 | 42 | protected $parameters; |
31 | 43 | |
32 | 44 | /** |
— | — | @@ -86,7 +98,6 @@ |
87 | 99 | $params = $this->parameters; |
88 | 100 | |
89 | 101 | $queryHandler = new SMQueryHandler( $res, $outputmode, $params ); |
90 | | - //$queryHandler->setText( ); |
91 | 102 | |
92 | 103 | $this->handleMarkerData( $params, $queryHandler->getLocations() ); |
93 | 104 | |
— | — | @@ -227,9 +238,11 @@ |
228 | 239 | |
229 | 240 | $params = parent::getParameters(); |
230 | 241 | |
| 242 | + // Obtain the parameter descriptions list. |
231 | 243 | $paramDescs = SMQueryPrinters::getParameterInfo(); |
232 | 244 | $this->service->addParameterInfo( $paramDescs ); |
233 | 245 | |
| 246 | + // Now go through the descriptions, and convert them from Validator- to SMW-style. |
234 | 247 | foreach ( $paramDescs as $paramDesc ) { |
235 | 248 | $param = array( |
236 | 249 | 'name' => $paramDesc->getName(), |
Index: branches/SemanticMaps0.8/includes/queryprinters/SM_QueryHandler.php |
— | — | @@ -75,6 +75,24 @@ |
76 | 76 | protected $pageLinkText; |
77 | 77 | |
78 | 78 | /** |
| 79 | + * A separator to use beteen the subject and properties in the text field. |
| 80 | + * |
| 81 | + * @since 0.8 |
| 82 | + * |
| 83 | + * @var string |
| 84 | + */ |
| 85 | + protected $subjectSeparator = '<hr />'; |
| 86 | + |
| 87 | + /** |
| 88 | + * Make the subject in the text bold or not? |
| 89 | + * |
| 90 | + * @since 0.8 |
| 91 | + * |
| 92 | + * @var boolean |
| 93 | + */ |
| 94 | + protected $boldSubject = true; |
| 95 | + |
| 96 | + /** |
79 | 97 | * Constructor. |
80 | 98 | * |
81 | 99 | * @since 0.7.3 |
— | — | @@ -122,9 +140,31 @@ |
123 | 141 | */ |
124 | 142 | public function setText( $text ) { |
125 | 143 | $this->text = $text; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Sets the subject separator. |
| 148 | + * |
| 149 | + * @since 0.8 |
| 150 | + * |
| 151 | + * @param string $subjectSeparator |
| 152 | + */ |
| 153 | + public function setSubjectSeparator( $subjectSeparator ) { |
| 154 | + $this->subjectSeparator = $subjectSeparator; |
126 | 155 | } |
127 | 156 | |
128 | 157 | /** |
| 158 | + * Sets if the subject should be made bold in the text. |
| 159 | + * |
| 160 | + * @since 0.8 |
| 161 | + * |
| 162 | + * @param string $boldSubject |
| 163 | + */ |
| 164 | + public function setBoldSubject( $boldSubject ) { |
| 165 | + $this->boldSubject = $boldSubject; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
129 | 169 | * Gets the query result as a list of locations. |
130 | 170 | * |
131 | 171 | * @since 0.7.3 |
— | — | @@ -159,9 +199,7 @@ |
160 | 200 | /** |
161 | 201 | * Returns the locations found in the provided result row. |
162 | 202 | * |
163 | | - * TODO: split up this method if possible (!) |
164 | 203 | * TODO: fix template handling |
165 | | - * TODO: clean up link type handling |
166 | 204 | * |
167 | 205 | * @since 0.7.3 |
168 | 206 | * |
— | — | @@ -170,20 +208,12 @@ |
171 | 209 | * @return array of MapsLocation |
172 | 210 | */ |
173 | 211 | protected function handleResultRow( array /* of SMWResultArray */ $row ) { |
174 | | - global $wgUser, $smgUseSpatialExtensions, $wgTitle; |
| 212 | + $coords = array(); |
| 213 | + $properties = array(); |
175 | 214 | |
176 | | - $locations = array(); |
177 | | - |
178 | | - $skin = $wgUser->getSkin(); |
179 | | - |
180 | 215 | $title = ''; |
181 | 216 | $text = ''; |
182 | | - $lat = ''; |
183 | | - $lon = ''; |
184 | 217 | |
185 | | - $coords = array(); |
186 | | - $label = array(); |
187 | | - |
188 | 218 | // Loop throught all fields of the record. |
189 | 219 | foreach ( $row as $i => $resultArray ) { |
190 | 220 | /* SMWPrintRequest */ $printRequest = $resultArray->getPrintRequest(); |
— | — | @@ -191,108 +221,155 @@ |
192 | 222 | // Loop throught all the parts of the field value. |
193 | 223 | while ( ( /* SMWDataValue */ $object = $resultArray->getNextObject() ) !== false ) { |
194 | 224 | if ( $object->getTypeID() == '_wpg' && $i == 0 ) { |
195 | | - $title = $object->getLongText( $this->outputmode, null ); |
196 | | - |
197 | | - if ( !$this->titleLinkSeperate && $this->linkAbsolute ) { |
198 | | - $text = Html::element( |
199 | | - 'a', |
200 | | - array( 'href' => $object->getTitle()->getFullUrl() ), |
201 | | - $object->getTitle()->getText() |
202 | | - ) . '<br />'; |
203 | | - } |
204 | | - else { |
205 | | - $text = $object->getLongText( $this->outputmode, $skin ) . '<br />'; |
206 | | - } |
207 | | - |
208 | | - if ( $this->titleLinkSeperate ) { |
209 | | - $text .= Html::element( |
210 | | - 'a', |
211 | | - array( 'href' => $object->getTitle()->getFullUrl() ), |
212 | | - str_replace( '$1', $object->getTitle()->getText(), $this->params['pagelinktext'] ) |
213 | | - ) . '<br />'; |
214 | | - } |
| 225 | + list( $title, $text ) = $this->handleResultSubject( $object ); |
215 | 226 | } |
216 | | - |
217 | | - if ( $object->getTypeID() != '_geo' && $i != 0 ) { |
218 | | - if ( $this->linkAbsolute ) { |
219 | | - $t = Title::newFromText( $printRequest->getHTMLText( NULL ), SMW_NS_PROPERTY ); |
220 | | - |
221 | | - if ( $t->exists() ) { |
222 | | - |
223 | | - $propertyName = $propertyName = Html::element( |
224 | | - 'a', |
225 | | - array( 'href' => $t->getFullUrl() ), |
226 | | - $printRequest->getHTMLText( NULL ) |
227 | | - ); |
228 | | - } |
229 | | - else { |
230 | | - $propertyName = $printRequest->getHTMLText( NULL ); |
231 | | - } |
232 | | - } |
233 | | - else { |
234 | | - $propertyName = $printRequest->getHTMLText( $skin ); |
235 | | - } |
236 | | - |
237 | | - if ( $propertyName != '' ) $propertyName .= ': '; |
238 | | - |
239 | | - if ( $this->linkAbsolute ) { |
240 | | - $hasPage = $object->getTypeID() == '_wpg'; |
241 | | - |
242 | | - if ( $hasPage ) { |
243 | | - $t = Title::newFromText( $object->getLongText( $this->outputmode, NULL ), NS_MAIN ); |
244 | | - $hasPage = $t->exists(); |
245 | | - } |
246 | | - |
247 | | - if ( $hasPage ) { |
248 | | - $propertyValue = Html::element( |
249 | | - 'a', |
250 | | - array( 'href' => $t->getFullUrl() ), |
251 | | - $object->getLongText( $this->outputmode, NULL ) |
252 | | - ); |
253 | | - } |
254 | | - else { |
255 | | - $propertyValue = $object->getLongText( $this->outputmode, NULL ); |
256 | | - } |
257 | | - } |
258 | | - else { |
259 | | - $propertyValue = $object->getLongText( $this->outputmode, $skin ); |
260 | | - } |
261 | | - |
262 | | - $text .= $propertyName . $propertyValue . '<br />'; |
| 227 | + else if ( $object->getTypeID() != '_geo' && $i != 0 ) { |
| 228 | + $properties[] = $this->handleResultProperty( $object, $printRequest ); |
263 | 229 | } |
264 | | - |
265 | | - if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) { |
| 230 | + else if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) { |
266 | 231 | $coords[] = $object->getDBkeys(); |
267 | 232 | } |
268 | 233 | } |
269 | 234 | } |
270 | 235 | |
| 236 | + if ( count( $properties ) > 0 && $text != '' ) { |
| 237 | + $text .= $this->subjectSeparator; |
| 238 | + } |
| 239 | + |
| 240 | + $text .= implode( '<br />', $properties ); |
| 241 | + $icon = $this->getLocationIcon( $row ); |
| 242 | + |
| 243 | + return $this->buildLocationsList( $coords, $title, $text, $icon ); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * Handles a SMWDataValue subject value. |
| 248 | + * Gets the plain text title and creates the HTML text with headers and the like. |
| 249 | + * |
| 250 | + * @since 0.8 |
| 251 | + * |
| 252 | + * @param SMWDataValue $object |
| 253 | + * |
| 254 | + * @return array with title and text |
| 255 | + */ |
| 256 | + protected function handleResultSubject( SMWDataValue $object ) { |
| 257 | + global $wgUser; |
| 258 | + |
| 259 | + $title = $object->getLongText( $this->outputmode, null ); |
| 260 | + $text = ''; |
| 261 | + |
| 262 | + if ( !$this->titleLinkSeperate && $this->linkAbsolute ) { |
| 263 | + $text = Html::element( |
| 264 | + 'a', |
| 265 | + array( 'href' => $object->getTitle()->getFullUrl() ), |
| 266 | + $object->getTitle()->getText() |
| 267 | + ); |
| 268 | + } |
| 269 | + else { |
| 270 | + $text = $object->getLongText( $this->outputmode, $wgUser->getSkin() ); |
| 271 | + } |
| 272 | + |
| 273 | + if ( $this->boldSubject ) { |
| 274 | + $text = '<b>' . $text . '</b>'; |
| 275 | + } |
| 276 | + |
| 277 | + if ( $this->titleLinkSeperate ) { |
| 278 | + $text .= Html::element( |
| 279 | + 'a', |
| 280 | + array( 'href' => $object->getTitle()->getFullUrl() ), |
| 281 | + str_replace( '$1', $object->getTitle()->getText(), $this->params['pagelinktext'] ) |
| 282 | + ); |
| 283 | + } |
| 284 | + |
| 285 | + return array( $title, $text ); |
| 286 | + } |
| 287 | + |
| 288 | + /** |
| 289 | + * Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue). |
| 290 | + * |
| 291 | + * @since 0.8 |
| 292 | + * |
| 293 | + * @param SMWDataValue $object |
| 294 | + * @param SMWPrintRequest $printRequest |
| 295 | + * |
| 296 | + * @return string |
| 297 | + */ |
| 298 | + protected function handleResultProperty( SMWDataValue $object, SMWPrintRequest $printRequest ) { |
| 299 | + global $wgUser; |
| 300 | + |
| 301 | + if ( $this->linkAbsolute ) { |
| 302 | + $t = Title::newFromText( $printRequest->getHTMLText( NULL ), SMW_NS_PROPERTY ); |
| 303 | + |
| 304 | + if ( $t->exists() ) { |
| 305 | + $propertyName = $propertyName = Html::element( |
| 306 | + 'a', |
| 307 | + array( 'href' => $t->getFullUrl() ), |
| 308 | + $printRequest->getHTMLText( NULL ) |
| 309 | + ); |
| 310 | + } |
| 311 | + else { |
| 312 | + $propertyName = $printRequest->getHTMLText( NULL ); |
| 313 | + } |
| 314 | + } |
| 315 | + else { |
| 316 | + $propertyName = $printRequest->getHTMLText( $wgUser->getSkin() ); |
| 317 | + } |
| 318 | + |
| 319 | + if ( $this->linkAbsolute ) { |
| 320 | + $hasPage = $object->getTypeID() == '_wpg'; |
| 321 | + |
| 322 | + if ( $hasPage ) { |
| 323 | + $t = Title::newFromText( $object->getLongText( $this->outputmode, NULL ), NS_MAIN ); |
| 324 | + $hasPage = $t->exists(); |
| 325 | + } |
| 326 | + |
| 327 | + if ( $hasPage ) { |
| 328 | + $propertyValue = Html::element( |
| 329 | + 'a', |
| 330 | + array( 'href' => $t->getFullUrl() ), |
| 331 | + $object->getLongText( $this->outputmode, NULL ) |
| 332 | + ); |
| 333 | + } |
| 334 | + else { |
| 335 | + $propertyValue = $object->getLongText( $this->outputmode, NULL ); |
| 336 | + } |
| 337 | + } |
| 338 | + else { |
| 339 | + $propertyValue = $object->getLongText( $this->outputmode, $wgUser->getSkin() ); |
| 340 | + } |
| 341 | + |
| 342 | + return $propertyName . ( $propertyName == '' ? '' : ': ' ) . $propertyValue; |
| 343 | + } |
| 344 | + |
| 345 | + /** |
| 346 | + * Builds a set of locations with the provided title, text and icon. |
| 347 | + * |
| 348 | + * @since 0.8 |
| 349 | + * |
| 350 | + * @param array $coords |
| 351 | + * @param string $title |
| 352 | + * @param string $text |
| 353 | + * @param string $icon |
| 354 | + * |
| 355 | + * @return array of MapsLocation |
| 356 | + */ |
| 357 | + protected function buildLocationsList( array $coords, $title, $text, $icon ) { |
| 358 | + $locations = array(); |
| 359 | + |
271 | 360 | foreach ( $coords as $coord ) { |
272 | 361 | if ( count( $coord ) >= 2 ) { |
273 | | - if ( $smgUseSpatialExtensions ) { |
274 | | - // TODO |
275 | | - } |
276 | | - else { |
277 | | - list( $lat, $lon ) = $coord; |
278 | | - } |
| 362 | + $location = new MapsLocation(); |
| 363 | + $location->setCoordinates( $coord ); |
279 | 364 | |
280 | | - if ( $lat != '' && $lon != '' ) { |
281 | | - $icon = $this->getLocationIcon( $row ); |
| 365 | + if ( $location->isValid() ) { |
| 366 | + $location->setTitle( $title ); |
| 367 | + $location->setText( $text ); |
| 368 | + $location->setIcon( $icon ); |
282 | 369 | |
283 | | - $location = new MapsLocation(); |
284 | | - |
285 | | - $location->setCoordinates( array( $lat, $lon ) ); |
286 | | - |
287 | | - if ( $location->isValid() ) { |
288 | | - $location->setTitle( $title ); |
289 | | - $location->setText( $text ); |
290 | | - $location->setIcon( $icon ); |
291 | | - |
292 | | - $locations[] = $location; |
293 | | - } |
| 370 | + $locations[] = $location; |
294 | 371 | } |
295 | 372 | } |
296 | | - } |
| 373 | + } |
297 | 374 | |
298 | 375 | return $locations; |
299 | 376 | } |
Index: branches/SemanticMaps0.8/includes/queryprinters/SM_KMLPrinter.php |
— | — | @@ -82,6 +82,7 @@ |
83 | 83 | $queryHandler = new SMQueryHandler( $res, $outputmode, $params['linkabsolute'], $params['pagelinktext'], false ); |
84 | 84 | $queryHandler->setText( $params['text'] ); |
85 | 85 | $queryHandler->setTitle( $params['title'] ); |
| 86 | + $queryHandler->setSubjectSeparator( '' ); |
86 | 87 | |
87 | 88 | $formatter = new MapsKMLFormatter( $params ); |
88 | 89 | $formatter->addPlacemarks( $queryHandler->getLocations() ); |