2016-04-28 10:18:52 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-09-01 11:17:47 +00:00
|
|
|
/* global moment:false */
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} data - Containing keys `id`, `size`, `comment`, `parsedcomment`, `timestamp`, `user` and `minor`
|
|
|
|
* @constructor
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
var Revision = function ( data ) {
|
2016-05-06 13:46:28 +00:00
|
|
|
this.id = data.revid;
|
2016-04-28 10:18:52 +00:00
|
|
|
this.size = data.size;
|
|
|
|
this.timestamp = data.timestamp;
|
2016-05-12 12:00:00 +00:00
|
|
|
this.minor = data.hasOwnProperty( 'minor' ) && ( data.minor || data.minor === '' );
|
2016-07-14 21:20:46 +00:00
|
|
|
|
|
|
|
// Comments and users can be suppressed thus we must check if they exist
|
|
|
|
if ( typeof data.comment !== 'undefined' ) {
|
|
|
|
this.comment = data.comment;
|
|
|
|
}
|
|
|
|
if ( typeof data.parsedcomment !== 'undefined' ) {
|
|
|
|
this.parsedComment = data.parsedcomment;
|
|
|
|
}
|
|
|
|
if ( typeof data.user !== 'undefined' ) {
|
|
|
|
this.user = data.user;
|
2016-06-27 14:00:13 +00:00
|
|
|
if ( typeof data.userGender !== 'undefined' ) {
|
|
|
|
this.userGender = data.userGender;
|
|
|
|
}
|
2016-07-14 21:20:46 +00:00
|
|
|
}
|
2016-04-28 10:18:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( Revision.prototype, {
|
2016-05-06 13:46:28 +00:00
|
|
|
/**
|
2016-06-17 13:06:12 +00:00
|
|
|
* @type {number}
|
2016-05-06 13:46:28 +00:00
|
|
|
*/
|
|
|
|
id: 0,
|
|
|
|
|
2016-04-28 10:18:52 +00:00
|
|
|
/**
|
2016-06-17 13:06:12 +00:00
|
|
|
* @type {number}
|
2016-04-28 10:18:52 +00:00
|
|
|
*/
|
|
|
|
size: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
comment: '',
|
|
|
|
|
2016-05-12 12:00:00 +00:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
minor: false,
|
|
|
|
|
2016-04-28 10:18:52 +00:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
parsedComment: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
timestamp: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
user: '',
|
|
|
|
|
2016-07-25 13:35:41 +00:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
userGender: '',
|
|
|
|
|
2016-05-12 13:52:54 +00:00
|
|
|
/**
|
2016-06-17 13:06:12 +00:00
|
|
|
* @type {number}
|
2016-05-12 13:52:54 +00:00
|
|
|
*/
|
|
|
|
relativeSize: 0,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-06 13:46:28 +00:00
|
|
|
getId: function () {
|
|
|
|
return this.id;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
getSize: function () {
|
|
|
|
return this.size;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-12 12:00:00 +00:00
|
|
|
isMinor: function () {
|
|
|
|
return this.minor;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
getParsedComment: function () {
|
|
|
|
return this.parsedComment;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-30 12:36:48 +00:00
|
|
|
hasEmptyComment: function () {
|
|
|
|
return this.getComment().trim().length === 0;
|
2016-04-28 10:18:52 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2016-05-30 12:36:48 +00:00
|
|
|
getComment: function () {
|
|
|
|
return this.comment;
|
2016-05-02 10:05:31 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Uses moment.js to format the date
|
|
|
|
*
|
|
|
|
* @param {string} rawDate
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
formatDate: function ( rawDate ) {
|
2016-05-20 18:00:52 +00:00
|
|
|
// Moment's offset works "backwards", as the number of minutes
|
|
|
|
// behind UTC, so we need to make this number negative
|
|
|
|
var offset = -mw.libs.revisionSlider.userOffset;
|
2016-08-09 11:19:46 +00:00
|
|
|
return moment( rawDate ).zone( offset ).format( 'LLL' );
|
2016-04-28 10:18:52 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
getFormattedDate: function () {
|
|
|
|
return this.formatDate( this.timestamp );
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2016-04-28 10:18:52 +00:00
|
|
|
getUser: function () {
|
|
|
|
return this.user;
|
2016-05-12 13:52:54 +00:00
|
|
|
},
|
|
|
|
|
2016-07-25 13:35:41 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUserGender: function () {
|
|
|
|
return this.userGender;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {number} size
|
|
|
|
*/
|
2016-05-12 13:52:54 +00:00
|
|
|
setRelativeSize: function ( size ) {
|
|
|
|
this.relativeSize = size;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-12 13:52:54 +00:00
|
|
|
getRelativeSize: function () {
|
|
|
|
return this.relativeSize;
|
2016-04-28 10:18:52 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.Revision = Revision;
|
|
|
|
}( mediaWiki, jQuery ) );
|