Completed
Push — master ( bb3b51...1b142a )
by Jeroen De
03:42
created

GeoJsonContent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 58
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fillParserOutput() 0 18 3
A getMapHtml() 0 13 1
A wrapHtmlInThumbDivs() 0 15 1
1
<?php
2
3
namespace Maps\MediaWiki\Content;
4
5
use Html;
6
use ParserOptions;
7
use ParserOutput;
8
use Title;
9
10
class GeoJsonContent extends \JsonContent {
11
12
	public const CONTENT_MODEL_ID = 'GeoJSON';
13
14
	public function __construct( string $text, string $modelId = self::CONTENT_MODEL_ID ) {
15
		parent::__construct( $text, $modelId );
16
	}
17
18
	protected function fillParserOutput( Title $title, $revId, ParserOptions $options,
19
		$generateHtml, ParserOutput &$output ) {
20
21
		if ( $generateHtml && $this->isValid() ) {
22
			$output->setText(
23
				$this->getMapHtml()
24
				.
25
				Html::element(
26
					'script',
27
					[],
28
					'var GeoJson =' . $this->beautifyJSON() . ';'
29
				)
30
			);
31
			$output->addModules( 'ext.maps.leaflet.editor' );
32
		} else {
33
			$output->setText( '' );
34
		}
35
	}
36
37
	private function getMapHtml(): string {
38
		return $this->wrapHtmlInThumbDivs(
39
			Html::rawElement(
40
				'div',
41
				[
42
					'id' => 'GeoJsonMap',
43
					'style' => "width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;",
44
					'class' => 'maps-map maps-leaflet GeoJsonMap'
45
				],
46
				wfMessage( 'maps-loading-map' )->inContentLanguage()->escaped()
47
			)
48
		);
49
	}
50
51
	private function wrapHtmlInThumbDivs( string $html ): string {
52
		return Html::rawElement(
53
			'div',
54
			[
55
				'class' => 'thumb'
56
			],
57
			Html::rawElement(
58
				'div',
59
				[
60
					'class' => 'thumbinner'
61
				],
62
				$html
63
			)
64
		);
65
	}
66
67
}
68