Manual talk:Interface/JavaScript


 * Would you please tell me how do I install the Commons.js file into the MediaWiki? Where do I put this file? How do I activate it? Thank you in advance.
 * Write it in your wiki page titled [[MediaWiki:Common.js]]. --almaghi 17:03, 22 July 2009 (UTC)

It's sometimes useful to start your Common.js with "// " and end it with "// " -- Sidcom 23:01, 22 February 2010 (UTC)
 * why is that? --12.46.139.200 17:23, 22 August 2011 (UTC)
 * Because some wikitext still gets parsed in your script file such as --~ . See topic below because I assume this is a bug. --Sebschlicht (talk) 20:51, 28 August 2014 (UTC)

Not working in 1.16.2?
Moved to Project:Support desk; further questions should go there. PleaseStand (talk) 04:24, 16 March 2012 (UTC)

Saving of JS/CSS files
If one edits a JS file and presses the save button, you will get redirected to the "Read"-view. This should not be the default behaviour for a JS file. This also applies to CSS files. Neither does one need a preview of the file itself, but of a wiki page using it. If the save button is clicked, one should stay at the page to do the next edit. Maybe I am missing a point, but at the moment I can't think of any setting where you would want to read the JS/CSS file after an edit. Does someone has an example I there are such settings? --Sebschlicht (talk) 20:51, 28 August 2014 (UTC)


 * Following your same argumentation, when you edit a CSS/JS page and you hit save, you want the CSS/JS applied to the page, so you want to see a page (the one you just edited for example), and not stay on the same edit screen. Staying on the same edit screen will also be confusing, since you won't be certain if the edit was saved or it was rejected without an error. --Ciencia Al Poder (talk) 09:28, 29 August 2014 (UTC)


 * When you edit a CSS/JS page and want to see a preview, you could enter the title of a page you want to see - with the new code applied. This functionality exists in the Lua editor, for example. You are right, one still needs to have feedback if you choose to save rather than to see a preview.
 * If the described preview functionality would exist for CSS/JS files you could always hit the preview button until you are satisfied. This not possible at the moment. --Sebschlicht (talk) 12:08, 25 September 2014 (UTC)

Wikitext parsing
If your JS file includes strings containing wikitext language such as --~ it will get parsed and replaced as expected on wiki pages. This should not be the default behaviour in a JS file.

You can use //    /* JS goes here */ //

to overcome this issue. --Sebschlicht (talk) 20:51, 28 August 2014 (UTC)

Why database name is exposed via JS ?
Considering page contents everyone can read database name used by site via mw.config.get('wgDBname'). This seems like security issue.
 * Why would it be? They still need to 1) contact the DB (shared database?), 2) know the DB username, 3) know the password. The DB name is not supposed to be sensitive. As for why it's public, the reason is that it's often a handy identifier for the website, e.g. "mediawikiwiki" is this wiki and not another wiki. Nemo 22:26, 3 January 2016 (UTC)