2018-11-16 16:33:52 +00:00
|
|
|
( function () {
|
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;
|
2018-09-13 20:54:39 +00:00
|
|
|
this.minor = !!data.minor || data.minor === '';
|
2016-07-14 21:20:46 +00:00
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
// Comments, tags, and users can be suppressed thus we must check if they exist
|
2018-08-02 07:35:37 +00:00
|
|
|
if ( 'comment' in data ) {
|
2016-07-14 21:20:46 +00:00
|
|
|
this.comment = data.comment;
|
|
|
|
}
|
2018-08-02 07:35:37 +00:00
|
|
|
if ( 'parsedcomment' in data ) {
|
2016-07-14 21:20:46 +00:00
|
|
|
this.parsedComment = data.parsedcomment;
|
|
|
|
}
|
2018-08-22 08:00:30 +00:00
|
|
|
if ( 'tags' in data ) {
|
|
|
|
this.tags = data.tags;
|
|
|
|
}
|
2018-08-02 07:35:37 +00:00
|
|
|
if ( 'user' in data ) {
|
2016-07-14 21:20:46 +00:00
|
|
|
this.user = data.user;
|
2018-08-02 07:35:37 +00:00
|
|
|
if ( 'userGender' in data ) {
|
2016-06-27 14:00:13 +00:00
|
|
|
this.userGender = data.userGender;
|
|
|
|
}
|
2016-07-14 21:20:46 +00:00
|
|
|
}
|
2016-04-28 10:18:52 +00:00
|
|
|
};
|
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
|
|
|
* @class mw.libs.revisionSlider.Revision
|
|
|
|
*/
|
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: '',
|
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
/**
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
|
|
|
tags: [],
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2018-08-22 08:00:30 +00:00
|
|
|
/**
|
|
|
|
* @return {string[]}
|
|
|
|
*/
|
|
|
|
getTags: function () {
|
|
|
|
return this.tags;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
hasNoTags: function () {
|
|
|
|
return this.tags.length === 0;
|
|
|
|
},
|
|
|
|
|
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 ) {
|
2017-04-05 12:33:59 +00:00
|
|
|
var offset = parseInt( mw.libs.revisionSlider.userOffset );
|
|
|
|
return moment( rawDate ).utcOffset( 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;
|
2018-11-16 16:33:52 +00:00
|
|
|
}() );
|