Completed
Push — master ( f47ce4...c9683e )
by mw
04:41
created

SemanticInterlanguageLinks::onExtensionFunction()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 8.3786
c 0
b 0
f 0
cc 7
nc 6
nop 0
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
SemanticInterlanguageLinks::load();
14
15
/**
16
 * @codeCoverageIgnore
17
 */
18
class SemanticInterlanguageLinks {
19
20
	/**
21
	 * @since 1.4
22
	 *
23
	 * @note It is expected that this function is loaded before LocalSettings.php
24
	 * to ensure that settings and global functions are available by the time
25
	 * the extension is activated.
26
	 */
27
	public static function load() {
28
29
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
30
			include_once __DIR__ . '/vendor/autoload.php';
31
		}
32
33
		// Load DefaultSettings
34
		require_once __DIR__ . '/DefaultSettings.php';
35
	}
36
37
	/**
38
	 * @since 1.3
39
	 */
40
	public static function initExtension( $credits = [] ) {
41
42
		// See https://phabricator.wikimedia.org/T151136
43
		define( 'SIL_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
44
45
		// Register message files
46
		$GLOBALS['wgMessagesDirs']['SemanticInterlanguageLinks'] = __DIR__ . '/i18n';
47
		$GLOBALS['wgExtensionMessagesFiles']['SemanticInterlanguageLinksMagic'] = __DIR__ . '/i18n/SemanticInterlanguageLinks.magic.php';
48
49
		$GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SIL\HookRegistry::onBeforeConfigCompletion';
50
	}
51
52
	/**
53
	 * @since 1.3
54
	 */
55
	public static function onExtensionFunction() {
56
57
		if ( !defined( 'SMW_VERSION' ) ) {
58
			if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
59
				die( "\nThe 'Semantic Interlanguage Links' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
60
			} else {
61
				die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">Semantic Interlanguage Links</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
62
			}
63
		}
64
65
		// Legacy
66
		if ( isset( $GLOBALS['egSILEnabledCategoryFilterByLanguage'] ) ) {
67
			$GLOBALS['silgEnabledCategoryFilterByLanguage'] = $GLOBALS['egSILEnabledCategoryFilterByLanguage'];
68
		}
69
70
		if ( isset( $GLOBALS['egSILCacheType'] ) ) {
71
			$GLOBALS['silgCacheType'] = $GLOBALS['egSILCacheType'];
72
		}
73
74
		$cacheFactory = new CacheFactory();
75
76
		$compositeCache = $cacheFactory->newCompositeCache( [
77
			$cacheFactory->newFixedInMemoryLruCache( 500 ),
78
			$cacheFactory->newMediaWikiCache( ObjectCache::getInstance( $GLOBALS['silgCacheType'] ) )
79
		] );
80
81
		$cacheKeyProvider = new CacheKeyProvider(
82
			$GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix']
83
		);
84
85
		$hookRegistry = new HookRegistry(
86
			ApplicationFactory::getInstance()->getStore(),
87
			$compositeCache,
88
			$cacheKeyProvider
89
		);
90
91
		$hookRegistry->register();
92
	}
93
94
	/**
95
	 * @since 1.3
96
	 *
97
	 * @return string|null
98
	 */
99
	public static function getVersion() {
100
		return SIL_VERSION;
101
	}
102
103
}
104