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::load(); |
||
20 | |||
21 | /** |
||
22 | * @codeCoverageIgnore |
||
23 | */ |
||
24 | class SemanticScribunto { |
||
25 | |||
26 | /** |
||
27 | * @since 1.0 |
||
28 | * |
||
29 | * @note It is expected that this function is loaded before LocalSettings.php |
||
30 | * to ensure that settings and global functions are available by the time |
||
31 | * the extension is activated. |
||
32 | */ |
||
33 | public static function load() { |
||
34 | |||
35 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
36 | include_once __DIR__ . '/vendor/autoload.php'; |
||
37 | } |
||
38 | |||
39 | // In case extension.json is being used, the the succeeding steps will |
||
40 | // be handled by the ExtensionRegistry |
||
41 | self::initExtension(); |
||
42 | |||
43 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
44 | self::onExtensionFunction(); |
||
45 | }; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @since 1.0 |
||
50 | */ |
||
51 | public static function initExtension() { |
||
52 | |||
53 | define( 'SMW_SCRIBUNTO_VERSION', '1.0.0' ); |
||
54 | |||
55 | // Register extension info |
||
56 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
57 | 'path' => __FILE__, |
||
58 | 'name' => 'Semantic Scribunto', |
||
59 | 'author' => array( |
||
60 | 'James Hong Kong', |
||
61 | '[https://www.semantic-mediawiki.org/wiki/User:Oetterer Tobias Oetterer]', |
||
62 | ), |
||
63 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticScribunto/', |
||
64 | 'descriptionmsg' => 'smw-scribunto-desc', |
||
65 | 'version' => SMW_SCRIBUNTO_VERSION, |
||
66 | 'license-name' => 'GPL-2.0+', |
||
67 | ); |
||
68 | |||
69 | // MW 1.26+ |
||
70 | if ( !function_exists( 'wfGlobalCacheKey' ) ) { |
||
71 | function wfGlobalCacheKey( /*...*/ ) { |
||
0 ignored issues
–
show
|
|||
72 | $args = func_get_args(); |
||
73 | $key = 'global:' . implode( ':', $args ); |
||
74 | return strtr( $key, ' ', '_' ); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // Register message files |
||
79 | $GLOBALS['wgMessagesDirs']['SemanticScribunto'] = __DIR__ . '/i18n'; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @since 1.0 |
||
84 | */ |
||
85 | public static function doCheckRequirements() { |
||
86 | |||
87 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.26', 'lt' ) ) { |
||
88 | 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.' ); |
||
89 | } |
||
90 | |||
91 | // Using the constant as indicator to avoid class_exists |
||
92 | if ( !defined( 'CONTENT_MODEL_SCRIBUNTO' ) ) { |
||
93 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> requires <a href="https://www.mediawiki.org/wiki/Extension:Scribunto">Scribunto</a>, please enable or install the extension first.' ); |
||
94 | } |
||
95 | |||
96 | if ( !defined( 'SMW_VERSION' ) ) { |
||
97 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticScribunto/">Semantic Scribunto</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>, please enable or install the extension first.' ); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @since 1.0 |
||
103 | */ |
||
104 | public static function onExtensionFunction() { |
||
105 | |||
106 | // Check requirements after LocalSetting.php has been processed |
||
107 | self::doCheckRequirements(); |
||
108 | |||
109 | $hookRegistry = new HookRegistry(); |
||
110 | $hookRegistry->register(); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @since 1.0 |
||
115 | * |
||
116 | * @param string|null $dependency |
||
117 | * |
||
118 | * @return string|null |
||
119 | */ |
||
120 | public static function getVersion( $dependency = null ) { |
||
121 | |||
122 | if ( $dependency === null && defined( 'SMW_SCRIBUNTO_VERSION' ) ) { |
||
123 | return SMW_SCRIBUNTO_VERSION; |
||
124 | } |
||
125 | |||
126 | if ( $dependency === 'SMW' && defined( 'SMW_VERSION' ) ) { |
||
127 | return SMW_VERSION; |
||
128 | } |
||
129 | |||
130 | if ( $dependency === 'Lua' && method_exists( 'Scribunto_LuaStandaloneInterpreter', 'getLuaVersion' ) ) { |
||
131 | return Scribunto_LuaStandaloneInterpreter::getLuaVersion( array( 'luaPath' => null ) ); |
||
132 | } |
||
133 | |||
134 | return null; |
||
135 | } |
||
136 | |||
137 | } |
||
138 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.