+
+ /**
+ * Message object, similar to Message in PHP
+ */
+ function Message( map, key, parameters ) {
+ this.format = 'parse';
+ this.map = map;
+ this.key = key;
+ this.parameters = typeof parameters === 'undefined' ? [] : $.makeArray( parameters );
+ }
+
+ /**
+ * Appends parameters for replacement
+ *
+ * @param parameters mixed First in a list of variadic arguments to append as message parameters
+ */
+ Message.prototype.params = function( parameters ) {
+ for ( var i = 0; i < parameters.length; i++ ) {
+ this.parameters[this.parameters.length] = parameters[i];
+ }
+ return this;
+ };
+
+ /**
+ * Converts message object to it's string form based on the state of format
+ *
+ * @return {string} String form of message
+ */
+ Message.prototype.toString = function() {
+ if ( !this.map.exists( this.key ) ) {
+ // Return <key> if key does not exist
+ return '<' + this.key + '>';
+ }
+ var text = this.map.get( this.key );
+ var parameters = this.parameters;
+ text = text.replace( /\$(\d+)/g, function( string, match ) {
+ var index = parseInt( match, 10 ) - 1;
+ return index in parameters ? parameters[index] : '$' + match;
+ } );
+ /* This should be fixed up when we have a parser
+ if ( this.format === 'parse' && 'language' in mediaWiki ) {
+ text = mediaWiki.language.parse( text );
+ }
+ */
+ return text;
+ };
+
+ /**
+ * Changes format to parse and converts message to string
+ *
+ * @return {string} String form of parsed message
+ */
+ Message.prototype.parse = function() {
+ this.format = 'parse';
+ return this.toString();
+ };
+
+ /**
+ * Changes format to plain and converts message to string
+ *
+ * @return {string} String form of plain message
+ */
+ Message.prototype.plain = function() {
+ this.format = 'plain';
+ return this.toString();
+ };
+
+ /**
+ * Checks if message exists
+ *
+ * @return {string} String form of parsed message
+ */
+ Message.prototype.exists = function() {
+ return this.map.exists( this.key );
+ };
+
+ /**
+ * 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 */
+