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

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.

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?

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

Removing task assignee due to inactivity, as this open task has been assigned to the same person for more than two years (see the emails sent to the task assignee on Oct27 and Nov23). Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome.
(See https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator.)