Merge "Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.user.js
index 04d9ec6..c42eb9a 100644 (file)
@@ -3,13 +3,9 @@
  * @singleton
  */
 ( function ( mw, $ ) {
-       var user, i,
+       var i,
                deferreds = {},
-               byteToHex = [],
-               // Extend the skeleton mw.user from mediawiki.js
-               // This is kind of ugly but we're stuck with this for b/c reasons
-               options = mw.user.options || new mw.Map(),
-               tokens = mw.user.tokens || new mw.Map();
+               byteToHex = [];
 
        /**
         * Get the current user's groups or rights
@@ -51,9 +47,8 @@
                byteToHex[i] = ( i + 256 ).toString( 16 ).slice( 1 );
        }
 
-       mw.user = user = {
-               options: options,
-               tokens: tokens,
+       // mw.user with the properties options and tokens gets defined in mediawiki.js.
+       $.extend( mw.user, {
 
                /**
                 * Generate a random user session ID.
@@ -83,7 +78,7 @@
                                crypto = window.crypto || window.msCrypto;
 
                        // Based on https://github.com/broofa/node-uuid/blob/bfd9f96127/uuid.js
-                       if ( crypto ) {
+                       if ( crypto && crypto.getRandomValues ) {
                                // Fill an array with 8 random values, each of which is 8 bits.
                                // Note that Uint8Array is array-like but does not implement Array.
                                rnds = new Uint8Array( 8 );
                 */
                getRegistration: function () {
                        var registration = mw.config.get( 'wgUserRegistration' );
-                       if ( user.isAnon() ) {
+                       if ( mw.user.isAnon() ) {
                                return false;
                        }
                        if ( registration === null ) {
                 * @return {boolean}
                 */
                isAnon: function () {
-                       return user.getName() === null;
+                       return mw.user.getName() === null;
                },
 
                /**
                 * @return {string} Random session ID
                 */
                sessionId: function () {
-                       var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
-                       if ( sessionId === undefined || sessionId === null ) {
-                               sessionId = user.generateRandomSessionId();
-                               $.cookie( 'mediaWiki.user.sessionId', sessionId, { expires: null, path: '/' } );
+                       var sessionId = mw.cookie.get( 'mwuser-session' );
+                       if ( sessionId === null ) {
+                               sessionId = mw.user.generateRandomSessionId();
+                               mw.cookie.set( 'mwuser-session', sessionId, { expires: null } );
                        }
                        return sessionId;
                },
                 * @return {string} User name or random session ID
                 */
                id: function () {
-                       return user.getName() || user.sessionId();
+                       return mw.user.getName() || mw.user.sessionId();
                },
 
                /**
                                expires: 30
                        }, options || {} );
 
-                       cookie = $.cookie( 'mediaWiki.user.bucket:' + key );
+                       cookie = mw.cookie.get( 'mwuser-bucket:' + key );
 
                        // Bucket information is stored as 2 integers, together as version:bucket like: "1:2"
                        if ( typeof cookie === 'string' && cookie.length > 2 && cookie.indexOf( ':' ) !== -1 ) {
                                        }
                                }
 
-                               $.cookie(
-                                       'mediaWiki.user.bucket:' + key,
+                               mw.cookie.set(
+                                       'mwuser-bucket:' + key,
                                        version + ':' + bucket,
-                                       { path: '/', expires: Number( options.expires ) }
+                                       { expires: Number( options.expires ) * 86400 }
                                );
                        }
 
                getRights: function ( callback ) {
                        return getUserInfo( 'rights' ).done( callback );
                }
-       };
+       } );
 
 }( mediaWiki, jQuery ) );