Topic on Project:Support desk

[RESOLVED] mw.config.get

3
Kanegasi (talkcontribs)

I have a bit of trouble understanding Manual:Interface/JavaScript#mw.config.

I'm relatively new to JavaScript. I've been revamping an edit counter script for the past two-three months that uses the API and posts a table to a page. These few months are my only JavaScript experience and I think I'm doing great learning by myself (with Internet help, of course). The old script was very specific to certain wiki elements and required tinkering to get it to work on another wiki using different install options, such as no $wgScriptPath set on the wiki I was trying to use it on and the first wiki had /w/ hardcoded into the ajax calls. I have gotten to the point where the script is smart enough to work as-is on practically any MediaWiki install, but of course, I don't have the means to test it like that, so I'm still learning as I go.

Anyways, my question, or request for clarification, is about using mw.config.get vice just using the wg variable directly. If I understand the page I linked correctly, I do not have to use mw.config.get if $wgLegacyJavaScript is true, correct? I noticed other scripts I have seen plop wgServer and wgScriptPath straight into an ajax call without using mw.config.get and my current revision of my script uses a few other wg variables and it works without having to use mw.config.get anywhere, but if $wgLegacyJavaScript is set to false on some wiki where someone uses my script, will my script not work?

If you want to browse my script, it is at wikipedia:User:Kanegasi/editcounter.js. If you're wondering why the revision history of that page is short, the original location I was working at was minecraftwiki.net and the full page history of my successes and failures can be seen here.

Ciencia Al Poder (talkcontribs)

You should use mw.config.get always, it will work whether $wgLegacyJavaScript is set to true or false. As that variable name suggests, accessing wg variables directly is legacy and support for this may be dropped eventually.

Kanegasi (talkcontribs)

I used to use just one mw.config.get for each variable and store that into another variable, instead of repeating mw.config.get several times. I'll have to go back to that then. Thank you for the clarification.

Reply to "[RESOLVED] mw.config.get"