1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Maps\MapsSetup; |
4
|
|
|
|
5
|
|
|
class MapsRegistration { |
6
|
|
|
|
7
|
|
|
public static function onRegistration( array $credits ) { |
|
|
|
|
8
|
|
|
if ( defined( 'Maps_COORDS_FLOAT' ) ) { |
9
|
|
|
// Do not initialize more than once. |
10
|
|
|
return true; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
14
|
|
|
include_once( __DIR__ . '/vendor/autoload.php' ); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
define( 'Maps_VERSION', $credits['version'] ); |
18
|
|
|
define( 'SM_VERSION', Maps_VERSION ); |
19
|
|
|
|
20
|
|
|
// The different coordinate notations. |
21
|
|
|
define( 'Maps_COORDS_FLOAT', 'float' ); |
22
|
|
|
define( 'Maps_COORDS_DMS', 'dms' ); |
23
|
|
|
define( 'Maps_COORDS_DM', 'dm' ); |
24
|
|
|
define( 'Maps_COORDS_DD', 'dd' ); |
25
|
|
|
|
26
|
|
|
if ( !(bool)'Defining PHP constants in JSON is a bad idea and breaks tools' ) { |
27
|
|
|
define( 'NS_GEO_JSON', 420 ); |
28
|
|
|
define( 'NS_GEO_JSON_TALK', 421 ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
require_once __DIR__ . '/Maps_Settings.php'; |
32
|
|
|
|
33
|
|
|
// Internationalization |
34
|
|
|
$GLOBALS['wgMessagesDirs']['Maps.class'] = __DIR__ . '/i18n'; |
35
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php'; |
36
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php'; |
37
|
|
|
|
38
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
39
|
|
|
if ( $GLOBALS['egMapsDisableExtension'] ) { |
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// Only initialize the extension when all dependencies are present. |
44
|
|
|
if ( !defined( 'Validator_VERSION' ) ) { |
45
|
|
|
throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) { |
49
|
|
|
throw new Exception( |
50
|
|
|
'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.' |
51
|
|
|
. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
( new MapsSetup( $GLOBALS ) )->setup(); |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
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: