summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/MapsRegistration.php
blob: 68d0ea05beb9cc80777433e46f9c31785ac67f30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

use Maps\MapsSetup;

class MapsRegistration {

	public static function onRegistration( array $credits ) {
		if ( defined( 'Maps_VERSION' ) ) {
			// Do not initialize more than once.
			return true;
		}

		if ( !defined( 'Maps_SETTINGS_LOADED' ) ) {
			require_once __DIR__ . '/Maps_Settings.php';
		}

		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
			include_once( __DIR__ . '/vendor/autoload.php' );
		}

		define( 'Maps_VERSION', $credits['version'] );
		define( 'SM_VERSION', Maps_VERSION );

		if ( !(bool)'Defining PHP constants in JSON is a bad idea and breaks tools' ) {
			define( 'NS_GEO_JSON', 420 );
			define( 'NS_GEO_JSON_TALK', 421 );
		}

		$GLOBALS['wgExtensionFunctions'][] = function() {
			if ( $GLOBALS['egMapsDisableExtension'] ) {
				return true;
			}

			// Only initialize the extension when all dependencies are present.
			if ( !defined( 'Validator_VERSION' ) ) {
				throw new Exception( 'You need to have Validator installed in order to use Maps' );
			}

			if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) {
				throw new Exception(
					'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
					. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
				);
			}

			( new MapsSetup( $GLOBALS ) )->setup();

			return true;
		};

		return true;
	}

}