Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -301,11 +301,11 @@ |
302 | 302 | * Generates a random user session ID (32 alpha-numeric characters). |
303 | 303 | * |
304 | 304 | * This information would potentially be stored in a cookie to identify a user during a |
305 | | - * session. It's uniqueness should not be depended on. |
| 305 | + * session or series of sessions. It's uniqueness should not be depended on. |
306 | 306 | * |
307 | 307 | * @return string random set of 32 alpha-numeric characters |
308 | 308 | */ |
309 | | - function generateSessionId() { |
| 309 | + function generateId() { |
310 | 310 | var id = ''; |
311 | 311 | var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; |
312 | 312 | for ( var i = 0, r; i < 32; i++ ) { |
— | — | @@ -325,27 +325,52 @@ |
326 | 326 | }; |
327 | 327 | |
328 | 328 | /* |
329 | | - * Gets the current user's name or a random session ID automatically generated and kept in |
330 | | - * a cookie. |
| 329 | + * Gets a random session ID automatically generated and kept in a cookie. |
331 | 330 | * |
| 331 | + * This ID is ephemeral for everyone, staying in their browser only until they close |
| 332 | + * their browser. |
| 333 | + * |
332 | 334 | * Do not use this method before the first call to mediaWiki.loader.go(), it depends on |
333 | | - * jquery.cookie, which is added to the first payload just after mediaWiki is defined, but |
| 335 | + * jquery.cookie, which is added to the first pay-load just after mediaWiki is defined, but |
334 | 336 | * won't be loaded until the first call to go(). |
335 | 337 | * |
336 | 338 | * @return string user name or random session ID |
337 | 339 | */ |
338 | 340 | this.sessionId = function () { |
| 341 | + var sessionId = $.cookie( 'mediaWiki.user.sessionId' ); |
| 342 | + if ( typeof sessionId == 'undefined' || sessionId == null ) { |
| 343 | + sessionId = generateId(); |
| 344 | + } |
| 345 | + // Set cookie if not set, or renew it if already set |
| 346 | + $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': null, 'path': '/' } ); |
| 347 | + return sessionId; |
| 348 | + }; |
| 349 | + |
| 350 | + /* |
| 351 | + * Gets the current user's name or a random ID automatically generated and kept in a cookie. |
| 352 | + * |
| 353 | + * This ID is persistent for anonymous users, staying in their browser up to 1 year. The |
| 354 | + * expiration time is reset each time the ID is queried, so in most cases this ID will |
| 355 | + * persist until the browser's cookies are cleared or the user doesn't visit for 1 year. |
| 356 | + * |
| 357 | + * Do not use this method before the first call to mediaWiki.loader.go(), it depends on |
| 358 | + * jquery.cookie, which is added to the first pay-load just after mediaWiki is defined, but |
| 359 | + * won't be loaded until the first call to go(). |
| 360 | + * |
| 361 | + * @return string user name or random session ID |
| 362 | + */ |
| 363 | + this.id = function() { |
339 | 364 | var name = that.name(); |
340 | 365 | if ( name ) { |
341 | 366 | return name; |
342 | 367 | } |
343 | | - var sessionId = $.cookie( 'mediaWiki.user.sessionId' ); |
344 | | - if ( typeof sessionId == 'undefined' || sessionId == null ) { |
345 | | - sessionId = generateSessionId(); |
| 368 | + var id = $.cookie( 'mediaWiki.user.id' ); |
| 369 | + if ( typeof id == 'undefined' || id == null ) { |
| 370 | + id = generateId(); |
346 | 371 | } |
347 | 372 | // Set cookie if not set, or renew it if already set |
348 | | - $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': 30, 'path': '/' } ); |
349 | | - return sessionId; |
| 373 | + $.cookie( 'mediaWiki.user.id', id, { 'expires': 365, 'path': '/' } ); |
| 374 | + return id; |
350 | 375 | }; |
351 | 376 | } |
352 | 377 | |