User:Pathoschild/Scripts/MooTools

From Meta, a Wikimedia project coordination wiki

This script became obsolete when MediaWiki enabled jQuery by default.


WikiMooTools is an implementation of MooTools extended with wiki-specific functions. MooTools is a compact object-oriented JavaScript framework that simplifies cross-browser scripting.

Library functions[edit]

MooTools modules[edit]

This implementation includes the MooTools 1.2.4 modules that are most useful for wikis. Click the linked module names for their documentation.

Get edit token (wmt_token)[edit]

Retrieves an edit token for the given session and wiki (required to perform database changes like editing, deletion, protection, emailing, etc). The same token can be reused throughout the session for any task requiring a token, and is valid for both the API and MediaWiki web interface.

syntax
wmt_token(object)
parameters

An object with any of the following properties:

  • onSuccess (function): a function to call on successful completion, passed a string containing the edit token. If omitted, a message is output to the JavaScript console.
  • onFailure (function): a function to call if an error occurs, passed the XmlHttpRequest object. If omitted, a message is output to the JavaScript console.
return value null.
example
wmt_token({
	onSuccess:cTokenSuccess,
	onFailure:cTokenFailure
});
function cTokenSuccess(token) {
	alert('The token is ' + token);
}
function cTokenFailure(xhr) {
	alert('An error occured: ' + xhr.status + ' ' + xhr.statusText);
}

Miscellaneous tasks[edit]

Create loading indicator (wmt_loader)[edit]

Returns a customizable loading indicator (default appearance: Loading...).

syntax
wmt_loader(object)
parameters

An object with any of the following optional properties:

  • img (string): the full URL to the image to use (defaults to commons:image:Loader3.gif).
  • txt (string): text to display right of the image (defaults to "Loading...").
  • container (element): loader container (defaults to new <span> element).
return value An element containing the loader.
example
$('bodyContent').adopt(wmt_loader());

Get list of titles matching prefix (wmt_prefixindex)[edit]

Retrieves a list of titles matching the given prefix in the given namespace, optionally restricted to the current title's subpages.

syntax
wmt_prefixindex(object)
parameters

An object with any of the following optional properties:

  • title (string): the prefix to list pages for (defaults to current title).
  • namespace (int): A namespace number (defaults to current namespace).
  • subpagesOnly (boolean): only list subpages like "title/foo", else list any pages including "title_other" (defaults to false).
  • onSuccess (function): a function to call on successful completion, passed a string containing the edit token. If omitted, a message is output to the JavaScript console.
  • onFailure (function): a function to call if an error occurs, passed the XmlHttpRequest object. If omitted, a message is output to the JavaScript console.
  • passOn (arbitrary): value will be passed on as a second parameter to the onSuccess or onFailure callback.
return value null.
example
wmt_prefixindex({
	title:'Pathoschild',
	namespace:2, // 2=user
	subpagesOnly:true,
	onSuccess:cTokenSuccess,
	onFailure:cTokenFailure
});
function cTokenSuccess(pages) {
	alert('User:Pathoschild has ' + pages.length + ' subpages.');
}
function cTokenFailure(xhr) {
	alert('An error occured: ' + xhr.status + ' ' + xhr.statusText);
}

Installation[edit]

This is still in early development, and not ready for general use.

See also[edit]