SemanticScribunto   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 0
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 6 2
A initExtension() 0 8 2
B onExtensionFunction() 0 30 7
1
<?php
2
3
use SMW\Scribunto\HookRegistry;
4
5
/**
6
 * @see https://github.com/SemanticMediaWiki/SemanticScribunto/
7
 *
8
 * @defgroup SemanticScribunto Semantic Scribunto
9
 */
10
SemanticScribunto::load();
11
12
/**
13
 * @codeCoverageIgnore
14
 */
15
class SemanticScribunto {
16
17
	/**
18
	 * @since 1.0
19
	 *
20
	 * @note It is expected that this function is loaded before LocalSettings.php
21
	 * to ensure that settings and global functions are available by the time
22
	 * the extension is activated.
23
	 */
24
	public static function load() {
25
26
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
27
			include_once __DIR__ . '/vendor/autoload.php';
28
		}
29
	}
30
31
	/**
32
	 * @since 1.0
33
	 */
34
	public static function initExtension( $credits = [] ) {
35
36
		// See https://phabricator.wikimedia.org/T151136
37
		define( 'SMW_SCRIBUNTO_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
38
39
		// Register message files
40
		$GLOBALS['wgMessagesDirs']['SemanticScribunto'] = __DIR__ . '/i18n';
41
	}
42
43
	/**
44
	 * @since 1.0
45
	 */
46
	public static function onExtensionFunction() {
47
48
		if ( !defined( 'SMW_VERSION' ) ) {
49
			if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
50
				die( "\nThe 'Semantic Scribunto' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
51
			} else {
52
				die(
53
					'<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> ' .
54
					'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> '.
55
					'to be installed and enabled.<br />'
56
				);
57
			}
58
		}
59
60
		// Using the constant as indicator to avoid class_exists
61
		if ( !defined( 'CONTENT_MODEL_SCRIBUNTO' ) ) {
62
			if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
63
				die( "\nThe 'Semantic Scribunto' extension requires the 'Scribunto' extension to be installed and enabled.\n" );
64
			} else {
65
				die(
66
					'<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> ' .
67
					'requires <a href="https://www.mediawiki.org/wiki/Extension:Scribunto">Scribunto</a>. Please install and ' .
68
					'enable the extension first.<br />'
69
				);
70
			}
71
		}
72
73
		$hookRegistry = new HookRegistry();
74
		$hookRegistry->register();
75
	}
76
77
}
78