Completed
Push — cs ( 148090 )
by Jeroen De
03:24
created

SMQueryHandler::setActiveIcon()   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

Importance

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

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
582
		return $GLOBALS['wgParser'];
583
	}
584
585
	/**
586
	 * @return boolean
587
	 */
588
	public function getHideNamespace() {
589
		return $this->hideNamespace;
590
	}
591
592
	/**
593
	 * @param boolean $hideNamespace
594
	 */
595
	public function setHideNamespace( $hideNamespace ) {
596
		$this->hideNamespace = $hideNamespace;
597
	}
598
599
	/**
600
	 * @return string
601
	 */
602
	public function getActiveIcon() {
603
		return $this->activeIcon;
604
	}
605
606
	/**
607
	 * @param string $activeIcon
608
	 */
609
	public function setActiveIcon( $activeIcon ) {
610
		$this->activeIcon = $activeIcon;
611
	}
612
613
}
614