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( |
||
46 | 'James Hong Kong', |
||
47 | '[https://www.semantic-mediawiki.org/wiki/User:Oetterer Tobias Oetterer]', |
||
48 | ), |
||
49 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticScribunto/', |
||
50 | 'descriptionmsg' => 'smw-scribunto-desc', |
||
51 | 'version' => SMW_SCRIBUNTO_VERSION, |
||
52 | 'license-name' => 'GPL-2.0+', |
||
53 | ); |
||
54 | |||
55 | // MW 1.26+ |
||
56 | if ( !function_exists( 'wfGlobalCacheKey' ) ) { |
||
57 | function wfGlobalCacheKey( /*...*/ ) { |
||
58 | $args = func_get_args(); |
||
59 | $key = 'global:' . implode( ':', $args ); |
||
60 | return strtr( $key, ' ', '_' ); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | // Register message files |
||
65 | $GLOBALS['wgMessagesDirs']['SemanticScribunto'] = __DIR__ . '/i18n'; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @since 1.0 |
||
70 | */ |
||
71 | public static function checkRequirements() { |
||
72 | |||
73 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.26', 'lt' ) ) { |
||
74 | 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.' ); |
||
75 | } |
||
76 | |||
77 | // Using the constant as indicator to avoid class_exists |
||
78 | if ( !defined( 'CONTENT_MODEL_SCRIBUNTO' ) ) { |
||
79 | 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.' ); |
||
0 ignored issues
–
show
|
|||
80 | } |
||
81 | |||
82 | if ( !defined( 'SMW_VERSION' ) ) { |
||
83 | 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.' ); |
||
0 ignored issues
–
show
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 ![]() |
|||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @since 1.0 |
||
89 | */ |
||
90 | public static function onExtensionFunction() { |
||
91 | |||
92 | // Check requirements after LocalSetting.php has been processed |
||
93 | self::checkRequirements(); |
||
94 | |||
95 | $hookRegistry = new HookRegistry(); |
||
96 | $hookRegistry->register(); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @since 1.0 |
||
101 | * |
||
102 | * @return string|null |
||
103 | */ |
||
104 | public static function getVersion() { |
||
105 | return SMW_SCRIBUNTO_VERSION; |
||
106 | } |
||
107 | |||
108 | } |
||
109 |
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.