1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\ApprovedRevs; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @license GNU GPL v2+ |
9
|
|
|
* @since 1.0 |
10
|
|
|
* |
11
|
|
|
* @author mwjames |
12
|
|
|
*/ |
13
|
|
|
class Hooks { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private $handlers = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @since 1.0 |
22
|
|
|
* |
23
|
|
|
* @param array $config |
24
|
|
|
*/ |
25
|
2 |
|
public function __construct( $config = [] ) { |
26
|
2 |
|
$this->registerHandlers( $config ); |
27
|
2 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
public static function hasPropertyCollisions( $var ) { |
33
|
|
|
|
34
|
|
|
if ( !isset( $var['sespgEnabledPropertyList'] ) ) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// SESP properties! |
39
|
|
|
$list = [ |
40
|
|
|
'_APPROVED' => true, |
41
|
|
|
'_APPROVEDBY' => true, |
42
|
|
|
'_APPROVEDDATE' => true, |
43
|
|
|
'_APPROVEDSTATUS' => true |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
foreach ( $var['sespgEnabledPropertyList'] as $key ) { |
47
|
|
|
if ( isset( $list[$key] ) ) { |
48
|
|
|
return $key; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @since 1.0 |
57
|
|
|
*/ |
58
|
1 |
|
public function register() { |
59
|
1 |
|
foreach ( $this->handlers as $name => $callback ) { |
60
|
1 |
|
\Hooks::register( $name, $callback ); |
61
|
|
|
} |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @since 1.0 |
66
|
|
|
*/ |
67
|
1 |
|
public function deregister() { |
68
|
1 |
|
foreach ( array_keys( $this->handlers ) as $name ) { |
69
|
|
|
|
70
|
1 |
|
\Hooks::clear( $name ); |
71
|
|
|
|
72
|
|
|
// Remove registered `wgHooks` hooks that are not cleared by the |
73
|
|
|
// previous call |
74
|
1 |
|
if ( isset( $GLOBALS['wgHooks'][$name] ) ) { |
75
|
1 |
|
unset( $GLOBALS['wgHooks'][$name] ); |
76
|
|
|
} |
77
|
|
|
} |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @since 1.0 |
82
|
|
|
* |
83
|
|
|
* @param string $name |
84
|
|
|
* |
85
|
|
|
* @return boolean |
86
|
|
|
*/ |
87
|
1 |
|
public function isRegistered( $name ) { |
88
|
1 |
|
return \Hooks::isRegistered( $name ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @since 1.0 |
93
|
|
|
* |
94
|
|
|
* @param string $name |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
1 |
|
public function getHandlers( $name ) { |
99
|
1 |
|
return \Hooks::getHandlers( $name ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @since 1.0 |
104
|
|
|
* |
105
|
|
|
* @param Title $title |
106
|
|
|
* @param integer $latestRevID |
107
|
|
|
*/ |
108
|
1 |
|
public function onSkipUpdate( $title, $latestRevID ) { |
109
|
|
|
|
110
|
1 |
|
$approvedRevsHandler = new ApprovedRevsHandler( |
111
|
1 |
|
new ApprovedRevsFacade() |
112
|
|
|
); |
113
|
|
|
|
114
|
1 |
|
return $approvedRevsHandler->isApprovedUpdate( $title, $latestRevID ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @since 1.0 |
119
|
|
|
* |
120
|
|
|
* @param Title $title |
121
|
|
|
* @param Revision|null &$revision |
122
|
|
|
*/ |
123
|
1 |
|
public function onChangeRevision( $title, &$revision ) { |
124
|
|
|
|
125
|
1 |
|
$approvedRevsHandler = new ApprovedRevsHandler( |
126
|
1 |
|
new ApprovedRevsFacade() |
127
|
|
|
); |
128
|
|
|
|
129
|
1 |
|
$approvedRevsHandler->doChangeRevision( $title, $revision ); |
130
|
|
|
|
131
|
1 |
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @since 1.0 |
136
|
|
|
* |
137
|
|
|
* @param Title $title |
138
|
|
|
* @param integer &$latestRevID |
139
|
|
|
*/ |
140
|
1 |
|
public function onOverrideRevisionID( $title, &$latestRevID ) { |
141
|
|
|
|
142
|
1 |
|
$approvedRevsHandler = new ApprovedRevsHandler( |
143
|
1 |
|
new ApprovedRevsFacade() |
144
|
|
|
); |
145
|
|
|
|
146
|
1 |
|
$approvedRevsHandler->doChangeRevisionID( $title, $latestRevID ); |
147
|
|
|
|
148
|
1 |
|
return true; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks#SMW::Property::initProperties |
153
|
|
|
* |
154
|
|
|
* @since 1.0 |
155
|
|
|
* |
156
|
|
|
* @param ProertyRegistry $$registry |
|
|
|
|
157
|
|
|
* @param integer &$latestRevID |
158
|
|
|
*/ |
159
|
|
|
public function onInitProperties( $registry ) { |
160
|
|
|
|
161
|
|
|
$propertyRegistry = new PropertyRegistry(); |
162
|
|
|
$propertyRegistry->register( $registry ); |
163
|
|
|
|
164
|
|
|
return true; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Hooks#SMWStore::updateDataBefore |
169
|
|
|
* |
170
|
|
|
* @since 1.0 |
171
|
|
|
* |
172
|
|
|
* @param ProertyRegistry $$registry |
|
|
|
|
173
|
|
|
* @param integer &$latestRevID |
174
|
|
|
*/ |
175
|
|
|
public function onUpdateDataBefore( $store, $semanticData ) { |
176
|
|
|
|
177
|
|
|
$propertyAnnotator = new PropertyAnnotator( |
178
|
|
|
new ServicesFactory() |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
$propertyAnnotator->setLogger( |
182
|
|
|
ApplicationFactory::getInstance()->getMediaWikiLogger( 'smw-approved-revs' ) |
183
|
|
|
); |
184
|
|
|
|
185
|
|
|
$propertyAnnotator->addAnnotation( $semanticData ); |
186
|
|
|
|
187
|
|
|
return true; |
188
|
|
|
} |
189
|
|
|
|
190
|
2 |
|
private function registerHandlers( $config ) { |
|
|
|
|
191
|
2 |
|
$this->handlers = [ |
192
|
2 |
|
'SMW::LinksUpdate::ApprovedUpdate' => [ $this, 'onSkipUpdate' ], |
193
|
2 |
|
'SMW::DataUpdater::SkipUpdate' => [ $this, 'onSkipUpdate' ], |
194
|
2 |
|
'SMW::Parser::ChangeRevision' => [ $this, 'onChangeRevision' ], |
195
|
2 |
|
'SMW::Factbox::OverrideRevisionID' => [ $this, 'onOverrideRevisionID' ], |
196
|
2 |
|
'SMW::Property::initProperties' => [ $this, 'onInitProperties' ], |
197
|
2 |
|
'SMWStore::updateDataBefore' => [ $this, 'onUpdateDataBefore' ] |
198
|
|
|
]; |
199
|
2 |
|
} |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.