Completed
Pull Request — master (#21)
by
unknown
02:48
created

SemanticScribunto.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
if ( !defined( 'MEDIAWIKI' ) ) {
11
	die( 'This file is part of the Semantic Scribunto extension, it is not a valid entry point.' );
12
}
13
14
if ( defined( 'SMW_SCRIBUNTO_VERSION' ) ) {
15
	// Do not initialize more than once.
16
	return 1;
17
}
18
19
SemanticScribunto::initExtension();
20
21
$GLOBALS['wgExtensionFunctions'][] = function() {
22
	SemanticScribunto::onExtensionFunction();
23
};
24
25
/**
26
 * @codeCoverageIgnore
27
 */
28
class SemanticScribunto {
29
30
	/**
31
	 * @since 1.0
32
	 */
33
	public static function initExtension() {
34
35
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
36
			include_once __DIR__ . '/vendor/autoload.php';
37
		}
38
39
		define( 'SMW_SCRIBUNTO_VERSION', '1.0.0-alpha' );
40
41
		// Register extension info
42
		$GLOBALS['wgExtensionCredits']['semantic'][] = array(
43
			'path'           => __FILE__,
44
			'name'           => 'Semantic Scribunto',
45
			'author'         => array( 'James Hong Kong' ),
46
			'url'            => 'https://github.com/SemanticMediaWiki/SemanticScribunto/',
47
			'descriptionmsg' => 'smw-scribunto-desc',
48
			'version'        => SMW_SCRIBUNTO_VERSION,
49
			'license-name'   => 'GPL-2.0+',
50
		);
51
52
		// MW 1.26+
53
		if ( !function_exists( 'wfGlobalCacheKey' ) ) {
54
			function wfGlobalCacheKey( /*...*/ ) {
55
				$args = func_get_args();
56
				$key = 'global:' . implode( ':', $args );
57
				return strtr( $key, ' ', '_' );
58
			}
59
		}
60
61
		// Register message files
62
		$GLOBALS['wgMessagesDirs']['SemanticScribunto'] = __DIR__ . '/i18n';
63
	}
64
65
	/**
66
	 * @since 1.0
67
	 */
68
	public static function checkRequirements() {
69
70
		if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.26', 'lt' ) ) {
71
			die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> is only compatible with MediaWiki 1.26 or above. You need to upgrade MediaWiki first.' );
72
		}
73
74
		// Using the constant as indicator to avoid class_exists
75
		if ( !defined( 'CONTENT_MODEL_SCRIBUNTO' ) ) {
76
			die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> requires the Scribunto extension, please enable or install <a href="https://www.mediawiki.org/wiki/Extension:Scribunto">Scribunto</a> first.' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkRequirements() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
77
		}
78
79
		if ( !defined( 'SMW_VERSION' ) ) {
80
			die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> requires the Semantic MediaWiki extension, please enable or install <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> first.' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkRequirements() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
81
		}
82
	}
83
84
	/**
85
	 * @since 1.0
86
	 */
87
	public static function onExtensionFunction() {
88
		self::checkRequirements();
89
90
		$hookRegistry = new HookRegistry();
91
		$hookRegistry->register();
92
	}
93
94
	/**
95
	 * @since 1.0
96
	 *
97
	 * @return string|null
98
	 */
99
	public static function getVersion() {
100
		return SMW_SCRIBUNTO_VERSION;
101
	}
102
103
}
104