summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/docs/technical/hooks.md
blob: b89bfefbb8ac9a571f68366a7e42cbe8986b93c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
This document contains details about event handlers (also known as [Hooks][hooks]) provided by Semantic MediaWiki to enable users to extent and integrate custom specific solutions.

Implementing a hook should be made in consideration of the expected performance impact for the front-end (additional DB read/write transactions etc.) and/or the back-end (prolonged job backlog etc.) process.

# List of available hooks

## 1.9

- `SMW::Factbox::BeforeContentGeneration` to replace or amend text elements shown in a Factbox. See also `$smwgFactboxUseCache` settings.<sup>Use of `smwShowFactbox` was deprecated with 1.9</sup>
- `SMW::Job::updatePropertyJobs` to add additional update jobs for a property and related subjects.<sup>Use of `smwUpdatePropertySubjects` was deprecated with 1.9</sup>
- `SMW::DataType::initTypes` to add additional DataType support.<sup>Use of `smwInitDatatypes` was deprecated with 1.9</sup>
- `SMW::SQLStore::updatePropertyTableDefinitions` to add additional table definitions during initialization.

## 2.1

### SMW::Store::BeforeQueryResultLookupComplete

* Version: 2.1
* Description: Hook to return a `QueryResult` object before the standard selection process is started and allows to suppress the standard selection process completely by returning `false`.
* Reference class: `SMW_SQLStore3.php`

<pre>
\Hooks::register( 'SMW::Store::AfterQueryResultLookupComplete', function( $store, $query, &$queryResult, $queryEngine ) {

	// Allow default processing
	return true;

	// Stop further processing
	return false;
} );
</pre>

### SMW::Store::AfterQueryResultLookupComplete

* Version: 2.1
* Description: Hook to manipulate a `QueryResult` after the selection process.
* Reference class: `SMW_SQLStore3.php`

<pre>
\Hooks::register( 'SMW::Store::AfterQueryResultLookupComplete', function( $store, &$queryResult ) {

	return true;
} );
</pre>

### SMW::Property::initProperties

* Version: 2.1
* Description: Hook to add additional predefined properties (`smwInitProperties` was deprecated with 2.1)
* Reference class: `SMW\PropertyRegistry`

<pre>
\Hooks::register( 'SMW::Property::initProperties', function( $propertyRegistry ) {

	return true;
} );
</pre>

### SMW::SQLStore::BeforeDeleteSubjectComplete

* Version: 2.1
* Description: Hook is called before the deletion of a subject is completed
* Reference class: `SMW_SQLStore3_Writers.php`

<pre>
\Hooks::register( 'SMW::SQLStore::BeforeDeleteSubjectComplete', function( $store, $title ) {

	return true;
} );
</pre>

### SMW::SQLStore::AfterDeleteSubjectComplete

* Version: 2.1
* Description: Hook is called after the deletion of a subject is completed
* Reference class: `SMW_SQLStore3_Writers.php`

<pre>
\Hooks::register( 'SMW::SQLStore::AfterDeleteSubjectComplete', function( $store, $title ) {

	return true;
} );
</pre>

### SMW::SQLStore::BeforeChangeTitleComplete

* Version: 2.1
* Description: Hook is called before change to a subject is completed
* Reference class: `SMW_SQLStore3_Writers.php`

<pre>
\Hooks::register( 'SMW::SQLStore::BeforeChangeTitleComplete', function( $store, $oldTitle, $newTitle, $pageId, $redirectId ) {

	return true;
} );
</pre>

## 2.2

### SMW::Parser::BeforeMagicWordsFinder

* Version: 2.2
* Description: Hook allowing to extend the magic words list that the `InTextAnnotationParser` should search for the wikitext.
* Reference class: `\SMW\InTextAnnotationParser`

<pre>
\Hooks::register( 'SMW::Parser::BeforeMagicWordsFinder', function( array &$magicWords ) {

	return true;
} );
</pre>

## 2.3

### SMW::SQLStore::BeforeDataRebuildJobInserts

* Version: 2.3
* Description: Hook to add update jobs while running the rebuild process.<sup>Use of `smwRefreshDataJobs` was deprecated with 2.3</sup>
* Reference class: `\SMW\SQLStore\EntityRebuildDispatcher`

<pre>
\Hooks::register( 'SMW::SQLStore::BeforeDataRebuildJobInsert', function( $store, array &$jobs ) {

	return true;
} );
</pre>

### SMW::SQLStore::AddCustomFixedPropertyTables

* Version: 2.3
* Description: Hook to add fixed property table definitions
* Reference class: `\SMW\MediaWiki\Specials\Browse\ContentsBuilder`

<pre>
\Hooks::register( 'SMW::SQLStore::AddCustomFixedPropertyTables', function( array &$customFixedProperties, &$propertyTablePrefix ) {
	$customFixedProperties['Foo'] = '_Bar';

	return true;
} );
</pre>

### SMW::Browse::AfterIncomingPropertiesLookupComplete

* Version: 2.3
* Description: Hook to extend the incoming properties display for `Special:Browse`
* Reference class: `\SMW\MediaWiki\Specials\Browse\ContentsBuilder`

<pre>
\Hooks::register( 'SMW::Browse::AfterIncomingPropertiesLookupComplete', function( $store, $semanticData, $requestOptions ) {

	return true;
} );
</pre>

### SMW::Browse::BeforeIncomingPropertyValuesFurtherLinkCreate

* Version: 2.3
* Description: Hook to replace the standard `SearchByProperty` with a custom link to an extended list of results (return `false` to replace the link)
* Reference class: `\SMW\MediaWiki\Specials\Browse\ContentsBuilder`

<pre>
\Hooks::register( 'SMW::Browse::BeforeIncomingPropertyValuesFurtherLinkCreate', function( $property, $subject, &$propertyValue ) {

	return true;
} );
</pre>

### SMW::SQLStore::AfterDataUpdateComplete

* Version: 2.3
* Description: Hook to add processing after the update has been completed and provides `ChangeOp` to identify entities that have been added/removed during the update. (`SMWSQLStore3::updateDataAfter` was deprecated with 2.3)

<pre>
\Hooks::register( 'SMW::SQLStore::AfterDataUpdateComplete', function( $store, $semanticData, $changeOp ) {

	return true;
} );
</pre>

## 2.4

### SMW::FileUpload::BeforeUpdate

* Version: 2.4
* Description: Hook to add extra annotations before the `Store` update is triggered

<pre>
\Hooks::register( 'SMW::FileUpload::BeforeUpdate', function( $filePage, $semanticData  ) {

	return true;
} );
</pre>

## 2.5

### SMW::Job::AfterUpdateDispatcherJobComplete

* Version: 2.5
* Description: Hook allows to add extra jobs after `UpdateDispatcherJob` has been processed.
* Reference class: `\SMW\MediaWiki\Jobs\UpdateDispatcherJob`

<pre>
\Hooks::register( 'SMW::Job::AfterUpdateDispatcherJobComplete', function( $job ) {

	// Find related dependencies
	$title = $job->getTitle();

	return true;
} );
</pre>

### SMW::SQLStore::Installer::AfterCreateTablesComplete

* Version: 2.5
* Description: Hook allows to add extra tables after the creation process as been finalized.
* Reference class: `\SMW\SQLStore\Installer`

<pre>
\Hooks::register( 'SMW::SQLStore::Installer::AfterCreateTablesComplete', function( $tableBuilder, $messageReporter ) {

	// Output details on the activity
	$messageReporter->reportMessage( '...' );

	// See documentation in the available TableBuilder interface
	$tableBuilder->create( ... );

	return true;
} );
</pre>

### SMW::SQLStore::Installer::AfterDropTablesComplete

* Version: 2.5
* Description: Hook allows to remove extra tables after the drop process as been finalized.
* Reference class: `\SMW\SQLStore\Installer`

<pre>
\Hooks::register( 'SMW::SQLStore::Installer::AfterDropTablesComplete', function( $tableBuilder, $messageReporter ) {

	// Output details on the activity
	$messageReporter->reportMessage( '...' );

	// See documentation in the available TableBuilder interface
	$tableBuilder->drop( ... );

	return true;
} );
</pre>

## 3.0

### SMW::GetPreferences

* Version: 3.0
* Description: Hook allows to add extra preferences that are ordered on the Semantic MediaWiki user preference tab
* Reference class: `\SMW\MediaWiki\Hooks\GetPreferences`

<pre>
\Hooks::register( 'SMW::GetPreferences', function( $user, &$preferences ) {


	return true;
} );
</pre>

### SMW::Setup::AfterInitializationComplete

* Version: 3.0
* Description: Hook allows to modify global configuration after initialization of Semantic MediaWiki is completed
* Reference class: `\SMW\Setup`

<pre>
use Hooks;

Hooks::register( 'SMW::Setup::AfterInitializationComplete', function( &$vars ) {

	// #2565
	unset( $GLOBALS['wgGroupPermissions']['smwcurator'] );

	return true;
} );
</pre>

### SMW::Exporter::Controller::AddExpData

* Version: 3.0
* Description: Hook allows to add additional RDF data for a selected page (was `smwAddToRDFExport`)
* Reference class: `SMWExportController`

<pre>
use Hooks;

Hooks::register( 'SMW::Exporter::Controller::AddExpData', function( DIWikiPage $subject, &$expDataList, $hasRecursionDepth, $withBacklinks ) {

	// $expData = new ExpData( ... );
	// $expDataList[] = $expData;

	return true;
} );
</pre>

### SMW::SQLStore::EntityReferenceCleanUpComplete

* Version: 3.0
* Description: Hook allows to get information about which entities have been removed
* Reference class: `PropertyTableIdReferenceDisposer`

<pre>
use Hooks;

Hooks::register( 'SMW::SQLStore::EntityReferenceCleanUpComplete', function( $store, $id, $subject, $isRedirect ) {

	return true;
} );
</pre>

### SMW::LinksUpdate::ApprovedUpdate

* Version: 3.0
* Description: Hook allows to suppress an update where for example the `latestRevID` is not the revision that is approved an should not be used for the `SemanticData` representation.
* Reference class: `SMW\MediaWiki\Hooks\LinksUpdateConstructed`

If you do suppress a revision, please log the event and make it visible to a user (or administrator) that an update was refused.

<pre>
use Hooks;

Hooks::register( 'SMW::LinksUpdate::ApprovedUpdate', function( $title, $latestRevID ) {

	// If you need to decline an update
	// return false;

	return true;
} );
</pre>

### SMW::Parser::ChangeRevision

* Version: 3.0
* Description: Hook allows to forcibly change a revision used during content parsing as in case of the `UpdateJob` execution or when running `rebuildData.php`.
* Reference class: `SMW\ContentParser`

If you do alter a revision, please log the event and make it visible to a user (or administrator) that it was changed.

<pre>
use Hooks;

Hooks::register( 'SMW::Parser::ChangeRevision', function( $title, &$revision ) {

	// Set a revision
	// $revision = \Revision::newFromId( $id );

	return true;
} );
</pre>

### SMW::Admin::TaskHandlerFactory

* Version: 3.0
* Description: Hook allows to extend available `TaskHandler` in `Special:SemanticMediaWiki`
* Reference class: `SMW\MediaWiki\Specials\Admin\TaskHandlerFactory`

<pre>
use Hooks;

Hooks::register( 'SMW::Admin::TaskHandlerFactory', function( &$taskHandlers, $store, $outputFormatter, $user ) {

	// Instance of TaskHandler
	// $taskHandlers[] = new FooTaskHandler();

	return true;
} );
</pre>

### SMW::DataUpdater::ContentProcessor

* Version: 3.0
* Description: Hook allows to extend the `SemanticData` with information from the `Content` object
* Reference class: `SMW\DataUpdater`

<pre>
use Hooks;

Hooks::register( 'SMW::DataUpdater::ContentProcessor', function( $semanticData, $content ) {

	if ( $content->getModel() === ' ... ' ) {
		// $data = $content->getNativeData();
		// ...
		// $semanticData->addPropertyObjectValue( ... );
	}

	return true;
} );
</pre>

## Other available hooks

Subsequent hooks should be renamed to follow a common naming practice that help distinguish them from other hook providers. In any case this list needs details and examples.

* `SMWParamFormat`, SMWResultFormat
* `\SMW\Store`, SMWStore::updateDataBefore (SMW::Store::BeforeDataUpdateComplete)
* `\SMW\Store`, SMWStore::updateDataAfter (SMW::Store::AfterDataUpdateComplete)
* `SMWSQLStore3Writers`, SMWSQLStore3::updateDataBefore (SMW::SQLStore::BeforeDataUpdateComplete)

[hooks]: https://www.mediawiki.org/wiki/Hooks "Manual:Hooks"