Hi,
I have enabled a Gadget on Fa Wikipedia (if you go to https://fa.wikipedia.org/wiki/Special:Preferences#mw-prefsection-gadgets it is the second one from the top) which depends on ext.gadgets.morebits (as defined on https://fa.wikipedia.org/wiki/MediaWiki:Gadgets-definition). It adds a portlet menu labeled "تذکر" which shows only on user talk pages. The menu contains a number of links, some of which start with "+".
These "+" links are supposed to open a dialog using morebits. If you use *debug=true* to bypass ResourceLoader, they work fine (feel free to try on my talk page https://fa.wikipedia.org/wiki/User_talk:Huji?debug=true after enabling the gadget for your account on Fa WP). However, if you don't bypass ResourceLoader, the "+" links won't work and an error is thrown reading "SimpleWindow is not defined" (try on my talk page without bypassing RL https://fa.wikipedia.org/wiki/User_talk:Huji). Note that SimpleWindow is defined in morebits.js
My questions are as follows:
1) How come it works when you bypass ResourceLoader? Note that nothing else has changed recently (including the morebits.js code on that Wiki)
2) Is it safe to assume that just by listing ext.gadgets.morebits as a dependency, morebits will be properly loaded by ResourceLoader?
3) Unless 1 or 2 answers it already: how would I fix this problem and make the gadget work?
Thanks,
Huji
On Thu, 20 Aug 2015 04:07:57 +0200, Huji Lee huji.huji@gmail.com wrote:
However, if you don't bypass ResourceLoader, the "+" links won't work and an error is thrown reading "SimpleWindow is not defined" (try on my talk page without bypassing RL https://fa.wikipedia.org/wiki/User_talk:Huji). Note that SimpleWindow is defined in morebits.js
When you load a script through ResourceLoader, it's not executed in global context. This means that global variables you define are actually *not global* (they are local to the function your code is wrapped in), unless you explicitly assign them as `window` properties.
The code of the gadget in question actually does it right:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var UserMessages = {}; window.UserMessages = UserMessages; // global access
(It would be sufficient to just do `window.UserMessages = {}`, but this is also just as correct.)
morebits doesn't:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var SimpleWindow = function( width, height ) { ...
This should be changed to:
window.SimpleWindow = function( width, height ) {
- How come it works when you bypass ResourceLoader? Note that nothing
else has changed recently (including the morebits.js code on that Wiki)
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
- Is it safe to assume that just by listing ext.gadgets.morebits as a
dependency, morebits will be properly loaded by ResourceLoader?
Yes, just be careful about explicitly allowing access to globals by attaching them to `window`.
Excellent answers. Thank you!
Here is a final question: how long does it generally take for a change made in a script to be reflected in the output of RL? Is it in the order of minutes or hours?
On Thu, Aug 20, 2015 at 10:26 AM, Bartosz Dziewoński matma.rex@gmail.com wrote:
On Thu, 20 Aug 2015 04:07:57 +0200, Huji Lee huji.huji@gmail.com wrote:
However, if you don't
bypass ResourceLoader, the "+" links won't work and an error is thrown reading "SimpleWindow is not defined" (try on my talk page without bypassing RL https://fa.wikipedia.org/wiki/User_talk:Huji). Note that SimpleWindow is defined in morebits.js
When you load a script through ResourceLoader, it's not executed in global context. This means that global variables you define are actually *not global* (they are local to the function your code is wrapped in), unless you explicitly assign them as `window` properties.
The code of the gadget in question actually does it right:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var UserMessages = {}; window.UserMessages = UserMessages; // global access
(It would be sufficient to just do `window.UserMessages = {}`, but this is also just as correct.)
morebits doesn't:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var SimpleWindow = function( width, height ) { ...
This should be changed to:
window.SimpleWindow = function( width, height ) {
- How come it works when you bypass ResourceLoader? Note that nothing else
has changed recently (including the morebits.js code on that Wiki)
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
- Is it safe to assume that just by listing ext.gadgets.morebits as a
dependency, morebits will be properly loaded by ResourceLoader?
Yes, just be careful about explicitly allowing access to globals by attaching them to `window`.
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Fri, 21 Aug 2015 04:46:36 +0200, Huji Lee huji.huji@gmail.com wrote:
Here is a final question: how long does it generally take for a change made in a script to be reflected in the output of RL? Is it in the order of minutes or hours?
It should happen within five minutes, or immediately if you clear the browser cache.
I wanted to bring this back up into your attention, hoping that I can get a response.
On Thu, Aug 20, 2015 at 10:46 PM, Huji Lee huji.huji@gmail.com wrote:
Excellent answers. Thank you!
Here is a final question: how long does it generally take for a change made in a script to be reflected in the output of RL? Is it in the order of minutes or hours?
On Thu, Aug 20, 2015 at 10:26 AM, Bartosz Dziewoński matma.rex@gmail.com wrote:
On Thu, 20 Aug 2015 04:07:57 +0200, Huji Lee huji.huji@gmail.com wrote:
However, if you don't
bypass ResourceLoader, the "+" links won't work and an error is thrown reading "SimpleWindow is not defined" (try on my talk page without bypassing RL https://fa.wikipedia.org/wiki/User_talk:Huji). Note that SimpleWindow is defined in morebits.js
When you load a script through ResourceLoader, it's not executed in global context. This means that global variables you define are actually *not global* (they are local to the function your code is wrapped in), unless you explicitly assign them as `window` properties.
The code of the gadget in question actually does it right:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var UserMessages = {}; window.UserMessages = UserMessages; // global access
(It would be sufficient to just do `window.UserMessages = {}`, but this is also just as correct.)
morebits doesn't:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var SimpleWindow = function( width, height ) { ...
This should be changed to:
window.SimpleWindow = function( width, height ) {
- How come it works when you bypass ResourceLoader? Note that nothing
else has changed recently (including the morebits.js code on that Wiki)
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
- Is it safe to assume that just by listing ext.gadgets.morebits as a
dependency, morebits will be properly loaded by ResourceLoader?
Yes, just be careful about explicitly allowing access to globals by attaching them to `window`.
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 28-08-2015 22:30, Huji Lee wrote:
I wanted to bring this back up into your attention, hoping that I can get a response.
On Thu, Aug 20, 2015 at 10:46 PM, Huji Lee huji.huji@gmail.com wrote:
Excellent answers. Thank you!
Here is a final question: how long does it generally take for a change made in a script to be reflected in the output of RL? Is it in the order of minutes or hours?
Minutes, sometimes immediately. In my experience, changes to resources like MediaWiki:Common.css and gadgets take a maximum of 5 minutes to re-cache (while on testwiki it usually takes effect immediately), and user css/scripts take effect immediately.
If I'm not mistaken, this may be configurable...
Regards,
On Fri, 28 Aug 2015 22:30:13 +0200, Huji Lee huji.huji@gmail.com wrote:
I wanted to bring this back up into your attention, hoping that I can get a response.
On Thu, Aug 20, 2015 at 10:46 PM, Huji Lee huji.huji@gmail.com wrote:
Excellent answers. Thank you!
Here is a final question: how long does it generally take for a change made in a script to be reflected in the output of RL? Is it in the order of minutes or hours?
I have replied previously: It should happen within five minutes, or immediately if you clear the browser cache.
https://lists.wikimedia.org/pipermail/wikitech-l/2015-August/082876.html
On Thu, Aug 20, 2015 at 11:26 AM, Bartosz Dziewoński matma.rex@gmail.com wrote:
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
FYI: That is https://phabricator.wikimedia.org/T64605
Helder
On Thu, Aug 20, 2015 at 11:26 AM, Bartosz Dziewoński matma.rex@gmail.com wrote:
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
FYI: That is https://phabricator.wikimedia.org/T64605
Helder
On Thu, Aug 20, 2015 at 7:26 AM, Bartosz Dziewoński matma.rex@gmail.com wrote:
When you load a script through ResourceLoader, it's not executed in global
context. This means that global variables you define are actually *not global* (they are local to the function your code is wrapped in), unless you explicitly assign them as `window` properties.
I added a section on this, "Global variables are not global" to https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide under MediaWiki 1.26, with a pointer to https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Globals where the latter says "Only mediaWiki https://www.mediawiki.org/wiki/RL/DM#MediaWiki and jQuery https://www.mediawiki.org/wiki/RL/DM#jQuery should be used (in addition to the browser's native APIs)."
The latter doesn't suggest creating an object with mediaWiki/mw. I added
You should expose your code's functionality to other clients as functions
and properties of an object within mediaWiki, e.g. mediaWiki.echo, and possibly as documented mw.config configuration variables.
but surely there's a page that talks about this idiom. Are there any gadgets that add an object within mediaWiki ? If we were to rewrite morebits.js from scratch, wouldn't it be better to create mediaWiki.moreBits.{quickForm, simpleWindow, ...} rather than window.MoreBits ?
Cheers,
wikitech-l@lists.wikimedia.org