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.' ); |
|
|
|
|
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.' ); |
|
|
|
|
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
|
|
|
|
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.