1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SMW\Notifications\HookRegistry; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticNotifications/ |
7
|
|
|
* |
8
|
|
|
* @defgroup SemanticNotifications Semantic Notifications |
9
|
|
|
*/ |
10
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
11
|
|
|
die( 'This file is part of the Semantic Notifications extension, it is not a valid entry point.' ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if ( defined( 'SMW_NOTIFICATIONS_VERSION' ) ) { |
15
|
|
|
// Do not initialize more than once. |
16
|
|
|
return 1; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
SemanticNotifications::load(); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @codeCoverageIgnore |
23
|
|
|
*/ |
24
|
|
|
class SemanticNotifications { |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @since 1.0 |
28
|
|
|
* |
29
|
|
|
* @note It is expected that this function is loaded before LocalSettings.php |
30
|
|
|
* to ensure that settings and global functions are available by the time |
31
|
|
|
* the extension is activated. |
32
|
|
|
*/ |
33
|
|
|
public static function load() { |
|
|
|
|
34
|
|
|
|
35
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
36
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$GLOBALS['snogChangeNotificationDetectionPropertyExemptionList'] = array( |
40
|
|
|
'_MDAT', |
41
|
|
|
'_REDI' |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
// In case extension.json is being used, the the succeeding steps are |
45
|
|
|
// expected to be handled by the ExtensionRegistry |
46
|
|
|
self::initExtension(); |
47
|
|
|
|
48
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
49
|
|
|
self::onExtensionFunction(); |
50
|
|
|
}; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @since 1.0 |
55
|
|
|
*/ |
56
|
|
|
public static function initExtension() { |
|
|
|
|
57
|
|
|
|
58
|
|
|
define( 'SMW_NOTIFICATIONS_VERSION', '1.0.0-alpha' ); |
59
|
|
|
|
60
|
|
|
// Register extension info |
61
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][] = array( |
62
|
|
|
'path' => __FILE__, |
63
|
|
|
'name' => 'Semantic Notifications', |
64
|
|
|
'author' => array( 'James Hong Kong' ), |
65
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticNotifications/', |
66
|
|
|
'descriptionmsg' => 'smw-notifications-desc', |
67
|
|
|
'version' => SMW_NOTIFICATIONS_VERSION, |
68
|
|
|
'license-name' => 'GPL-2.0+', |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// Register message files |
72
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticNotifications'] = __DIR__ . '/i18n'; |
73
|
|
|
|
74
|
|
|
self::onBeforeCreateEchoEvent(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Register the hook before the execution of ExtensionFunction |
79
|
|
|
* |
80
|
|
|
* @since 1.0 |
81
|
|
|
*/ |
82
|
|
|
public static function onBeforeCreateEchoEvent() { |
|
|
|
|
83
|
|
|
$GLOBALS['wgHooks']['BeforeCreateEchoEvent'][] = "\SMW\Notifications\EchoNotificationsManager::initNotificationsDefinitions"; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @since 1.0 |
88
|
|
|
*/ |
89
|
|
|
public static function doCheckRequirements() { |
|
|
|
|
90
|
|
|
|
91
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { |
92
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// There is no good way to detect whether Echo is available or not without |
96
|
|
|
// making a class_exists, what should I say ... |
97
|
|
|
if ( !isset( $GLOBALS['wgMessagesDirs']['Echo'] ) ) { |
98
|
|
|
die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> requires the Echo extension, please enable or install <a href="https://www.mediawiki.org/wiki/Extension:Echo">Echo(Notifications)</a> first.' ); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
102
|
|
|
die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> requires the Semantic MediaWiki extension, please enable or install <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> first.' ); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @since 1.0 |
108
|
|
|
*/ |
109
|
|
|
public static function onExtensionFunction() { |
110
|
|
|
|
111
|
|
|
// Check requirements after LocalSetting.php has been processed |
112
|
|
|
self::doCheckRequirements(); |
113
|
|
|
|
114
|
|
|
$hookRegistry = new HookRegistry(); |
115
|
|
|
$hookRegistry->register(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @since 1.0 |
120
|
|
|
* |
121
|
|
|
* @return string|null |
122
|
|
|
*/ |
123
|
|
|
public static function getVersion() { |
124
|
|
|
return SMW_NOTIFICATIONS_VERSION; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
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.