How can an extension have a soft requirement on a module, so that it only adds that module to its ResourceLoader dependencies if the extension providing that module is loaded?
For example, there's no sense in depending on ext.eventLog if the wiki doesn't load Extension:EventLogging, but if it's available then you want the module sent to the browser along with your code. (Obviously your JS would check to see if the module's functions are available before invoking them.)
I think your extension can't change dependencies when specifying its module in $wgResourceModules[], it has to do it later. Maybe in a ResourceLoaderRegisterModules hook (although RL runs that before it registers the static wgResourceModules array), or possibly in a setup function you add to $wgExtensionFunctions
Or, in each onHook handler where you call addModule(), you could test there and add the optional module.
Thanks for any insight, I'll add it to mediawiki.org.
-- =S Page software engineer on Editor Engagement Experiments
I'm confused. You want your extension to load the module only if the extension is loaded? If your extension isnt loaded than what is loading your module.
If you only want to load the module for certain configurations, that sounds like a job for $wgExtensionFunctions -bawolff On 2013-01-27 8:58 PM, "S Page" spage@wikimedia.org wrote:
How can an extension have a soft requirement on a module, so that it only adds that module to its ResourceLoader dependencies if the extension providing that module is loaded?
For example, there's no sense in depending on ext.eventLog if the wiki doesn't load Extension:EventLogging, but if it's available then you want the module sent to the browser along with your code. (Obviously your JS would check to see if the module's functions are available before invoking them.)
I think your extension can't change dependencies when specifying its module in $wgResourceModules[], it has to do it later. Maybe in a ResourceLoaderRegisterModules hook (although RL runs that before it registers the static wgResourceModules array), or possibly in a setup function you add to $wgExtensionFunctions
Or, in each onHook handler where you call addModule(), you could test there and add the optional module.
Thanks for any insight, I'll add it to mediawiki.org.
-- =S Page software engineer on Editor Engagement Experiments
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
I mean How can an extension's ResourceLoader module have a soft dependency on a module provided by another extension?
If ext.eventLogging is available on this wiki, I want to use its functionality in my extension's JS. But my JS can live without it. Extensions with similar soft dependencies on ClickTracking express it as a hard requirement, which makes them harder to use on other wikis.
Thanks.
On Sun, Jan 27, 2013 at 5:07 PM, Brian Wolff bawolff@gmail.com wrote:
I'm confused. You want your extension to load the module only if the extension is loaded? If your extension isnt loaded than what is loading your module.
If you only want to load the module for certain configurations, that sounds like a job for $wgExtensionFunctions -bawolff On 2013-01-27 8:58 PM, "S Page" spage@wikimedia.org wrote:
How can an extension have a soft requirement on a module, so that it only adds that module to its ResourceLoader dependencies if the extension providing that module is loaded?
For example, there's no sense in depending on ext.eventLog if the wiki doesn't load Extension:EventLogging, but if it's available then you want the module sent to the browser along with your code. (Obviously your JS would check to see if the module's functions are available before invoking them.)
I think your extension can't change dependencies when specifying its module in $wgResourceModules[], it has to do it later. Maybe in a ResourceLoaderRegisterModules hook (although RL runs that before it registers the static wgResourceModules array), or possibly in a setup function you add to $wgExtensionFunctions
Or, in each onHook handler where you call addModule(), you could test there and add the optional module.
Thanks for any insight, I'll add it to mediawiki.org.
-- =S Page software engineer on Editor Engagement Experiments
On Sunday, January 27, 2013 at 5:53 PM, S Page wrote:
I mean How can an extension's ResourceLoader module have a soft dependency on a module provided by another extension?
1) Bind to ResourceLoaderRegisterModules. 2) Register the optional module only if its dependencies are present. 3) In your extension's JavaScript code, replace the function with a no-op if it is missing: if ( mediaWiki.eventLog == undefined ) mediaWiki.eventLog = { logEvent: function () {} };
-- Ori Livneh
On Sunday, January 27, 2013 at 6:05 PM, Ori Livneh wrote:
On Sunday, January 27, 2013 at 5:53 PM, S Page wrote:
I mean How can an extension's ResourceLoader module have a soft dependency on a module provided by another extension?
- Bind to ResourceLoaderRegisterModules.
- Register the optional module only if its dependencies are present.
- In your extension's JavaScript code, replace the function with a no-op if it is missing: if ( mediaWiki.eventLog == undefined ) mediaWiki.eventLog = { logEvent: function () {} };
Example: https://gist.github.com/4652474
On 01/27/2013 07:58 PM, S Page wrote:
How can an extension have a soft requirement on a module, so that it only adds that module to its ResourceLoader dependencies if the extension providing that module is loaded?
For example, there's no sense in depending on ext.eventLog if the wiki doesn't load Extension:EventLogging, but if it's available then you want the module sent to the browser along with your code. (Obviously your JS would check to see if the module's functions are available before invoking them.)
That's one design decision, but I don't think it's the obvious one. In fact, it's rather uncommon.
The way most loggers are used, you can always call the log function (without checking, or defining your own shim), and it's up to the logging library to be a no-op or actually log.
Matt Flaschen
On Sun, Jan 27, 2013 at 6:42 PM, Matthew Flaschen mflaschen@wikimedia.orgwrote:
On 01/27/2013 07:58 PM, S Page wrote:
How can an extension have a soft requirement on a module, so that it only adds that module to its ResourceLoader dependencies if the extension providing that module is loaded?
For example, there's no sense in depending on ext.eventLog if the wiki doesn't load Extension:EventLogging, but if it's available then you want the module sent to the browser along with your code. (Obviously your JS would check to see if the module's functions are available before invoking them.)
That's one design decision, but I don't think it's the obvious one. In fact, it's rather uncommon.
The way most loggers are used, you can always call the log function (without checking, or defining your own shim), and it's up to the logging library to be a no-op or actually log.
Matt Flaschen
I agree, but if it is unknown whether the wiki had this logging library installed, that approach doesn't help.
However to get back at S' question, I'd recommend changing the rules because the game is no fun this way.
Variable dependencies mean you can't rely on something, that's an unacceptable design. Whatever it is that insists the need for a variable dependency should be changed instead.
I think the picture you present is misrepresented. I'd say, just depend on it. But for some reason you don't want to.
Requiring that the wiki install it seems like a trivial thing. That can't be the real reason.
I presume that when you say it is unknown whether the wiki has it installed, the real issue is that it is unknown whether the wiki has it enabled at this time.
Being able to disable logging whenever you desire is a valid use case.
However in that case the problem lies with the logging library to come up with a sane way to enable/disable the library that does not involve commenting out the "require_once" line of the extensions' installation. But for example something like $wgEventLoggingEnable.
Then the logging library would disable the backend API when the extension is disabled and also swap the front-end client for a no-op.
-- Krinkle
On 01/28/2013 04:55 PM, Krinkle wrote:
Requiring that the wiki install it seems like a trivial thing. That can't be the real reason.
I presume that when you say it is unknown whether the wiki has it installed, the real issue is that it is unknown whether the wiki has it enabled at this time.
I also proposed that we say "just install it". There is already a default "blank" configuration (e.g. $wgEventLoggingFile = false is already the default).
We just need to make sure it behaves correctly as a no-op logger out of the box.
The only down side is you have to do an extra git clone, which I don't think is a big deal.
Matt Flaschen
wikitech-l@lists.wikimedia.org