MediaWiki/js: Difference between revisions

From Freephile Wiki
Adds example of common.js in the MediaWiki namespace
 
m Add image
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[File:Screenshot qunit.png|thumb|479x479px]]
The first thing to know about [[MediaWiki]] and [[JavaScript]] is that the site administrator can customize the wiki installation by simply modifying the article [[MediaWiki:Common.js]]
The first thing to know about [[MediaWiki]] and [[JavaScript]] is that the site administrator can customize the wiki installation by simply modifying the article [[MediaWiki:Common.js]]


For instance, if you put the JavaScript code for WikEd in there, it will make the WikEd editor available to all users of the local wiki.
For instance, if you put the [[JavaScript|JavaScript]] code for [[wp:User:Cacycle/wikEd | wikEd]] in there, it will make the WikEd editor available to all users of the local wiki.
[[Category:Wiki]]
 
== Debugging JavaScript ==
<ol>
<li> Access the developer tools of your browser
<ul>
<li>Chrome  <code>CTRL + SHIFT + J</code>
<li>Firefox <code>CTRL + SHIFT + I</code>
</ul>
<li>Go to the console tab (look for errors)
<li>append <code>?debug=true</code> to the URL and reload the page.  This will give you non-minified JavaScript.
</ol>
 
== JavaScript Unit Testing ==
MediaWiki uses the QUnit test framework for [https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing JavaScript Unit testing].
 
Set <code>$wgEnableJavaScriptTest</code> to <code>'''true'''</code>  and visit [[Special:JavaScriptTest]] to see the test output.
[[Category:JavaScript]]

Latest revision as of 19:25, 28 October 2025

The first thing to know about MediaWiki and JavaScript is that the site administrator can customize the wiki installation by simply modifying the article MediaWiki:Common.js

For instance, if you put the JavaScript code for wikEd in there, it will make the WikEd editor available to all users of the local wiki.

Debugging JavaScript[edit]

  1. Access the developer tools of your browser
    • Chrome CTRL + SHIFT + J
    • Firefox CTRL + SHIFT + I
  2. Go to the console tab (look for errors)
  3. append ?debug=true to the URL and reload the page. This will give you non-minified JavaScript.

JavaScript Unit Testing[edit]

MediaWiki uses the QUnit test framework for JavaScript Unit testing.

Set $wgEnableJavaScriptTest to true and visit Special:JavaScriptTest to see the test output.