*/
function Map( global ) {
this.values = ( global === true ) ? window : {};
- };
+ }
/**
* Gets the value of a key, or a list of key/value pairs for an array of keys.
this.map = map;
this.key = key;
this.parameters = typeof parameters === 'undefined' ? [] : $.makeArray( parameters );
- };
+ }
/**
* Appends parameters for replacement
* User object
*/
function User() {
+
+ /* Private Members */
+
+ var that = this;
+
+ /* Public Members */
+
this.options = new Map();
+
+ /* Public Methods */
+
+ /*
+ * Generates a random user session ID (32 alpha-numeric characters).
+ *
+ * This information would potentially be stored in a cookie to identify a user during a
+ * session. It's uniqueness should not be depended on.
+ *
+ * @return string random set of 32 alpha-numeric characters
+ */
+ function generateSessionId() {
+ var id = '';
+ var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
+ for ( var i = 0, r; i < 32; i++ ) {
+ r = Math.floor( Math.random() * seed.length );
+ id += seed.substring( r, r + 1 );
+ }
+ return id;
+ }
+
+ /*
+ * Gets the current user's name.
+ *
+ * @return mixed user name string or null if users is anonymous
+ */
+ this.name = function() {
+ return mediaWiki.config.get( 'wgUserName' );
+ };
+
+ /*
+ * Gets the current user's name or a random session ID automatically generated and kept in
+ * a cookie.
+ *
+ * @return string user name or random session ID
+ */
+ this.sessionId = function () {
+ var name = that.name();
+ if ( name ) {
+ return name;
+ }
+ var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
+ if ( typeof sessionId == 'undefined' || sessionId == null ) {
+ sessionId = generateSessionId();
+ $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': 30, 'path': '/' } );
+ }
+ return sessionId;
+ };
}
/* Public Members */
/**
* Gets a message string, similar to wfMsg()
*
- * @param {string} key Key of message to get
- * @param {mixed} params First argument in a list of variadic arguments, each a parameter for $
+ * @param key string Key of message to get
+ * @param parameters mixed First argument in a list of variadic arguments, each a parameter for $
* replacement
*/
this.msg = function( key, parameters ) {
}
}
return true;
- };
+ }
/**
* Generates an ISO8601 "basic" string from a UNIX timestamp
function pad( a, b, c ) {
return [a < 10 ? '0' + a : a, b < 10 ? '0' + b : b, c < 10 ? '0' + c : c].join( '' );
}
- var d = new Date()
+ var d = new Date();
d.setTime( timestamp * 1000 );
return [
pad( d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate() ), 'T',
/**
* Gets a list of module names that a module depends on in their proper dependency order
*
- * @param mixed string module name or array of string module names
+ * @param module string module name or array of string module names
* @return list of dependencies
* @throws Error if circular reference is detected
*/
return resolved;
}
throw new Error( 'Invalid module argument: ' + module );
- };
+ }
/**
* Narrows a list of module names down to those matching a specific
* state. Possible states are 'undefined', 'registered', 'loading',
* 'loaded', or 'ready'
*
- * @param mixed string or array of strings of module states to filter by
- * @param array list of module names to filter (optional, all modules
+ * @param states string or array of strings of module states to filter by
+ * @param modules array list of module names to filter (optional, all modules
* will be used by default)
* @return array list of filtered module names
*/
/**
* Executes a loaded module, making it ready to use
*
- * @param string module name to execute
+ * @param module string module name to execute
*/
function execute( module ) {
if ( typeof registry[module] === 'undefined' ) {
* Adds a dependencies to the queue with optional callbacks to be run
* when the dependencies are ready or fail
*
- * @param mixed string moulde name or array of string module names
- * @param function ready callback to execute when all dependencies are ready
- * @param function error callback to execute when any dependency fails
+ * @param dependencies string module name or array of string module names
+ * @param ready function callback to execute when all dependencies are ready
+ * @param error function callback to execute when any dependency fails
*/
function request( dependencies, ready, error ) {
// Allow calling by single module name
/**
* Executes a function as soon as one or more required modules are ready
*
- * @param mixed string or array of strings of modules names the callback
+ * @param dependencies string or array of strings of modules names the callback
* dependencies to be ready before
* executing
- * @param function callback to execute when all dependencies are ready (optional)
- * @param function callback to execute when if dependencies have a errors (optional)
+ * @param ready function callback to execute when all dependencies are ready (optional)
+ * @param error function callback to execute when if dependencies have a errors (optional)
*/
this.using = function( dependencies, ready, error ) {
// Validate input
/**
* Loads an external script or one or more modules for future use
*
- * @param {mixed} modules either the name of a module, array of modules,
+ * @param modules mixed either the name of a module, array of modules,
* or a URL of an external script or style
- * @param {string} type mime-type to use if calling with a URL of an
+ * @param type string mime-type to use if calling with a URL of an
* external script or style; acceptable values are "text/css" and
* "text/javascript"; if no type is provided, text/javascript is
* assumed
/**
* Changes the state of a module
*
- * @param mixed module string module name or object of module name/state pairs
- * @param string state string state name
+ * @param module string module name or object of module name/state pairs
+ * @param state string state name
*/
this.state = function( module, state ) {
if ( typeof module === 'object' ) {
/**
* Gets the version of a module
*
- * @param string module name of module to get version for
+ * @param module string name of module to get version for
*/
this.version = function( module ) {
if ( module in registry && 'version' in registry[module] ) {
return formatVersionNumber( registry[module].version );
}
return null;
- }
+ };
/* Cache document ready status */
*/
this.Cdata = function( value ) {
this.value = value;
- }
+ };
/**
* Create an HTML element string, with safe escaping.