Completed
Push — master ( 8a9c18...741c63 )
by mw
04:13 queued 15s
created

SemanticInterlanguageLinks.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 14.

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.

Loading history...
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 ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) {
18
	die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">SemanticInterlanguageLinks</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' );
19
}
20
21
if ( defined( 'SIL_VERSION' ) ) {
22
	// Do not initialize more than once.
23
	return 1;
24
}
25
26
SemanticInterlanguageLinks::initExtension();
27
28
$GLOBALS['wgExtensionFunctions'][] = function() {
29
	SemanticInterlanguageLinks::onExtensionFunction();
30
};
31
32
/**
33
 * @codeCoverageIgnore
34
 */
35
class SemanticInterlanguageLinks {
36
37
	/**
38
	 * @since 1.3
39
	 */
40
	public static function initExtension() {
41
42
		// Load DefaultSettings
43
		require_once __DIR__ . '/DefaultSettings.php';
44
45
		define( 'SIL_VERSION', '1.3.0' );
46
47
		// Register extension info
48
		$GLOBALS[ 'wgExtensionCredits' ][ 'semantic' ][ ] = array(
49
			'path'           => __FILE__,
50
			'name'           => 'Semantic Interlanguage Links',
51
			'author'         => array( 'James Hong Kong' ),
52
			'url'            => 'https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/',
53
			'descriptionmsg' => 'sil-desc',
54
			'version'        => SIL_VERSION,
55
			'license-name'   => 'GPL-2.0+',
56
		);
57
58
		// Register message files
59
		$GLOBALS['wgMessagesDirs']['SemanticInterlanguageLinks'] = __DIR__ . '/i18n';
60
		$GLOBALS['wgExtensionMessagesFiles']['SemanticInterlanguageLinksMagic'] = __DIR__ . '/i18n/SemanticInterlanguageLinks.magic.php';
61
	}
62
63
	/**
64
	 * @since 1.3
65
	 */
66
	public static function onExtensionFunction() {
67
68
		$cacheFactory = new CacheFactory();
69
70
		$compositeCache = $cacheFactory->newCompositeCache( array(
71
			$cacheFactory->newFixedInMemoryLruCache( 500 ),
72
			$cacheFactory->newMediaWikiCache( ObjectCache::getInstance( $GLOBALS['egSILCacheType'] ) )
73
		) );
74
75
		$cacheKeyProvider = new CacheKeyProvider(
76
			$GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix']
77
		);
78
79
		$hookRegistry = new HookRegistry(
80
			ApplicationFactory::getInstance()->getStore(),
81
			$compositeCache,
82
			$cacheKeyProvider
83
		);
84
85
		$hookRegistry->register();
86
	}
87
88
	/**
89
	 * @since 1.3
90
	 *
91
	 * @return string|null
92
	 */
93
	public static function getVersion() {
94
		return SIL_VERSION;
95
	}
96
97
}
98