Page MenuHomePhabricator

Only load Javascript when it may be used
Closed, ResolvedPublic12 Estimated Story Points

Description

There is currently a check in the main Javascript module to actually run the code, but it is still loaded. This can be done in WikispeechHooks::onBeforePageDisplay() and should check namespace and if the latest revision is viewed (listening to earlier revisions is currently not possible but JS still gets loaded).

To do:

  • Only load JS if actually needed
  • Ensure all cases which prevents listening also prevent JS loading (e.g. namespace, user-rights, user has disabled Wikispeech etc.)

Event Timeline

can you provide link to source code ? I want to solve this

@Vaibhav0199 This task will likely be updated since it also touches on a second need we have. I can ping you ones the two, and their effect on each other, has been clarified.

If you anyway want to have a look at the source code it's over at gerrit:mediawiki/extensions/Wikispeech WikispeechHooks.php

@Sebastian_Berlin-WMSE I believe the things to check for are probably: whitelisted namespace, supported pagelanguage and current revision

Yes, checking page language is probably good to do here too. Technically, you could have a page with an unsupported language containing a section with a supported language (e.g. a quote), but that's an edge.

Which version control is used here to keep track of projects ?
I mean how can integrate changes and test them

Which version control is used here to keep track of projects ?
I mean how can integrate changes and test them

gerrit is based on git if that is what you mean? You can find some more info about it via this portal page. For local testing Vagrant is used.

Yes, checking page language is probably good to do here too. Technically, you could have a page with an unsupported language containing a section with a supported language (e.g. a quote), but that's an edge.

Thats an edge case which is also currently not supported (we rely entirely on pagelanguage).

I spotted T146742: Use `addJsConfigVars()` to enable extension variables which is probably also worth considering at the same time since it also has to do with limiting the loaded JS.

Lokal_Profil set the point value for this task to 12.Mar 11 2020, 1:17 PM

Change 591928 had a related patch set uploaded (by Sebastian Berlin (WMSE); owner: Sebastian Berlin (WMSE)):
[mediawiki/extensions/Wikispeech@master] Only load Javascript modules when they can be used

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

I ran into some issues with code in ext.wikispeech.main running during tests which caused error for Jenkins. After some time of troubleshooting I decided just to keep the namespace check there to prevent this. It's not elegant, but it'll do for now.

Change 591928 merged by jenkins-bot:
[mediawiki/extensions/Wikispeech@master] Only load Javascript modules when they can be used

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