r78539 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78538‎ | r78539 | r78540 >
Date:18:32, 17 December 2010
Author:tparscal
Status:ok
Tags:
Comment:
Split the functionality of mediaWiki.user.sessionId into id and sessionId - the first of which is as persistent as possible, and the latter of which will change every time the browser is closed.
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -301,11 +301,11 @@
302302 * Generates a random user session ID (32 alpha-numeric characters).
303303 *
304304 * 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.
306306 *
307307 * @return string random set of 32 alpha-numeric characters
308308 */
309 - function generateSessionId() {
 309+ function generateId() {
310310 var id = '';
311311 var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
312312 for ( var i = 0, r; i < 32; i++ ) {
@@ -325,27 +325,52 @@
326326 };
327327
328328 /*
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.
331330 *
 331+ * This ID is ephemeral for everyone, staying in their browser only until they close
 332+ * their browser.
 333+ *
332334 * 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
334336 * won't be loaded until the first call to go().
335337 *
336338 * @return string user name or random session ID
337339 */
338340 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() {
339364 var name = that.name();
340365 if ( name ) {
341366 return name;
342367 }
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();
346371 }
347372 // 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;
350375 };
351376 }
352377

Follow-up revisions

RevisionCommit summaryAuthorDate
r78886Followup r78539: don't renew a cookie that expires at the end of the session ...catrope14:07, 23 December 2010
r830371.17wmf1: Merge revs to mediawiki.js required by ArticleFeedback: r78104, r78...catrope19:23, 1 March 2011
r85080MFT r78108, r78179, r78344, r78347, r78350, r78365, r78380, r78425, r78539, r...demon19:09, 31 March 2011

Status & tagging log