Alias for a special property

From semantic-mediawiki.org

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.

09: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

13:56, 4 May 2015

Thank you, looks like it works.

14:12, 4 May 2015