Page MenuHomePhabricator

Loading dependency from within another extension
Open, Needs TriagePublic

Description

As part of our on-going extension.json experiment, SemanticGlossary has been converted to use it but I'm a bit unhappy about how it loads the required Lingo extension from within the callback and uses the ExtensionRegistry instance:

// must NOT use ExtensionRegistry::getInstance() to avoid recursion!
$registry = new ExtensionRegistry();
if ( file_exists( __DIR__ . '/extensions/Lingo/extension.json' ) ) {
	$registry->load( __DIR__ . '/extensions/Lingo/extension.json' );
} else {
	$registry->load( $GLOBALS[ 'wgExtensionDirectory' ] . '/Lingo/extension.json' );
}

Some advise on how to improve the situation would be much appreciated. SemanticFormsSelect [2] (not released yet with extension.json) currently enforces a die( ... ) on the event that the required PageForms extension is not manually added to the LocalSettings which is suboptimal [3].

[0] https://github.com/SemanticMediaWiki/SemanticGlossary/blob/master/SemanticGlossary.php#L22-L28
[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/1732
[2] https://github.com/SemanticMediaWiki/SemanticFormsSelect/blob/master/extension.json
[3] https://github.com/SemanticMediaWiki/SemanticFormsSelect/issues/44#issuecomment-263418602

Event Timeline

mwjames created this task.Dec 3 2016, 2:36 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 3 2016, 2:36 AM
mwjames updated the task description. (Show Details)Dec 3 2016, 2:37 AM
Legoktm added a subscriber: Legoktm.Dec 3 2016, 3:16 AM

At the very least, this is going to be blocked on Florian's work towards T117277: Extend 'requires' section of extension.json to include extensions so extensions can specify dependencies in their extension.json. This should be doable as a follow-up to that - check if the extension has a missing dependency, if it exists on the file system in $wgExtensionDirectory, load it.

That said, I would strongly not recommend loading extensions manually using an ExtensionRegistry instance that is not the main one - it's not supported, and won't work with features like T117277.

Kghbln added a subscriber: Kghbln.May 24 2017, 7:03 AM

At the very least, this is going to be blocked on Florian's work towards T117277: Extend 'requires' section of extension.json to include extensions so extensions can specify dependencies in their extension.json. This should be doable as a follow-up to that - check if the extension has a missing dependency, if it exists on the file system in $wgExtensionDirectory, load it.
That said, I would strongly not recommend loading extensions manually using an ExtensionRegistry instance that is not the main one - it's not supported, and won't work with features like T117277.

So where to we go from there now that T117277 was tackled in the meantime?

Florian claimed this task.Jun 10 2017, 5:43 PM

Change 358177 had a related patch set uploaded (by Florianschmidtwelzow; owner: Florianschmidtwelzow):
[mediawiki/core@master] Try to autoload required, but not installed extensions

https://gerrit.wikimedia.org/r/358177