Completed
Push — issue138 ( ec6bb3 )
by
unknown
04:30
created

Leaflet.php ➔ efMapsInitLeaflet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 57 and the first side effect is on line 18.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * This groupe contains all Leaflet related files of the Maps extension.
5
 *
6
 * @defgroup Leaflet
7
 */
8
9
/**
10
 * This file holds the hook and initialization for the Leaflet service.
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Pavel Astakhov < [email protected] >
14
 */
15
16
// Check to see if we are being called as an extension or directly
17
if ( !defined( 'MEDIAWIKI' ) ) {
18
	die( 'This file is an extension to MediaWiki and thus not a valid entry point.' );
19
}
20
21
call_user_func( function() {
22
	global $wgHooks, $wgResourceModules;
23
24
	// Specify the function that will initialize the parser function.
25
	$wgHooks['MappingServiceLoad'][] = 'efMapsInitLeaflet';
26
27
	$pathParts = ( explode( DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR, __DIR__, 2 ) );
28
29
	$wgResourceModules['ext.maps.leaflet'] = [
30
		'dependencies' => [ 'ext.maps.common' ],
31
		'localBasePath' => __DIR__,
32
		'remoteExtPath' => end( $pathParts ),
33
		'group' => 'ext.maps',
34
		'targets' => [
35
			'mobile',
36
			'desktop'
37
		],
38
		'scripts' => [
39
			'jquery.leaflet.js',
40
			'ext.maps.leaflet.js',
41
		],
42
		'messages' => [
43
			'maps-markers',
44
			'maps-copycoords-prompt',
45
			'maps-searchmarkers-text',
46
		],
47
	];
48
} );
49
50
/**
51
 * Initialization function for the Leaflet service.
52
 *
53
 * @ingroup Leaflet
54
 *
55
 * @return boolean true
56
 */
57
function efMapsInitLeaflet() {
58
	global $wgAutoloadClasses;
59
60
	$wgAutoloadClasses['MapsLeaflet'] = __DIR__ . '/Maps_Leaflet.php';
61
62
	MapsMappingServices::registerService( 'leaflet', 'MapsLeaflet' );
63
	$leafletMaps = MapsMappingServices::getServiceInstance( 'leaflet' );
64
	$leafletMaps->addFeature( 'display_map', 'MapsDisplayMapRenderer' );
65
66
	return true;
67
}
68