r83037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83036‎ | r83037 | r83038 >
Date:19:23, 1 March 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: Merge revs to mediawiki.js required by ArticleFeedback: r78104, r78344, r78347, r78350, r78365, r78539, r78886
Modified paths:
  • /branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js
@@ -225,7 +225,91 @@
226226 * User object
227227 */
228228 function User() {
 229+
 230+ /* Private Members */
 231+
 232+ var that = this;
 233+
 234+ /* Public Members */
 235+
229236 this.options = new Map();
 237+
 238+ /* Public Methods */
 239+
 240+ /*
 241+ * Generates a random user session ID (32 alpha-numeric characters).
 242+ *
 243+ * This information would potentially be stored in a cookie to identify a user during a
 244+ * session or series of sessions. It's uniqueness should not be depended on.
 245+ *
 246+ * @return string random set of 32 alpha-numeric characters
 247+ */
 248+ function generateId() {
 249+ var id = '';
 250+ var seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
 251+ for ( var i = 0, r; i < 32; i++ ) {
 252+ r = Math.floor( Math.random() * seed.length );
 253+ id += seed.substring( r, r + 1 );
 254+ }
 255+ return id;
 256+ }
 257+
 258+ /*
 259+ * Gets the current user's name.
 260+ *
 261+ * @return mixed user name string or null if users is anonymous
 262+ */
 263+ this.name = function() {
 264+ return mediaWiki.config.get( 'wgUserName' );
 265+ };
 266+
 267+ /*
 268+ * Gets a random session ID automatically generated and kept in a cookie.
 269+ *
 270+ * This ID is ephemeral for everyone, staying in their browser only until they close
 271+ * their browser.
 272+ *
 273+ * Do not use this method before the first call to mediaWiki.loader.go(), it depends on
 274+ * jquery.cookie, which is added to the first pay-load just after mediaWiki is defined, but
 275+ * won't be loaded until the first call to go().
 276+ *
 277+ * @return string user name or random session ID
 278+ */
 279+ this.sessionId = function () {
 280+ var sessionId = $.cookie( 'mediaWiki.user.sessionId' );
 281+ if ( typeof sessionId == 'undefined' || sessionId == null ) {
 282+ sessionId = generateId();
 283+ $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': null, 'path': '/' } );
 284+ }
 285+ return sessionId;
 286+ };
 287+
 288+ /*
 289+ * Gets the current user's name or a random ID automatically generated and kept in a cookie.
 290+ *
 291+ * This ID is persistent for anonymous users, staying in their browser up to 1 year. The
 292+ * expiration time is reset each time the ID is queried, so in most cases this ID will
 293+ * persist until the browser's cookies are cleared or the user doesn't visit for 1 year.
 294+ *
 295+ * Do not use this method before the first call to mediaWiki.loader.go(), it depends on
 296+ * jquery.cookie, which is added to the first pay-load just after mediaWiki is defined, but
 297+ * won't be loaded until the first call to go().
 298+ *
 299+ * @return string user name or random session ID
 300+ */
 301+ this.id = function() {
 302+ var name = that.name();
 303+ if ( name ) {
 304+ return name;
 305+ }
 306+ var id = $.cookie( 'mediaWiki.user.id' );
 307+ if ( typeof id == 'undefined' || id == null ) {
 308+ id = generateId();
 309+ }
 310+ // Set cookie if not set, or renew it if already set
 311+ $.cookie( 'mediaWiki.user.id', id, { 'expires': 365, 'path': '/' } );
 312+ return id;
 313+ };
230314 }
231315
232316 /* Public Members */
@@ -1022,6 +1106,9 @@
10231107 delete startUp;
10241108 }
10251109
 1110+// Add jQuery Cookie to initial payload (used in mediaWiki.user)
 1111+mediaWiki.loader.load( 'jquery.cookie' );
 1112+
10261113 // Alias $j to jQuery for backwards compatibility
10271114 window.$j = jQuery;
10281115 window.mw = mediaWiki;
Property changes on: branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js
___________________________________________________________________
Modified: svn:mergeinfo
10291116 Merged /trunk/phase3/resources/mediawiki/mediawiki.js:r78104,78344,78347,78350,78365,78539,78886

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78104Added name and sessionId methods to user object - now anonymous users have an...tparscal23:18, 8 December 2010
r78344Fixed issue in r78104 where jquery.cookie wouldn't load properly. Changed the...tparscal23:51, 13 December 2010
r78347Fixes r78104 much better than r78344 did. By adding jquery.cookie to the load...tparscal00:02, 14 December 2010
r78350Added comment about why you should not be depending on mediaWiki.user.session...tparscal00:08, 14 December 2010
r78365Followup r78104: set the cookie unconditionally, so its expiry is renewed eve...catrope11:09, 14 December 2010
r78539Split the functionality of mediaWiki.user.sessionId into id and sessionId - t...tparscal18:32, 17 December 2010
r78886Followup r78539: don't renew a cookie that expires at the end of the session ...catrope14:07, 23 December 2010

Status & tagging log