1 | <?php |
||
14 | class Hooks { |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | private $handlers = []; |
||
20 | |||
21 | /** |
||
22 | * @var Cache |
||
23 | */ |
||
24 | private $cache; |
||
25 | |||
26 | /** |
||
27 | * @since 1.0 |
||
28 | * |
||
29 | * @param array $config |
||
30 | */ |
||
31 | 2 | public function __construct( $config = [] ) { |
|
34 | |||
35 | /** |
||
36 | * @since 1.0 |
||
37 | * |
||
38 | * @param Cache $cache |
||
39 | */ |
||
40 | 1 | public function setCache( Cache $cache ) { |
|
43 | |||
44 | /** |
||
45 | * @since 1.0 |
||
46 | */ |
||
47 | public static function hasPropertyCollisions( $var ) { |
||
69 | |||
70 | /** |
||
71 | * @since 1.0 |
||
72 | * |
||
73 | 1 | * @param array &$vars |
|
74 | 1 | */ |
|
75 | 1 | public static function initExtension( &$vars ) { |
|
76 | |||
77 | 1 | /** |
|
78 | * @see https://www.semantic-mediawiki.org/wiki/Hooks#SMW::Config::BeforeCompletion |
||
79 | * |
||
80 | * @since 1.0 |
||
81 | * |
||
82 | 1 | * @param array &$config |
|
83 | 1 | */ |
|
84 | $vars['wgHooks']['SMW::Config::BeforeCompletion'][] = function( &$config ) { |
||
85 | 1 | ||
86 | if ( isset( $config['smwgImportFileDirs'] ) ) { |
||
87 | $config['smwgImportFileDirs'] += [ 'sar' => __DIR__ . '/../data/import' ]; |
||
88 | } |
||
89 | 1 | ||
90 | 1 | return true; |
|
91 | }; |
||
92 | } |
||
93 | 1 | ||
94 | /** |
||
95 | * @since 1.0 |
||
96 | */ |
||
97 | public function register() { |
||
98 | foreach ( $this->handlers as $name => $callback ) { |
||
99 | \Hooks::register( $name, $callback ); |
||
100 | } |
||
101 | } |
||
102 | 1 | ||
103 | 1 | /** |
|
104 | * @since 1.0 |
||
105 | */ |
||
106 | public function deregister() { |
||
107 | foreach ( array_keys( $this->handlers ) as $name ) { |
||
108 | |||
109 | \Hooks::clear( $name ); |
||
110 | |||
111 | // Remove registered `wgHooks` hooks that are not cleared by the |
||
112 | // previous call |
||
113 | 1 | if ( isset( $GLOBALS['wgHooks'][$name] ) ) { |
|
114 | 1 | unset( $GLOBALS['wgHooks'][$name] ); |
|
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @since 1.0 |
||
121 | * |
||
122 | * @param string $name |
||
123 | 1 | * |
|
124 | * @return boolean |
||
125 | 1 | */ |
|
126 | 1 | public function isRegistered( $name ) { |
|
127 | return \Hooks::isRegistered( $name ); |
||
128 | } |
||
129 | 1 | ||
130 | /** |
||
131 | * @since 1.0 |
||
132 | * |
||
133 | * @param string $name |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | public function getHandlers( $name ) { |
||
138 | 1 | return \Hooks::getHandlers( $name ); |
|
139 | } |
||
140 | 1 | ||
141 | 1 | /** |
|
142 | * @since 1.0 |
||
143 | * |
||
144 | 1 | * @param Title $title |
|
145 | * @param integer $latestRevID |
||
146 | 1 | */ |
|
147 | public function onIsApprovedRevision( $title, $latestRevID ) { |
||
148 | |||
149 | $approvedRevsHandler = new ApprovedRevsHandler( |
||
150 | new ApprovedRevsFacade() |
||
151 | ); |
||
152 | |||
153 | return $approvedRevsHandler->isApprovedUpdate( $title, $latestRevID ); |
||
154 | } |
||
155 | 1 | ||
156 | /** |
||
157 | 1 | * @since 1.0 |
|
158 | 1 | * |
|
159 | * @param Title $title |
||
160 | * @param Revision|null &$revision |
||
161 | 1 | */ |
|
162 | public function onChangeRevision( $title, &$revision ) { |
||
163 | 1 | ||
164 | $approvedRevsHandler = new ApprovedRevsHandler( |
||
165 | new ApprovedRevsFacade() |
||
166 | ); |
||
167 | |||
168 | $approvedRevsHandler->doChangeRevision( $title, $revision ); |
||
169 | |||
170 | return true; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | 1 | * @since 1.0 |
|
175 | * |
||
176 | 1 | * @param Title $title |
|
177 | 1 | * @param integer &$latestRevID |
|
178 | */ |
||
179 | 1 | public function onOverrideRevisionID( $title, &$latestRevID ) { |
|
180 | |||
181 | $approvedRevsHandler = new ApprovedRevsHandler( |
||
182 | new ApprovedRevsFacade() |
||
183 | ); |
||
184 | |||
185 | $approvedRevsHandler->doChangeRevisionID( $title, $latestRevID ); |
||
186 | |||
187 | return true; |
||
188 | } |
||
189 | |||
190 | 1 | /** |
|
191 | * @see https://www.semantic-mediawiki.org/wiki/Hooks#SMW::Property::initProperties |
||
192 | 1 | * |
|
193 | 1 | * @since 1.0 |
|
194 | * |
||
195 | * @param ProertyRegistry $$registry |
||
|
|||
196 | 1 | * @param integer &$latestRevID |
|
197 | 1 | */ |
|
198 | public function onInitProperties( $registry ) { |
||
199 | |||
200 | 1 | $propertyRegistry = new PropertyRegistry(); |
|
201 | $propertyRegistry->register( $registry ); |
||
202 | 1 | ||
203 | return true; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * @see https://www.semantic-mediawiki.org/wiki/Hooks#SMWStore::updateDataBefore |
||
208 | * |
||
209 | * @since 1.0 |
||
210 | * |
||
211 | * @param ProertyRegistry $$registry |
||
212 | * @param integer &$latestRevID |
||
213 | */ |
||
214 | public function onUpdateDataBefore( $store, $semanticData ) { |
||
215 | 1 | ||
216 | $propertyAnnotator = new PropertyAnnotator( |
||
217 | 1 | new ServicesFactory() |
|
218 | ); |
||
219 | 1 | ||
220 | $propertyAnnotator->setLogger( |
||
221 | ApplicationFactory::getInstance()->getMediaWikiLogger( 'smw-approved-revs' ) |
||
222 | ); |
||
223 | |||
224 | $propertyAnnotator->addAnnotation( $semanticData ); |
||
225 | |||
226 | return true; |
||
227 | } |
||
228 | 1 | ||
229 | 1 | /** |
|
230 | * @see ?? |
||
231 | 1 | * |
|
232 | * @since 1.0 |
||
233 | * |
||
234 | * @param ParserOutput $output |
||
235 | * @param Title $title |
||
236 | * @param integer $rev_id |
||
237 | * @param string $content |
||
238 | */ |
||
239 | public function onApprovedRevsRevisionApproved( $output, $title, $rev_id, $content ) { |
||
257 | |||
258 | /** |
||
259 | * @see ?? |
||
260 | * |
||
261 | * @since 1.0 |
||
262 | * |
||
263 | * @param Parser $parser |
||
264 | * @param Title $title |
||
265 | * @param integer $timestamp |
||
266 | 1 | * @param string $sha1 |
|
267 | */ |
||
268 | 1 | public function onApprovedRevsFileRevisionApproved( $parser, $title, $timestamp, $sha1 ) { |
|
282 | |||
283 | 1 | /** |
|
284 | * @see https://www.semantic-mediawiki.org/wiki/Hooks#... |
||
285 | 1 | * |
|
286 | 1 | * @since 1.0 |
|
287 | * |
||
288 | * @param Title $title |
||
289 | 1 | * @param File &$file |
|
290 | */ |
||
291 | 1 | public function onChangeFile( $title, &$file ) { |
|
301 | 2 | ||
302 | 2 | /** |
|
303 | 2 | * @see https://www.semantic-mediawiki.org/wiki/Hooks#... |
|
304 | 2 | * |
|
305 | 2 | * @since 1.0 |
|
306 | * |
||
307 | 2 | * @param Title $title |
|
308 | * @param File &$file |
||
309 | */ |
||
310 | public function onChangeFileBeforeIngestProcessComplete( $title, &$file ) { |
||
320 | |||
321 | private function registerHandlers( $config ) { |
||
333 | |||
334 | } |
||
335 |
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.