ResourceLoader/Core modules

Shortcut: RL/DM

This page intends to list, document, explain and give examples for all the libraries, plugins and scripts present in MediaWiki's resources by default. = jQuery & plugins = jQuery 1.4.2 is loaded. For more information about jQuery in general and all it's core functions, refer to http://api.jquery.com/

jQuery UI
jQuery UI 1.8.2: http://jqueryui.com/demos/ The following components are included:
 * jquery.ui.accordion.js
 * jquery.ui.autocomplete.js
 * jquery.ui.button.js
 * jquery.ui.core.js
 * jquery.ui.datepicker.js
 * jquery.ui.dialog.js
 * jquery.ui.draggable.js
 * jquery.ui.droppable.js
 * jquery.ui.mouse.js
 * jquery.ui.position.js
 * jquery.ui.progressbar.js
 * jquery.ui.resizable.js
 * jquery.ui.selectable.js
 * jquery.ui.slider.js
 * jquery.ui.sortable.js
 * jquery.ui.tabs.js
 * jquery.ui.widget.js
 * i18n

jQuery.checkboxShiftClick
This single-function plugin can be called to add this functionality to any number of checkboxes. By default (onload) it's applied to all  elements that have a type of checkbox, excluding any with a class of 'noshiftselect'. As it has a built-in prevention to avoid binding the CheckboxShiftClick twice to the same element you can simply run the line below under "Default" again at any time if you want to enable dynamically added checkboxes in the page to be shift-selectable as well. Or alternatively run it on the specific selector of choise (see second example below).

jQuery.client
A plugin that extract information about the client's browser, layout engine and operating system.

Profile
The profile function is the main function here and returns (and caches) all the information in an object in. All possible values (except for version numbers) are predefined. A typical return looks like this:

Here a few examples Check jquery.client.js for possible values of browser names, layout engines and platforms.

Test
TODO

jQuery.makeCollapsible
Plugin makes all passed elements collapsible. It supports lots of variations such as:
 * Simple: Add " " to a with some content and save the page. The inner content of this  will be detected as collapsible content and a toggle-link will be added with a localized label (collapsible-expand, collapsible-collapse)
 * Initial state: Adding " " as extra class will cause the element to be initially collapsed when the page is loaded.
 * Custom label:HTML5 only Using the data-collapsetext and data-expandtext attributes one can define a custom text for the toggle labels added by the script. When added in wikitext these could populated by a localized message like:

Example: Hide the collapsible element by default, the toggle element resides outside of it
 * Remote toggle: If you don't want the script to put the default toggle link (wether or not with a custom label) in your element, you can make one of your own. This could reside anywhere inside or outside the collapsible element. It's relationship to the collapsible element is detected by using the prefix  and   for the collapsible element and the togglelink respectively.

For live examples, see TranslateWiki - Collapsing Testpage

jQuery.placeholder
This plugin adds support for placeholder texts in input fields for browsers that don't support the HTML5 attribute yet. If the attribute is not supported it's applied to all input elements with a 'placeholder' attribute, on-load.

It has a built-in check for browser support, but for effeciency it's best to do this check (also) wrapped around to call.

jQuery Prototyping
There are several prototypes for older browsers serving as backwards-compatibility for new native prototypes in newer browser. Also several other convenience functions have been added.
 * trimLeft: Trims whitespace from the left side of the string
 * trimRight: Trims whitespace from the right of the string
 * trim: Trims whitespace from the both ends of the string
 * ucFirst: Returns the string with the first character capitalized
 * escapeRE: Returns a string for literal use in a regular expressions by escaping characters that have a special meaning in a regex.
 * isEmpty: This function checks if a variable is empty. Supports strings, booleans, arrays and objects. The string "0" is considered empty. A string containing only whitespace (ie. " ") is considered not empty.
 * compareArray: Compares two arrays and returns a boolean for whether they are in fact the same
 * compareObject: Compares two objects for it's properties and values (recursive)

= MediaWiki =

mediaWiki.config
An instance of the Map class that is global by default for backwards compatibility and contains the wgVars such as wgSiteName, wgArticleId etc.

mediaWiki.html

 * mediaWiki.html.escape: Escape a string for HTML. Converts special characters to HTML entities.
 * mediaWiki.html.element: Create an HTML element string, with safe escaping.

mediaWiki.loader

 * mediaWiki.loader.go
 * mediaWiki.loader.implement
 * mediaWiki.loader.load can be called with an external script or style URI beginning with either "http://" or "https://" and a mime-type, either "text/css" or "text/javascript". If no mime-type is provided, "text/javascript" is assumed.


 * mediaWiki.loader.register
 * mediaWiki.loader.state</tt>
 * mediaWiki.loader.using</tt>
 * mediaWiki.loader.version</tt>
 * mediaWiki.loader.work</tt>

mediaWiki.Map
A reuable class to store, get and set a set of variables. The core uses this for  and

When making an instance the function takes one parameter which affects whether the set will be made globally available (ie. as items of ) or local. By default this is false (not global) and will thus not not overwrite any global variables with the same name.


 * .values</tt>: An object containing the variables. If global = true, this is an alias to the  object.
 * .exists</tt>: Function returns true if an entry with the key(s) exists, false otherwise
 * .get</tt>: Returns the value of the key(s) or (optionally) the value of the second argument if the key does not exist (returns null if it doesn't exist and no fallback was provided)
 * .set</tt>: Creates or alters one or multiple values

Examples

Address Book example

anonymous
Function returns boolean on whether the user is anonymous (true) or logged in (false).

name
Function returns the username or 'null' if logged out.

options
Contains the preferences of the user, or the defaults when logged out. (Instance of the Map class)

sessionId
When called for the first time generates a sessionId and sets a domain-wide cookie and returns the sessionId. When it's set already (ie. after calling it, or when it was set earlier this session on another page) returns just the sessionId.

mediaWiki.log
This script is loaded in debug-mode and is an alternative to calling console.log which would cause errors in browsers that dont have a console or dont have it enabled.

mediaWiki.log
Calling this either pushes the messages to console (if available) or adds it to an #mw-log-console (the element is created on the first call)

addCSS
Adds a  element to the HEAD and returns the CSSStyleSheet object.

The CSSStyleSheet object can be used to disable the css rules at any later time and re-enable them as well. This can be done through the 'disabled' attribute. When setting this to true, the rules no longer apply. When setting to false, the rules apply again.

See also W3 on CSSStyleSheet for more info.

addPortletLink
This function is ported from the legacy wikibits keeping it fully backwards compatible, with a few adjustments that support all core skins and with added support for a CSS-selector as.

$content
A jQuery object for a page's content body regardless of the skin used. This is, for example, #bodyContent in the Vector-skin.

Here is a more advanced example involving loading in extra content with an AJAX request. Run this example on a page other than the main page.

getParamValue
This function returns the value of the specified URL parameter. By default it uses the current window's address. Optionally can be passed a custom location.

It returns  if is not present. Returns an empty string if it was an empty parameter (such as

jsMessage
This function is ported from the legacy wikibits keeping it fully backwards compatible, with a few adjustments and with added support to hide the message by calling with no arguments or when passing null.

rawurlencode
This function returns an encoded string in its raw form for use in urls.

wikiUrlencode
This function returns an article/page name in its encoded form.

wikiGetlink
This function returns the full website address of a local wiki page.