Completed
Push — master ( bb5b4a...05c2eb )
by Jeroen De
07:43
created

SemanticMaps   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 96
rs 10
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initExtension() 0 58 1
A onExtensionFunction() 0 18 1
A getVersion() 0 3 1
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 43 and the first side effect is on line 11.

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
 * Initialization file for the Semantic Maps extension.
5
 *
6
 * @licence GNU GPL v2+
7
 * @author Jeroen De Dauw < [email protected] >
8
 */
9
10
if ( !defined( 'MEDIAWIKI' ) ) {
11
	die( 'Not an entry point.' );
12
}
13
14
if ( defined( 'SM_VERSION' ) ) {
15
	// Do not initialize more than once.
16
	return 1;
17
}
18
19
if ( version_compare( $GLOBALS['wgVersion'], '1.23c', '<' ) ) {
20
	throw new Exception(
21
		'This version of Semantic Maps requires MediaWiki 1.23 or above; use Semantic Maps 3.3.x for older versions.'
22
		. ' See https://github.com/SemanticMediaWiki/SemanticMaps/blob/master/INSTALL.md for more info.'
23
	);
24
}
25
26
if ( !defined( 'Maps_VERSION' ) && is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
27
	include_once( __DIR__ . '/vendor/autoload.php' );
28
}
29
30
if ( !defined( 'Maps_VERSION' ) ) {
31
	throw new Exception( 'You need to have Maps installed in order to use Semantic Maps' );
32
}
33
34
SemanticMaps::initExtension();
35
36
$GLOBALS['wgExtensionFunctions'][] = function() {
37
	SemanticMaps::onExtensionFunction();
38
};
39
40
/**
41
 * @codeCoverageIgnore
42
 */
43
class SemanticMaps {
44
45
	/**
46
	 * @since 3.4
47
	 */
48
	public static function initExtension() {
0 ignored issues
show
Coding Style introduced by
initExtension 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...
49
50
		// Load DefaultSettings
51
		require_once __DIR__ . '/DefaultSettings.php';
52
53
		define( 'SM_VERSION', '3.4.0-alpha' );
54
55
		$GLOBALS['wgExtensionCredits']['semantic'][] = [
56
			'path' => __FILE__,
57
			'name' => 'Semantic Maps',
58
			'version' => SM_VERSION,
59
			'author' => [
60
				'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]'
61
			],
62
			'url' => 'https://github.com/SemanticMediaWiki/SemanticMaps/blob/master/README.md#semantic-maps',
63
			'descriptionmsg' => 'semanticmaps-desc',
64
			'license-name'   => 'GPL-2.0+'
65
		];
66
67
		include_once __DIR__ . '/src/queryprinters/SM_QueryPrinters.php';
68
69
		$moduleTemplate = [
70
				'position' => 'bottom',
71
				'localBasePath' => __DIR__ . '/src',
72
				'remoteExtPath' => 'SemanticMaps/src',
73
				'group' => 'ext.semanticmaps',
74
		];
75
76
		$GLOBALS['wgResourceModules']['ext.sm.forminputs'] = $moduleTemplate + [
77
			'dependencies' => [ 'ext.maps.coord' ],
78
			'localBasePath' => __DIR__ . '/src/forminputs',
79
			'remoteExtPath' => 'SemanticMaps/src/forminputs',
80
			'scripts' => [
81
				'jquery.mapforminput.js'
82
			],
83
			'messages' => [
84
				'semanticmaps_enteraddresshere',
85
				'semanticmaps-updatemap',
86
				'semanticmaps_lookupcoordinates',
87
				'semanticmaps-forminput-remove',
88
				'semanticmaps-forminput-add',
89
				'semanticmaps-forminput-locations'
90
			]
91
		];
92
93
		$GLOBALS['wgResourceModules']['ext.sm.common'] = $moduleTemplate + [
94
			'scripts' => [
95
				'ext.sm.common.js'
96
			]
97
		];
98
99
		include_once __DIR__ . '/src/services/GoogleMaps3/SM_GoogleMaps3.php';
100
		include_once __DIR__ . '/src/services/Leaflet/SM_Leaflet.php';
101
		include_once __DIR__ . '/src/services/OpenLayers/SM_OpenLaysers.php';
102
103
		// Internationalization
104
		$GLOBALS['wgMessagesDirs']['SemanticMaps'] = __DIR__ . '/i18n';
105
	}
106
107
	/**
108
	 * @since 3.4
109
	 */
110
	public static function onExtensionFunction() {
0 ignored issues
show
Coding Style introduced by
onExtensionFunction 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...
111
112
		$GLOBALS['wgHooks']['MappingServiceLoad'][] = function() {
113
			MapsMappingServices::registerServiceFeature( 'openlayers', 'qp', 'SMMapPrinter' );
114
			return true;
115
		};
116
117
		// Hook for initializing the Geographical Data types.
118
		$GLOBALS['wgHooks']['SMW::DataType::initTypes'][] = 'SemanticMapsHooks::initGeoDataTypes';
119
120
		// Hook for defining the default query printer for queries that ask for geographical coordinates.
121
		$GLOBALS['wgHooks']['SMWResultFormat'][] = 'SemanticMapsHooks::addGeoCoordsDefaultFormat';
122
123
		// Hook for adding a Semantic Maps links to the Admin Links extension.
124
		$GLOBALS['wgHooks']['AdminLinks'][] = 'SemanticMapsHooks::addToAdminLinks';
125
126
		$GLOBALS['wgHooks']['sfFormPrinterSetup'][] = 'SemanticMaps\FormInputsSetup::run';
127
	}
128
129
	/**
130
	 * @since 3.4
131
	 *
132
	 * @return string|null
133
	 */
134
	public static function getVersion() {
135
		return SM_VERSION;
136
	}
137
138
}
139