2020-11-18 09:11:12 +00:00
|
|
|
/* global moment:false */
|
|
|
|
/**
|
|
|
|
* @param {Object} data - Containing keys `id`, `size`, `comment`, `parsedcomment`, `timestamp`, `user` and `minor`
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function Revision( data ) {
|
|
|
|
this.id = data.revid;
|
|
|
|
this.size = data.size;
|
|
|
|
this.timestamp = data.timestamp;
|
|
|
|
this.minor = !!data.minor || data.minor === '';
|
|
|
|
|
|
|
|
// Comments, tags, and users can be suppressed thus we must check if they exist
|
|
|
|
if ( 'comment' in data ) {
|
|
|
|
this.comment = data.comment;
|
|
|
|
}
|
|
|
|
if ( 'parsedcomment' in data ) {
|
|
|
|
this.parsedComment = data.parsedcomment;
|
|
|
|
}
|
|
|
|
if ( 'tags' in data ) {
|
|
|
|
this.tags = data.tags;
|
|
|
|
}
|
|
|
|
if ( 'user' in data ) {
|
|
|
|
this.user = data.user;
|
|
|
|
if ( 'userGender' in data ) {
|
|
|
|
this.userGender = data.userGender;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.libs.revisionSlider.Revision
|
|
|
|
*/
|
|
|
|
$.extend( Revision.prototype, {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {number}
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
id: 0,
|
2016-07-14 21:20:46 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
size: 0,
|
2016-04-28 10:18:52 +00:00
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
comment: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
|
|
|
tags: [],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
minor: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
parsedComment: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
timestamp: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
user: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
userGender: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
relativeSize: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getId: function () {
|
|
|
|
return this.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getSize: function () {
|
|
|
|
return this.size;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isMinor: function () {
|
|
|
|
return this.minor;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getParsedComment: function () {
|
|
|
|
return this.parsedComment;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
hasEmptyComment: function () {
|
|
|
|
return this.getComment().trim().length === 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getComment: function () {
|
|
|
|
return this.comment;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string[]}
|
|
|
|
*/
|
|
|
|
getTags: function () {
|
|
|
|
return this.tags;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
hasNoTags: function () {
|
|
|
|
return this.tags.length === 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses moment.js to format the date
|
|
|
|
*
|
|
|
|
* @param {string} rawDate
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
formatDate: function ( rawDate ) {
|
|
|
|
var offset = parseInt( mw.libs.revisionSlider.userOffset );
|
|
|
|
return moment( rawDate ).utcOffset( offset ).format( 'LLL' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getFormattedDate: function () {
|
|
|
|
return this.formatDate( this.timestamp );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUser: function () {
|
|
|
|
return this.user;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUserGender: function () {
|
|
|
|
return this.userGender;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} size
|
|
|
|
*/
|
|
|
|
setRelativeSize: function ( size ) {
|
|
|
|
this.relativeSize = size;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getRelativeSize: function () {
|
|
|
|
return this.relativeSize;
|
|
|
|
}
|
|
|
|
} );
|
2016-04-28 10:18:52 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.Revision = Revision;
|