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 Semantic Interlanguage Links 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
|
|
|
/** |
46
|
|
|
* In case extension.json is being used, the succeeding steps are |
47
|
|
|
* expected to be handled by the ExtensionRegistry aka extension.json |
48
|
|
|
* ... |
49
|
|
|
* |
50
|
|
|
* "callback": "SemanticInterlanguageLinks::initExtension", |
51
|
|
|
* "ExtensionFunctions": [ |
52
|
|
|
* "SemanticInterlanguageLinks::onExtensionFunction" |
53
|
|
|
* ], |
54
|
|
|
*/ |
55
|
|
|
self::initExtension(); |
56
|
|
|
|
57
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
58
|
|
|
self::onExtensionFunction(); |
59
|
|
|
}; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @since 1.3 |
64
|
|
|
*/ |
65
|
|
|
public static function initExtension() { |
66
|
|
|
|
67
|
|
|
define( 'SIL_VERSION', '1.5.0-alpha' ); |
68
|
|
|
|
69
|
|
|
// Register extension info |
70
|
|
|
$GLOBALS[ 'wgExtensionCredits' ][ 'semantic' ][ ] = array( |
71
|
|
|
'path' => __FILE__, |
72
|
|
|
'name' => 'Semantic Interlanguage Links', |
73
|
|
|
'author' => array( 'James Hong Kong' ), |
74
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/', |
75
|
|
|
'descriptionmsg' => 'sil-desc', |
76
|
|
|
'version' => SIL_VERSION, |
77
|
|
|
'license-name' => 'GPL-2.0-or-later', |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
// Register message files |
81
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticInterlanguageLinks'] = __DIR__ . '/i18n'; |
82
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticInterlanguageLinksMagic'] = __DIR__ . '/i18n/SemanticInterlanguageLinks.magic.php'; |
83
|
|
|
|
84
|
|
|
self::onBeforeExtensionFunction(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register hooks that require to be listed as soon as possible and preferable |
89
|
|
|
* before the execution of onExtensionFunction |
90
|
|
|
* |
91
|
|
|
* @since 1.4 |
92
|
|
|
*/ |
93
|
|
|
public static function onBeforeExtensionFunction() { |
94
|
|
|
$GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SIL\HookRegistry::onBeforeConfigCompletion'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @since 1.4 |
99
|
|
|
*/ |
100
|
|
|
public static function checkRequirements() { |
101
|
|
|
|
102
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { |
103
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">Semantic Interlanguage Links</a> is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
107
|
|
|
die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticInterlanguageLinks/">Semantic Interlanguage Links</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>. Please enable or install the extension first.' ); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @since 1.3 |
113
|
|
|
*/ |
114
|
|
|
public static function onExtensionFunction() { |
115
|
|
|
|
116
|
|
|
// Check requirements after LocalSetting.php has been processed |
117
|
|
|
self::checkRequirements(); |
118
|
|
|
|
119
|
|
|
// Legacy |
120
|
|
|
if ( isset( $GLOBALS['egSILEnabledCategoryFilterByLanguage'] ) ) { |
121
|
|
|
$GLOBALS['silgEnabledCategoryFilterByLanguage'] = $GLOBALS['egSILEnabledCategoryFilterByLanguage']; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ( isset( $GLOBALS['egSILCacheType'] ) ) { |
125
|
|
|
$GLOBALS['silgCacheType'] = $GLOBALS['egSILCacheType']; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$cacheFactory = new CacheFactory(); |
129
|
|
|
|
130
|
|
|
$compositeCache = $cacheFactory->newCompositeCache( array( |
131
|
|
|
$cacheFactory->newFixedInMemoryLruCache( 500 ), |
132
|
|
|
$cacheFactory->newMediaWikiCache( ObjectCache::getInstance( $GLOBALS['silgCacheType'] ) ) |
133
|
|
|
) ); |
134
|
|
|
|
135
|
|
|
$cacheKeyProvider = new CacheKeyProvider( |
136
|
|
|
$GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix'] |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$hookRegistry = new HookRegistry( |
140
|
|
|
ApplicationFactory::getInstance()->getStore(), |
141
|
|
|
$compositeCache, |
142
|
|
|
$cacheKeyProvider |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$hookRegistry->register(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @since 1.3 |
150
|
|
|
* |
151
|
|
|
* @return string|null |
152
|
|
|
*/ |
153
|
|
|
public static function getVersion() { |
154
|
|
|
return SIL_VERSION; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
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.