Completed
Push — master ( 684184...9a35aa )
by Jeroen De
08:07
created

includes/services/Leaflet/Maps_Leaflet.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Class holding information and functionality specific to Leaflet.
5
 * This information and features can be used by any mapping feature.
6
 *
7
 * @licence GNU GPL v2+
8
 * @author Pavel Astakhov < [email protected] >
9
 */
10
class MapsLeaflet extends MapsMappingService {
11
12
	/**
13
	 * Constructor
14
	 */
15
	public function __construct( $serviceName ) {
16
		parent::__construct(
17
			$serviceName,
18
			[ 'leafletmaps', 'leaflet' ]
19
		);
20
	}
21
22
	/**
23
	 * @see MapsMappingService::addParameterInfo
24
	 *
25
	 * @since 3.0
26
	 */
27
	public function addParameterInfo( array &$params ) {
0 ignored issues
show
addParameterInfo 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...
28
		global $GLOBALS;
29
30
		$params['zoom'] = [
31
			'type' => 'integer',
32
			'range' => [ 0, 20 ],
33
			'default' => false,
34
			'message' => 'maps-par-zoom'
35
		];
36
37
		$params['defzoom'] = [
38
			'type' => 'integer',
39
			'range' => [ 0, 20 ],
40
			'default' => self::getDefaultZoom(),
41
			'message' => 'maps-leaflet-par-defzoom'
42
		];
43
44
		$params['layer'] = [
45
			'type' => 'string',
46
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableLayers'], true, true ),
47
			'default' => $GLOBALS['egMapsLeafletLayer'],
48
			'message' =>'maps-leaflet-par-layer',
49
		];
50
51
		$params['overlaylayers'] = [
52
			'type' => 'string',
53
			'values' => array_keys( $GLOBALS['egMapsLeafletAvailableOverlayLayers'], true, true ),
54
			'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
55
			'message' =>'maps-leaflet-par-overlaylayers',
56
			'islist' => true,
57
		];
58
59
		$params['resizable'] = [
60
			'type' => 'boolean',
61
			'default' => $GLOBALS['egMapsResizableByDefault'],
62
			'message' => 'maps-par-resizable'
63
		];
64
65
		$params['enablefullscreen'] = [
66
			'type' => 'boolean',
67
			'default' => false,
68
			'message' => 'maps-par-enable-fullscreen',
69
		];
70
71
		$params['markercluster'] = [
72
			'type' => 'boolean',
73
			'default' => false,
74
			'message' => 'maps-par-markercluster',
75
		];
76
77
		$params['clustermaxzoom'] = [
78
			'type' => 'integer',
79
			'default' => 20,
80
			'message' => 'maps-par-clustermaxzoom',
81
		];
82
83
		$params['clusterzoomonclick'] = [
84
			'type' => 'boolean',
85
			'default' => true,
86
			'message' => 'maps-par-clusterzoomonclick',
87
		];
88
89
		$params['clustermaxradius'] = [
90
			'type' => 'integer',
91
			'default' => 80,
92
			'message' => 'maps-par-maxclusterradius',
93
		];
94
95
		$params['clusterspiderfy'] = [
96
			'type' => 'boolean',
97
			'default' => true,
98
			'message' => 'maps-leaflet-par-clusterspiderfy',
99
		];
100
	}
101
102
	/**
103
	 * @see iMappingService::getDefaultZoom
104
	 *
105
	 * @since 3.0
106
	 */
107
	public function getDefaultZoom() {
0 ignored issues
show
getDefaultZoom 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...
108
		return $GLOBALS['egMapsLeafletZoom'];
109
	}
110
111
	/**
112
	 * @see MapsMappingService::getMapId
113
	 *
114
	 * @since 3.0
115
	 */
116
	public function getMapId( $increment = true ) {
117
		static $mapsOnThisPage = 0;
118
119
		if ( $increment ) {
120
			$mapsOnThisPage++;
121
		}
122
123
		return 'map_leaflet_' . $mapsOnThisPage;
124
	}
125
126
	/**
127
	 * @see MapsMappingService::getResourceModules
128
	 *
129
	 * @since 3.0
130
	 *
131
	 * @return array of string
132
	 */
133
	public function getResourceModules() {
134
		return array_merge(
135
			parent::getResourceModules(),
136
			[ 'ext.maps.leaflet' ]
137
		);
138
	}
139
140
	protected function getDependencies() {
0 ignored issues
show
getDependencies 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...
141
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';
142
		return [
143
			Html::linkedStyle( "$leafletPath/leaflet.css" ),
144
			Html::linkedScript( "$leafletPath/leaflet.js" ),
145
		];
146
	}
147
148
}
149