Discuss Hooks

From semantic-mediawiki.org

Contents

Thread titleRepliesLast modified
Correct way to register "SMW::Store::AfterDataUpdateComplete" hook in extension.json311:10, 1 May 2018
Alias for a special property214:12, 4 May 2015

Correct way to register "SMW::Store::AfterDataUpdateComplete" hook in extension.json

I tried to register "SMW::Store::AfterDataUpdateComplete" in my extention.json but it seems not to be working.

 "Hooks": {
    "SMW::SQLStore::AfterDataUpdateComplete": [
      "SomeExtensionNs\\Hook::onAfterDataUpdateComplete"
     ]
 },

Could it be that there some typo?

It works when i register the Hook the old way like:

		global $wgHooks;
		$wgHooks['SMW::SQLStore::AfterDataUpdateComplete'][] = 'SomeExtenionNs::onAfterDataUpdateComplete'
Racoon (talk)16:05, 26 April 2018

See https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3141.

mwjames (talk)12:41, 28 April 2018

@mwjames, many thanks for looking into this. After reading your reply, I saw that I meant "I tried to register "SMW::SQLStore::AfterDataUpdateComplete" in my extention.json but it seems to be not working." Did I get you right, that it should be possible to register "SMW::SQLStore::AfterDataUpdateComplete" via extension.json? Maybe I did something wrong with namespaces:

 "Hooks": {
    "SMW::SQLStore::AfterDataUpdateComplete": [
      "SomeExtensionNs\\Hook::onAfterDataUpdateComplete"
     ]
 },
Racoon (talk)15:08, 30 April 2018

From reading the reply on GitHub I'd say that this is currently not possible.

[[kgh]] (talk)11:10, 1 May 2018
 
 
 

Alias for a special property

I need to add an alias to a special property (redirect won't work because of the collation).

Ufter the last SMW update the code to do it in LocalSettings.php stopped working again.

The best I could think of is:

use SMW\DIProperty;
DIProperty::registerPropertyAlias ('_SUBP', 'Подчинённое свойству');

Unfortunately, now it causes a fatal error due to the fact that $smwgContLang is not initialised yet.

Looks like I should use a hook. But which hook should it be? The SMW hooks that look useful are listed as deprecated.

Alexander Mashintalk09:51, 4 May 2015

> DIProperty::registerPropertyAlias ('_SUBP', 'Подчинённое свойству');

DIProperty::registerPropertyAlias is deprecated, see [0] (object registration and entity representation are two distinct responsibilities)

> Unfortunately, now it causes a fatal error due to the fact that $smwgContLang is not initialised yet.

Using direct object registration in LocalSettings.php is discouraged as an object might rely on an internal dependency that have not yet been loaded by the time LocalSettings is accessed (as with the Language, or NS constants etc.).

> Looks like I should use a hook. But which hook should it be? The SMW hooks that look useful are listed as deprecated.

'SMW::Property::initProperties', see [1]

$GLOBALS['wgHooks']['SMW::Property::initProperties'][] = function () {
  \SMW\PropertyRegistry::getInstance()->registerPropertyAlias( $id, $label );
};

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/includes/dataitems/SMW_DI_Property.php#L379

[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/src/PropertyRegistry.php#L334

mwjames (talk)13:56, 4 May 2015

Thank you, looks like it works.

Alexander Mashintalk14:12, 4 May 2015