1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Maps\Elements\Location; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class for handling geographical SMW queries. |
7
|
|
|
* |
8
|
|
|
* @since 0.7.3 |
9
|
|
|
* |
10
|
|
|
* @licence GNU GPL v2+ |
11
|
|
|
* @author Jeroen De Dauw < [email protected] > |
12
|
|
|
*/ |
13
|
|
|
class SMQueryHandler { |
14
|
|
|
|
15
|
|
|
protected $queryResult; |
16
|
|
|
protected $outputmode; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @since 2.0 |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $geoShapes = array( |
24
|
|
|
'lines' => array(), |
25
|
|
|
'locations' => array(), |
26
|
|
|
'polygons' => array() |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The template to use for the text, or false if there is none. |
31
|
|
|
* |
32
|
|
|
* @since 0.7.3 |
33
|
|
|
* |
34
|
|
|
* @var string|boolean false |
35
|
|
|
*/ |
36
|
|
|
protected $template = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The global icon. |
40
|
|
|
* |
41
|
|
|
* @since 0.7.3 |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
public $icon = ''; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The global text. |
49
|
|
|
* |
50
|
|
|
* @since 1.0 |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
public $text = ''; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The global title. |
58
|
|
|
* |
59
|
|
|
* @since 1.0 |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
public $title = ''; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Make a separate link to the title or not? |
67
|
|
|
* |
68
|
|
|
* @since 0.7.3 |
69
|
|
|
* |
70
|
|
|
* @var boolean |
71
|
|
|
*/ |
72
|
|
|
public $titleLinkSeparate; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Should link targets be made absolute (instead of relative)? |
76
|
|
|
* |
77
|
|
|
* @since 1.0 |
78
|
|
|
* |
79
|
|
|
* @var boolean |
80
|
|
|
*/ |
81
|
|
|
protected $linkAbsolute; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The text used for the link to the page (if it's created). $1 will be replaced by the page name. |
85
|
|
|
* |
86
|
|
|
* @since 1.0 |
87
|
|
|
* |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
protected $pageLinkText; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* A separator to use between the subject and properties in the text field. |
94
|
|
|
* |
95
|
|
|
* @since 1.0 |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
protected $subjectSeparator = '<hr />'; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Make the subject in the text bold or not? |
103
|
|
|
* |
104
|
|
|
* @since 1.0 |
105
|
|
|
* |
106
|
|
|
* @var boolean |
107
|
|
|
*/ |
108
|
|
|
protected $boldSubject = true; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Show the subject in the text or not? |
112
|
|
|
* |
113
|
|
|
* @since 1.0 |
114
|
|
|
* |
115
|
|
|
* @var boolean |
116
|
|
|
*/ |
117
|
|
|
protected $showSubject = true; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Hide the namespace or not. |
121
|
|
|
* |
122
|
|
|
* @var boolean |
123
|
|
|
*/ |
124
|
|
|
protected $hideNamespace = false; |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Defines which article names in the result are hyperlinked, all normally is the default |
129
|
|
|
* none, subject, all |
130
|
|
|
*/ |
131
|
|
|
protected $linkStyle = 'all'; |
132
|
|
|
|
133
|
|
|
/* |
134
|
|
|
* Show headers (with links), show headers (just text) or hide them. show is default |
135
|
|
|
* show, plain, hide |
136
|
|
|
*/ |
137
|
|
|
protected $headerStyle = 'show'; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Marker icon to show when marker equals active page |
141
|
|
|
* |
142
|
|
|
* @var string |
143
|
|
|
*/ |
144
|
|
|
protected $activeIcon; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @var string |
148
|
|
|
*/ |
149
|
|
|
protected $userParam = ''; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Constructor. |
153
|
|
|
* |
154
|
|
|
* @since 0.7.3 |
155
|
|
|
* |
156
|
|
|
* @param SMWQueryResult $queryResult |
157
|
|
|
* @param integer $outputmode |
158
|
|
|
* @param boolean $linkAbsolute |
159
|
|
|
* @param string $pageLinkText |
160
|
|
|
* @param boolean $titleLinkSeparate |
161
|
|
|
* @param string $activeIcon |
162
|
|
|
*/ |
163
|
|
|
public function __construct( SMWQueryResult $queryResult, $outputmode, $linkAbsolute = false, $pageLinkText = '$1', $titleLinkSeparate = false, $hideNamespace = false, $activeIcon = null ) { |
164
|
|
|
$this->queryResult = $queryResult; |
165
|
|
|
$this->outputmode = $outputmode; |
166
|
|
|
|
167
|
|
|
$this->linkAbsolute = $linkAbsolute; |
168
|
|
|
$this->pageLinkText = $pageLinkText; |
169
|
|
|
$this->titleLinkSeparate = $titleLinkSeparate; |
170
|
|
|
$this->hideNamespace = $hideNamespace; |
171
|
|
|
$this->activeIcon = $activeIcon; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Sets the template. |
176
|
|
|
* |
177
|
|
|
* @since 1.0 |
178
|
|
|
* |
179
|
|
|
* @param string $template |
180
|
|
|
*/ |
181
|
|
|
public function setTemplate( $template ) { |
182
|
|
|
$this->template = $template === '' ? false : $template; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @since 3.2 |
187
|
|
|
* |
188
|
|
|
* @param string $userParam |
189
|
|
|
*/ |
190
|
|
|
public function setUserParam( $userParam ) { |
191
|
|
|
$this->userParam = $userParam; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Sets the global icon. |
196
|
|
|
* |
197
|
|
|
* @since 1.0 |
198
|
|
|
* |
199
|
|
|
* @param string $icon |
200
|
|
|
*/ |
201
|
|
|
public function setIcon( $icon ) { |
202
|
|
|
$this->icon = $icon; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Sets the global title. |
207
|
|
|
* |
208
|
|
|
* @since 1.0 |
209
|
|
|
* |
210
|
|
|
* @param string $title |
211
|
|
|
*/ |
212
|
|
|
public function setTitle( $title ) { |
213
|
|
|
$this->title = $title; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Sets the global text. |
218
|
|
|
* |
219
|
|
|
* @since 1.0 |
220
|
|
|
* |
221
|
|
|
* @param string $text |
222
|
|
|
*/ |
223
|
|
|
public function setText( $text ) { |
224
|
|
|
$this->text = $text; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Sets the subject separator. |
229
|
|
|
* |
230
|
|
|
* @since 1.0 |
231
|
|
|
* |
232
|
|
|
* @param string $subjectSeparator |
233
|
|
|
*/ |
234
|
|
|
public function setSubjectSeparator( $subjectSeparator ) { |
235
|
|
|
$this->subjectSeparator = $subjectSeparator; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Sets if the subject should be made bold in the text. |
240
|
|
|
* |
241
|
|
|
* @since 1.0 |
242
|
|
|
* |
243
|
|
|
* @param string $boldSubject |
244
|
|
|
*/ |
245
|
|
|
public function setBoldSubject( $boldSubject ) { |
246
|
|
|
$this->boldSubject = $boldSubject; |
|
|
|
|
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Sets if the subject should shown in the text. |
251
|
|
|
* |
252
|
|
|
* @since 1.0 |
253
|
|
|
* |
254
|
|
|
* @param string $showSubject |
255
|
|
|
*/ |
256
|
|
|
public function setShowSubject( $showSubject ) { |
257
|
|
|
$this->showSubject = $showSubject; |
|
|
|
|
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Sets the text for the link to the page when separate from the title. |
262
|
|
|
* |
263
|
|
|
* @since 1.0 |
264
|
|
|
* |
265
|
|
|
* @param string $text |
266
|
|
|
*/ |
267
|
|
|
public function setPageLinkText( $text ) { |
268
|
|
|
$this->pageLinkText = $text; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* |
273
|
|
|
* @since 2.0.1 |
274
|
|
|
* |
275
|
|
|
* @param boolean $link |
276
|
|
|
*/ |
277
|
|
|
public function setLinkStyle ( $link ) { |
278
|
|
|
$this->linkStyle = $link; |
|
|
|
|
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* |
283
|
|
|
* @since 2.0.1 |
284
|
|
|
* |
285
|
|
|
* @param boolean $headers |
286
|
|
|
*/ |
287
|
|
|
public function setHeaderStyle ( $headers ) { |
288
|
|
|
$this->headerStyle = $headers; |
|
|
|
|
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @since 2.0 |
293
|
|
|
* |
294
|
|
|
* @return array |
295
|
|
|
*/ |
296
|
|
|
public function getShapes() { |
297
|
|
|
$this->findShapes(); |
298
|
|
|
return $this->geoShapes; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @since 2.0 |
303
|
|
|
*/ |
304
|
|
|
protected function findShapes() { |
305
|
|
|
while ( ( $row = $this->queryResult->getNext() ) !== false ) { |
306
|
|
|
$this->handleResultRow( $row ); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Returns the locations found in the provided result row. |
312
|
|
|
* |
313
|
|
|
* @since 0.7.3 |
314
|
|
|
* |
315
|
|
|
* @param SMWResultArray[] $row |
316
|
|
|
*/ |
317
|
|
|
protected function handleResultRow( array $row ) { |
318
|
|
|
$locations = array(); |
319
|
|
|
$properties = array(); |
320
|
|
|
|
321
|
|
|
$title = ''; |
322
|
|
|
$text = ''; |
323
|
|
|
|
324
|
|
|
// Loop through all fields of the record. |
325
|
|
|
foreach ( $row as $i => $resultArray ) { |
326
|
|
|
/* SMWPrintRequest */ $printRequest = $resultArray->getPrintRequest(); |
327
|
|
|
|
328
|
|
|
// Loop through all the parts of the field value. |
329
|
|
|
while ( ( /* SMWDataValue */ $dataValue = $resultArray->getNextDataValue() ) !== false ) { |
330
|
|
|
if ( $dataValue->getTypeID() == '_wpg' && $i == 0 ) { |
331
|
|
|
list( $title, $text ) = $this->handleResultSubject( $dataValue ); |
|
|
|
|
332
|
|
|
} |
333
|
|
|
else if ( $dataValue->getTypeID() == '_str' && $i == 0 ) { |
334
|
|
|
$title = $dataValue->getLongText( $this->outputmode, null ); |
335
|
|
|
$text = $dataValue->getLongText( $this->outputmode, smwfGetLinker() ); |
336
|
|
|
} |
337
|
|
|
else if ( $dataValue->getTypeID() == '_gpo' ) { |
338
|
|
|
$dataItem = $dataValue->getDataItem(); |
339
|
|
|
$polyHandler = new PolygonHandler ( $dataItem->getString() ); |
340
|
|
|
$this->geoShapes[ $polyHandler->getGeoType() ][] = $polyHandler->shapeFromText(); |
341
|
|
|
} |
342
|
|
|
else if ( $dataValue->getTypeID() != '_geo' && $i != 0 && !$this->isHeadersHide()) { |
343
|
|
|
$properties[] = $this->handleResultProperty( $dataValue, $printRequest ); |
|
|
|
|
344
|
|
|
} |
345
|
|
|
else if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) { |
346
|
|
|
$dataItem = $dataValue->getDataItem(); |
347
|
|
|
|
348
|
|
|
$location = Location::newFromLatLon( $dataItem->getLatitude(), $dataItem->getLongitude() ); |
349
|
|
|
|
350
|
|
|
$locations[] = $location; |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
if ( count( $properties ) > 0 && $text !== '' ) { |
356
|
|
|
$text .= $this->subjectSeparator; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
$icon = $this->getLocationIcon( $row ); |
360
|
|
|
|
361
|
|
|
$this->geoShapes['locations'] = array_merge( |
362
|
|
|
$this->geoShapes['locations'], |
363
|
|
|
$this->buildLocationsList( |
364
|
|
|
$locations, |
365
|
|
|
$text, |
366
|
|
|
$icon, |
367
|
|
|
$properties, |
368
|
|
|
Title::newFromText( $title ) |
369
|
|
|
) |
370
|
|
|
); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Handles a SMWWikiPageValue subject value. |
375
|
|
|
* Gets the plain text title and creates the HTML text with headers and the like. |
376
|
|
|
* |
377
|
|
|
* @since 1.0 |
378
|
|
|
* |
379
|
|
|
* @param SMWWikiPageValue $object |
380
|
|
|
* |
381
|
|
|
* @return array with title and text |
382
|
|
|
*/ |
383
|
|
|
protected function handleResultSubject( SMWWikiPageValue $object ) { |
384
|
|
|
$title = $object->getLongText( $this->outputmode, null ); |
385
|
|
|
$text = ''; |
386
|
|
|
|
387
|
|
|
if ( $this->showSubject ) { |
388
|
|
|
if( !$this->showArticleLink()){ |
389
|
|
|
$text = $this->hideNamespace ? $object->getText() : $object->getTitle()->getFullText(); |
390
|
|
|
}else if ( !$this->titleLinkSeparate && $this->linkAbsolute ) { |
391
|
|
|
$text = Html::element( |
392
|
|
|
'a', |
393
|
|
|
array( 'href' => $object->getTitle()->getFullUrl() ), |
394
|
|
|
$this->hideNamespace ? $object->getText() : $object->getTitle()->getFullText() |
395
|
|
|
); |
396
|
|
|
} |
397
|
|
|
else { |
398
|
|
|
if($this->hideNamespace){ |
399
|
|
|
$text = $object->getShortHTMLText(smwfGetLinker()); |
400
|
|
|
}else{ |
401
|
|
|
$text = $object->getLongHTMLText( smwfGetLinker() ); |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
if ( $this->boldSubject ) { |
406
|
|
|
$text = '<b>' . $text . '</b>'; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
if ( $this->titleLinkSeparate ) { |
410
|
|
|
$txt = $object->getTitle()->getText(); |
411
|
|
|
|
412
|
|
|
if ( $this->pageLinkText !== '' ) { |
413
|
|
|
$txt = str_replace( '$1', $txt, $this->pageLinkText ); |
414
|
|
|
} |
415
|
|
|
$text .= Html::element( |
416
|
|
|
'a', |
417
|
|
|
array( 'href' => $object->getTitle()->getFullUrl() ), |
418
|
|
|
$txt |
419
|
|
|
); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
return array( $title, $text ); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
protected function showArticleLink(){ |
427
|
|
|
return $this->linkStyle !== 'none'; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue). |
432
|
|
|
* |
433
|
|
|
* @since 1.0 |
434
|
|
|
* |
435
|
|
|
* @param SMWDataValue $object |
436
|
|
|
* @param SMWPrintRequest $printRequest |
437
|
|
|
* |
438
|
|
|
* @return string |
439
|
|
|
*/ |
440
|
|
|
protected function handleResultProperty( SMWDataValue $object, SMWPrintRequest $printRequest ) { |
441
|
|
|
if($this->isHeadersHide()){ |
442
|
|
|
return ''; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
if ( $this->template ) { |
446
|
|
|
if ( $object instanceof SMWWikiPageValue ) { |
447
|
|
|
return $object->getTitle()->getPrefixedText(); |
448
|
|
|
} else { |
449
|
|
|
return $object->getLongText( SMW_OUTPUT_WIKI, null ); |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
if ( $this->linkAbsolute ) { |
454
|
|
|
$titleText = $printRequest->getText( null ); |
455
|
|
|
$t = Title::newFromText($titleText , SMW_NS_PROPERTY ); |
456
|
|
|
|
457
|
|
|
if ($this->isHeadersShow() && $t instanceof Title && $t->exists() ) { |
|
|
|
|
458
|
|
|
$propertyName = $propertyName = Html::element( |
459
|
|
|
'a', |
460
|
|
|
array( 'href' => $t->getFullUrl() ), |
461
|
|
|
$printRequest->getHTMLText( null ) |
462
|
|
|
); |
463
|
|
|
} |
464
|
|
|
else { |
465
|
|
|
$propertyName = $titleText; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
else { |
469
|
|
|
if($this->isHeadersShow()){ |
470
|
|
|
$propertyName = $printRequest->getHTMLText( smwfGetLinker() ); |
471
|
|
|
}else if($this->isHeadersPlain()){ |
472
|
|
|
$propertyName = $printRequest->getText(null); |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
if ( $this->linkAbsolute ) { |
477
|
|
|
$hasPage = $object->getTypeID() == '_wpg'; |
478
|
|
|
|
479
|
|
|
if ( $hasPage ) { |
480
|
|
|
$t = Title::newFromText( $object->getLongText( $this->outputmode, null ), NS_MAIN ); |
481
|
|
|
$hasPage = $t !== null && $t->exists(); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
if ( $hasPage ) { |
485
|
|
|
$propertyValue = Html::element( |
486
|
|
|
'a', |
487
|
|
|
array( 'href' => $t->getFullUrl() ), |
|
|
|
|
488
|
|
|
$object->getLongText( $this->outputmode, null ) |
489
|
|
|
); |
490
|
|
|
} |
491
|
|
|
else { |
492
|
|
|
$propertyValue = $object->getLongText( $this->outputmode, null ); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
else { |
496
|
|
|
$propertyValue = $object->getLongText( $this->outputmode, smwfGetLinker() ); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
return $propertyName . ( $propertyName === '' ? '' : ': ' ) . $propertyValue; |
|
|
|
|
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
|
503
|
|
|
protected function isHeadersShow(){ |
504
|
|
|
return $this->headerStyle === 'show'; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
protected function isHeadersHide(){ |
508
|
|
|
return $this->headerStyle === 'hide'; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
protected function isHeadersPlain(){ |
512
|
|
|
return $this->headerStyle === 'plain'; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Builds a set of locations with the provided title, text and icon. |
517
|
|
|
* |
518
|
|
|
* @since 1.0 |
519
|
|
|
* |
520
|
|
|
* @param Location[] $locations |
521
|
|
|
* @param string $text |
522
|
|
|
* @param string $icon |
523
|
|
|
* @param array $properties |
524
|
|
|
* @param Title|null $title |
525
|
|
|
* |
526
|
|
|
* @return Location[] |
527
|
|
|
*/ |
528
|
|
|
protected function buildLocationsList( array $locations, $text, $icon, array $properties, Title $title = null ) { |
529
|
|
|
if ( $this->template ) { |
530
|
|
|
global $wgParser; |
531
|
|
|
$parser = clone $wgParser; |
532
|
|
|
} |
533
|
|
|
else { |
534
|
|
|
$text .= implode( '<br />', $properties ); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
if ( $title === null ) { |
538
|
|
|
$titleOutput = ''; |
539
|
|
|
} |
540
|
|
|
else { |
541
|
|
|
$titleOutput = $this->hideNamespace ? $title->getText() : $title->getFullText(); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
foreach ( $locations as &$location ) { |
545
|
|
|
if ( $this->template ) { |
546
|
|
|
$segments = array_merge( |
547
|
|
|
array( |
548
|
|
|
$this->template, |
549
|
|
|
'title=' . $titleOutput, |
550
|
|
|
'latitude=' . $location->getCoordinates()->getLatitude(), |
551
|
|
|
'longitude=' . $location->getCoordinates()->getLongitude(), |
552
|
|
|
'userparam=' . $this->userParam |
553
|
|
|
), |
554
|
|
|
$properties |
555
|
|
|
); |
556
|
|
|
|
557
|
|
|
$text .= $parser->parse( '{{' . implode( '|', $segments ) . '}}', $parser->getTitle(), new ParserOptions() )->getText(); |
|
|
|
|
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$location->setTitle( $titleOutput ); |
561
|
|
|
$location->setText( $text ); |
562
|
|
|
$location->setIcon( $icon ); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
return $locations; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Get the icon for a row. |
570
|
|
|
* |
571
|
|
|
* @since 0.7.3 |
572
|
|
|
* |
573
|
|
|
* @param array $row |
574
|
|
|
* |
575
|
|
|
* @return string |
576
|
|
|
*/ |
577
|
|
|
protected function getLocationIcon( array $row ) { |
578
|
|
|
$icon = ''; |
579
|
|
|
$legend_labels = array(); |
580
|
|
|
|
581
|
|
|
//Check for activeicon parameter |
582
|
|
|
|
583
|
|
|
if ( $this->shouldGetActiveIconUrlFor( $row[0]->getResultSubject()->getTitle() ) ){ |
584
|
|
|
$icon = MapsMapper::getFileUrl( $this->activeIcon ); |
|
|
|
|
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
// Look for display_options field, which can be set by Semantic Compound Queries |
588
|
|
|
// the location of this field changed in SMW 1.5 |
589
|
|
|
$display_location = method_exists( $row[0], 'getResultSubject' ) ? $row[0]->getResultSubject() : $row[0]; |
590
|
|
|
|
591
|
|
|
if ( property_exists( $display_location, 'display_options' ) && is_array( $display_location->display_options ) ) { |
592
|
|
|
$display_options = $display_location->display_options; |
593
|
|
|
if ( array_key_exists( 'icon', $display_options ) ) { |
594
|
|
|
$icon = $display_options['icon']; |
595
|
|
|
|
596
|
|
|
// 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 |
597
|
|
|
if ( array_key_exists( 'legend label', $display_options ) ) { |
598
|
|
|
|
599
|
|
|
$legend_label = $display_options['legend label']; |
600
|
|
|
|
601
|
|
|
if ( ! array_key_exists( $icon, $legend_labels ) ) { |
602
|
|
|
$legend_labels[$icon] = $legend_label; |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
} // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here |
607
|
|
|
elseif ( $this->icon !== '' ) { |
608
|
|
|
$icon = MapsMapper::getFileUrl( $this->icon ); |
|
|
|
|
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
return $icon; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
private function shouldGetActiveIconUrlFor( Title $title ) { |
615
|
|
|
global $wgTitle; |
616
|
|
|
|
617
|
|
|
return isset( $this->activeIcon ) && is_object( $wgTitle ) |
618
|
|
|
&& $wgTitle->equals( $title ); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* @param boolean $hideNamespace |
623
|
|
|
*/ |
624
|
|
|
public function setHideNamespace( $hideNamespace ) { |
625
|
|
|
$this->hideNamespace = $hideNamespace; |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @return boolean |
630
|
|
|
*/ |
631
|
|
|
public function getHideNamespace() { |
632
|
|
|
return $this->hideNamespace; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* @param string $activeIcon |
637
|
|
|
*/ |
638
|
|
|
public function setActiveIcon( $activeIcon ){ |
639
|
|
|
$this->activeIcon = $activeIcon; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* @return string |
644
|
|
|
*/ |
645
|
|
|
public function getActiveIcon( ){ |
646
|
|
|
return $this->activeIcon; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
} |
650
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.