1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Notifications; |
4
|
|
|
|
5
|
|
|
use SMW\Notifications\EchoPresentationModel; |
6
|
|
|
use SMW\Notifications\EchoFormatter; |
7
|
|
|
use SMW\Notifications\ChangeNotification\ChangeNotificationFilter; |
8
|
|
|
use SMW\Notifications\DataValues\NotificationGroupValue; |
9
|
|
|
use SMWDataItem as DataItem; |
10
|
|
|
use Hooks; |
11
|
|
|
use EchoEvent; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 1.0 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class HookRegistry { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $handlers = array(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @since 1.0 |
28
|
|
|
* |
29
|
|
|
* @param array $options |
|
|
|
|
30
|
|
|
*/ |
31
|
1 |
|
public function __construct() { |
32
|
1 |
|
$this->addCallbackHandlers(); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @since 1.0 |
37
|
|
|
*/ |
38
|
1 |
|
public function register() { |
39
|
1 |
|
foreach ( $this->handlers as $name => $callback ) { |
40
|
1 |
|
Hooks::register( $name, $callback ); |
41
|
|
|
} |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @since 1.0 |
46
|
|
|
* |
47
|
|
|
* @param string $name |
48
|
|
|
* |
49
|
|
|
* @return boolean |
50
|
|
|
*/ |
51
|
1 |
|
public function isRegistered( $name ) { |
52
|
1 |
|
return Hooks::isRegistered( $name ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @since 1.0 |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* |
60
|
|
|
* @return Callable|false |
61
|
|
|
*/ |
62
|
1 |
|
public function getHandlerFor( $name ) { |
63
|
1 |
|
return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
private function addCallbackHandlers() { |
|
|
|
|
67
|
|
|
|
68
|
1 |
|
$echoNotificationsManager = new EchoNotificationsManager(); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks.md |
72
|
|
|
*/ |
73
|
1 |
|
$this->handlers['SMW::Property::initProperties'] = function ( $baseRegistry ) { |
74
|
|
|
|
75
|
1 |
|
$propertyRegistry = new PropertyRegistry(); |
76
|
|
|
|
77
|
1 |
|
$propertyRegistry->registerTo( |
78
|
1 |
|
$baseRegistry |
79
|
|
|
); |
80
|
|
|
|
81
|
1 |
|
return true; |
82
|
|
|
}; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMW::DataType::initTypes |
86
|
|
|
*/ |
87
|
1 |
|
$this->handlers['SMW::DataType::initTypes'] = function ( $dataTypeRegistry ) { |
88
|
|
|
|
89
|
1 |
|
$dataTypeRegistry->registerDatatype( |
90
|
1 |
|
NotificationGroupValue::TYPE_ID, |
91
|
1 |
|
'\SMW\Notifications\DataValues\NotificationGroupValue', |
92
|
1 |
|
DataItem::TYPE_BLOB |
93
|
|
|
); |
94
|
|
|
|
95
|
1 |
|
return true; |
96
|
|
|
}; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide |
100
|
|
|
* @see https://www.mediawiki.org/wiki/Extension:Echo/BeforeCreateEchoEvent |
101
|
|
|
* |
102
|
|
|
* @param array &$notifications |
103
|
|
|
* @param array &$notificationCategories |
104
|
|
|
* @param array &$icons |
105
|
|
|
*/ |
106
|
1 |
|
$this->handlers['BeforeCreateEchoEvent'] = function( array &$notifications, array &$notificationCategories, array &$icons ) use ( $echoNotificationsManager ) { |
107
|
|
|
|
108
|
1 |
|
$echoNotificationsManager->initNotificationsDefinitions( |
109
|
1 |
|
$notifications, |
110
|
1 |
|
$notificationCategories, |
111
|
1 |
|
$icons |
112
|
|
|
); |
113
|
|
|
|
114
|
1 |
|
return true; |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGetDefaultOptions |
119
|
|
|
* |
120
|
|
|
* @param array[] &$defaultOptions |
121
|
|
|
*/ |
122
|
1 |
|
$this->handlers['UserGetDefaultOptions'] = function( array &$defaultOptions ) use ( $echoNotificationsManager ) { |
123
|
1 |
|
$echoNotificationsManager->addDefaultOptions( $defaultOptions ); |
124
|
1 |
|
return true; |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide#Bundled_notifications |
129
|
|
|
* |
130
|
|
|
* @param EchoEvent $event |
131
|
|
|
* @param string &$bundleString |
132
|
|
|
*/ |
133
|
1 |
|
$this->handlers['EchoGetBundleRules'] = function( EchoEvent $event, &$bundleString ) use ( $echoNotificationsManager ) { |
134
|
1 |
|
$echoNotificationsManager->getNotificationsBundle( $event, $bundleString ); |
135
|
1 |
|
return true; |
136
|
|
|
}; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @see https://www.mediawiki.org/wiki/Notifications/Developer_guide#Bundled_notifications |
140
|
|
|
* |
141
|
|
|
* @param EchoEvent $event |
142
|
|
|
* @param array &$users |
143
|
|
|
*/ |
144
|
1 |
|
$this->handlers['EchoGetDefaultNotifiedUsers'] = function( EchoEvent $event, &$users ) use ( $echoNotificationsManager ) { |
145
|
1 |
|
$echoNotificationsManager->getDefaultRecipientsByType( $event, $users ); |
146
|
1 |
|
return true; |
147
|
|
|
}; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMW::SQLStore::AfterDataUpdateComplete |
151
|
|
|
*/ |
152
|
1 |
|
$this->handlers['SMW::SQLStore::AfterDataUpdateComplete'] = function ( $store, $semanticData, $compositePropertyTableDiffIterator ) use ( $echoNotificationsManager ) { |
153
|
|
|
|
154
|
1 |
|
$changeNotificationFilter = new ChangeNotificationFilter( |
155
|
1 |
|
$semanticData->getSubject(), |
156
|
1 |
|
$store |
157
|
|
|
); |
158
|
|
|
|
159
|
1 |
|
$changeNotificationFilter->setAgent( |
160
|
1 |
|
$GLOBALS['wgUser'] |
161
|
|
|
); |
162
|
|
|
|
163
|
1 |
|
$changeNotificationFilter->setPropertyExemptionList( |
164
|
1 |
|
$GLOBALS['snogChangeNotificationDetectionPropertyExemptionList'] |
165
|
|
|
); |
166
|
|
|
|
167
|
1 |
|
$changeNotificationFilter->isCommandLineMode( |
168
|
1 |
|
$GLOBALS['wgCommandLineMode'] |
169
|
|
|
); |
170
|
|
|
|
171
|
1 |
|
$echoNotificationsManager->createEvent( |
172
|
1 |
|
$changeNotificationFilter->findChangeEvent( $compositePropertyTableDiffIterator ) |
173
|
|
|
); |
174
|
|
|
|
175
|
1 |
|
return true; |
176
|
|
|
}; |
177
|
|
|
|
178
|
1 |
|
} |
179
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.