Completed
Push — master ( f67785...2177d9 )
by mw
07:32
created

SMQueryHandler::setUserParam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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;
0 ignored issues
show
Documentation Bug introduced by
The property $boldSubject was declared of type boolean, but $boldSubject is of type string. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
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;
0 ignored issues
show
Documentation Bug introduced by
The property $showSubject was declared of type boolean, but $showSubject is of type string. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
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;
0 ignored issues
show
Documentation Bug introduced by
The property $linkStyle was declared of type string, but $link is of type boolean. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
279
	}
280
281
	/**
282
	 *
283
	 * @since 2.0.1
284
	 *
285
	 * @param boolean $headers
286
	 */
287
	public function setHeaderStyle ( $headers ) {
288
		$this->headerStyle = $headers;
0 ignored issues
show
Documentation Bug introduced by
The property $headerStyle was declared of type string, but $headers is of type boolean. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
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 );
0 ignored issues
show
Compatibility introduced by
$dataValue of type object<SMWDataValue> is not a sub-type of object<SMWWikiPageValue>. It seems like you assume a child class of the class SMWDataValue to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
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 );
0 ignored issues
show
Documentation introduced by
$printRequest is of type object<SMW\Query\PrintRequest>, but the function expects a object<SMWPrintRequest>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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() ) {
0 ignored issues
show
Bug introduced by
The class Title does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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() ),
0 ignored issues
show
Bug introduced by
The variable $t does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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;
0 ignored issues
show
Bug introduced by
The variable $propertyName does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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();
0 ignored issues
show
Bug introduced by
The variable $parser does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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 );
0 ignored issues
show
Deprecated Code introduced by
The method MapsMapper::getFileUrl() has been deprecated.

This method has been deprecated.

Loading history...
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 );
0 ignored issues
show
Deprecated Code introduced by
The method MapsMapper::getFileUrl() has been deprecated.

This method has been deprecated.

Loading history...
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