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 SIL\HookRegistry; |
||
4 | use SIL\CacheKeyProvider; |
||
5 | use SMW\ApplicationFactory; |
||
6 | use Onoi\Cache\CacheFactory; |
||
7 | |||
8 | /** |
||
9 | * @see https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/ |
||
10 | * |
||
11 | * @defgroup SIL Semantic Interlanguage Links |
||
12 | */ |
||
13 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
14 | die( 'This file is part of the SemanticInterlanguageLinks extension, it is not a valid entry point.' ); |
||
15 | } |
||
16 | |||
17 | if ( defined( 'SIL_VERSION' ) ) { |
||
18 | // Do not initialize more than once. |
||
19 | return 1; |
||
20 | } |
||
21 | |||
22 | SemanticInterlanguageLinks::load(); |
||
23 | |||
24 | /** |
||
25 | * @codeCoverageIgnore |
||
26 | */ |
||
27 | class SemanticInterlanguageLinks { |
||
28 | |||
29 | /** |
||
30 | * @since 1.4 |
||
31 | * |
||
32 | * @note It is expected that this function is loaded before LocalSettings.php |
||
33 | * to ensure that settings and global functions are available by the time |
||
34 | * the extension is activated. |
||
35 | */ |
||
36 | public static function load() { |
||
37 | |||
38 | // Load DefaultSettings |
||
39 | require_once __DIR__ . '/DefaultSettings.php'; |
||
40 | |||
41 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
42 | include_once __DIR__ . '/vendor/autoload.php'; |
||
43 | } |
||
44 | |||
45 | // In case extension.json is being used, the the succeeding steps will |
||
46 | // be handled by the ExtensionRegistry |
||
47 | self::initExtension(); |
||
48 | |||
49 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
50 | self::onExtensionFunction(); |
||
51 | }; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @since 1.3 |
||
56 | */ |
||
57 | public static function initExtension() { |
||
58 | |||
59 | define( 'SIL_VERSION', '1.4.0-alpha' ); |
||
60 | |||
61 | // Register extension info |
||
62 | $GLOBALS[ 'wgExtensionCredits' ][ 'semantic' ][ ] = array( |
||
63 | 'path' => __FILE__, |
||
64 | 'name' => 'Semantic Interlanguage Links', |
||
65 | 'author' => array( 'James Hong Kong' ), |
||
66 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/', |
||
67 | 'descriptionmsg' => 'sil-desc', |
||
68 | 'version' => SIL_VERSION, |
||
69 | 'license-name' => 'GPL-2.0+', |
||
70 | ); |
||
71 | |||
72 | // Register message files |
||
73 | $GLOBALS['wgMessagesDirs']['SemanticInterlanguageLinks'] = __DIR__ . '/i18n'; |
||
74 | $GLOBALS['wgExtensionMessagesFiles']['SemanticInterlanguageLinksMagic'] = __DIR__ . '/i18n/SemanticInterlanguageLinks.magic.php'; |
||
75 | |||
76 | self::onBeforeExtensionFunction(); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Register hooks that require to be listed as soon as possible and preferable |
||
81 | * before the execution of onExtensionFunction |
||
82 | * |
||
83 | * @since 1.4 |
||
84 | */ |
||
85 | public static function onBeforeExtensionFunction() { |
||
86 | $GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SIL\HookRegistry::onBeforeConfigCompletion'; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @since 1.4 |
||
91 | */ |
||
92 | public static function doCheckRequirements() { |
||
93 | |||
94 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
||
95 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">Semantic InterlanguageLinks</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
||
0 ignored issues
–
show
|
|||
96 | } |
||
97 | |||
98 | if ( !defined( 'SMW_VERSION' ) ) { |
||
99 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">Semantic InterlanguageLinks</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
doCheckRequirements() 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
Loading history...
|
|||
100 | } |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @since 1.3 |
||
105 | */ |
||
106 | public static function onExtensionFunction() { |
||
107 | |||
108 | // Check requirements after LocalSetting.php has been processed |
||
109 | self::doCheckRequirements(); |
||
110 | |||
111 | $cacheFactory = new CacheFactory(); |
||
112 | |||
113 | $compositeCache = $cacheFactory->newCompositeCache( array( |
||
114 | $cacheFactory->newFixedInMemoryLruCache( 500 ), |
||
115 | $cacheFactory->newMediaWikiCache( ObjectCache::getInstance( $GLOBALS['egSILCacheType'] ) ) |
||
116 | ) ); |
||
117 | |||
118 | $cacheKeyProvider = new CacheKeyProvider( |
||
119 | $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix'] |
||
120 | ); |
||
121 | |||
122 | $hookRegistry = new HookRegistry( |
||
123 | ApplicationFactory::getInstance()->getStore(), |
||
124 | $compositeCache, |
||
125 | $cacheKeyProvider |
||
126 | ); |
||
127 | |||
128 | $hookRegistry->register(); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @since 1.3 |
||
133 | * |
||
134 | * @return string|null |
||
135 | */ |
||
136 | public static function getVersion() { |
||
137 | return SIL_VERSION; |
||
138 | } |
||
139 | |||
140 | } |
||
141 |
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.