2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {RevisionList} revisionList
|
2017-08-23 15:01:03 +00:00
|
|
|
* @param {string} [dir]
|
2016-06-17 13:06:12 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2017-03-03 13:55:42 +00:00
|
|
|
var RevisionListView = function ( revisionList, dir ) {
|
2016-05-10 12:42:05 +00:00
|
|
|
this.revisionList = revisionList;
|
2017-03-03 13:55:42 +00:00
|
|
|
this.dir = dir;
|
2016-05-10 12:42:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( RevisionListView.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisionList: null,
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
revisionWidth: 16,
|
|
|
|
|
2017-04-20 12:57:48 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
minRevisionHeight: 5,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
maxRevisionHeight: 66,
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
tooltipTimeout: -1,
|
|
|
|
|
2017-08-17 14:08:49 +00:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
allowHover: true,
|
|
|
|
|
2017-03-03 13:55:42 +00:00
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
dir: null,
|
|
|
|
|
2017-04-13 15:01:02 +00:00
|
|
|
/**
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
html: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {number} revisionTickWidth
|
2016-06-27 14:00:13 +00:00
|
|
|
* @param {number} positionOffset
|
2016-06-17 13:06:12 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2016-06-27 14:00:13 +00:00
|
|
|
render: function ( revisionTickWidth, positionOffset ) {
|
2017-04-13 15:01:02 +00:00
|
|
|
var revs = this.revisionList.getRevisions(),
|
2016-05-10 12:42:05 +00:00
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
2016-06-24 13:13:20 +00:00
|
|
|
self = this,
|
2016-08-03 12:08:05 +00:00
|
|
|
i, diffSize, relativeChangeSize,
|
2017-08-17 14:08:49 +00:00
|
|
|
setHovered = function ( event ) {
|
|
|
|
if ( self.allowHover ) {
|
|
|
|
self.setRevisionHovered( $( this ), event );
|
|
|
|
}
|
2016-06-24 13:13:20 +00:00
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
unsetHovered = function () {
|
|
|
|
self.unsetRevisionHovered( $( this ) );
|
2016-06-24 13:13:20 +00:00
|
|
|
};
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
positionOffset = positionOffset || 0;
|
2016-08-03 12:08:05 +00:00
|
|
|
this.revisionWidth = revisionTickWidth;
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2017-04-13 15:01:02 +00:00
|
|
|
this.$html = $( '<div>' ).addClass( 'mw-revslider-revisions' );
|
|
|
|
|
2016-05-12 13:52:54 +00:00
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
diffSize = revs[ i ].getRelativeSize();
|
2017-04-20 12:57:48 +00:00
|
|
|
relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2017-04-13 15:01:02 +00:00
|
|
|
this.$html
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( 'mw-revslider-revision-wrapper' )
|
2016-08-03 12:08:05 +00:00
|
|
|
.width( this.revisionWidth )
|
2016-05-30 10:06:44 +00:00
|
|
|
.append( $( '<div>' )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( 'mw-revslider-revision' )
|
2016-05-30 10:06:44 +00:00
|
|
|
.attr( 'data-revid', revs[ i ].getId() )
|
2016-06-27 14:00:13 +00:00
|
|
|
.attr( 'data-pos', positionOffset + i + 1 )
|
2016-05-18 14:55:39 +00:00
|
|
|
.css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
2016-08-03 12:08:05 +00:00
|
|
|
width: this.revisionWidth + 'px',
|
2016-05-18 14:55:39 +00:00
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} )
|
2016-07-01 10:13:53 +00:00
|
|
|
.addClass( diffSize > 0 ? 'mw-revslider-revision-up' : 'mw-revslider-revision-down' )
|
|
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-revision-border-box' ) )
|
2016-05-18 14:55:39 +00:00
|
|
|
)
|
2017-08-17 14:08:49 +00:00
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision-wrapper-up' )
|
|
|
|
.width( this.revisionWidth )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer mw-revslider-pointer-ghost' )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.append( $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision-wrapper-down' )
|
|
|
|
.width( this.revisionWidth )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer mw-revslider-pointer-ghost' )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.mouseenter( setHovered )
|
|
|
|
.mouseleave( unsetHovered )
|
2016-05-26 09:50:51 +00:00
|
|
|
);
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
this.keepTooltipsOnHover();
|
2016-08-31 15:28:27 +00:00
|
|
|
this.closeTooltipsOnClick();
|
2016-06-24 13:13:20 +00:00
|
|
|
|
2017-04-13 15:01:02 +00:00
|
|
|
return this.$html;
|
2016-05-10 12:42:05 +00:00
|
|
|
},
|
|
|
|
|
2017-08-17 14:08:49 +00:00
|
|
|
enableHover: function () {
|
|
|
|
this.allowHover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
disableHover: function () {
|
|
|
|
this.allowHover = false;
|
|
|
|
this.unsetAllHovered();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @param {Event} event
|
|
|
|
*/
|
|
|
|
setRevisionHovered: function ( $revisionWrapper, event ) {
|
|
|
|
var hasMovedTop = event.pageY - $revisionWrapper.offset().top < $revisionWrapper.height() / 2,
|
|
|
|
isOlderTop = $revisionWrapper.hasClass( 'mw-revslider-revision-older' ) && hasMovedTop,
|
|
|
|
isNewerBottom = $revisionWrapper.hasClass( 'mw-revslider-revision-newer' ) && !hasMovedTop,
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper;
|
|
|
|
|
|
|
|
this.showTooltip( $revisionWrapper );
|
|
|
|
|
|
|
|
if ( isOlderTop ) {
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper.prev();
|
|
|
|
} else if ( isNewerBottom ) {
|
|
|
|
$neighborRevisionWrapper = $revisionWrapper.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $neighborRevisionWrapper.length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasMovedTop ) {
|
|
|
|
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
|
|
|
if ( isOlderTop ) {
|
|
|
|
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setRevisionGhost( $revisionWrapper.find( '.mw-revslider-revision-wrapper-down' ) );
|
|
|
|
if ( isNewerBottom ) {
|
|
|
|
this.setRevisionGhost( $neighborRevisionWrapper.find( '.mw-revslider-revision-wrapper-up' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getRevisionWrapperPos: function ( $revisionWrapper ) {
|
|
|
|
return +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
setRevisionGhost: function ( $revisionWrapper ) {
|
|
|
|
$revisionWrapper.addClass( 'mw-revslider-revision-hovered' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
unsetRevisionHovered: function ( $revisionWrapper ) {
|
|
|
|
this.unsetRevisionGhosts( $revisionWrapper );
|
|
|
|
this.hideTooltip( $revisionWrapper );
|
|
|
|
},
|
|
|
|
|
|
|
|
unsetAllHovered: function () {
|
|
|
|
$( '.mw-revslider-revision-wrapper-up, .mw-revslider-revision-wrapper-down' )
|
|
|
|
.removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
unsetRevisionGhosts: function ( $revisionWrapper ) {
|
|
|
|
$revisionWrapper.children().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
$revisionWrapper.prev().children().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
$revisionWrapper.next().children().removeClass( 'mw-revslider-revision-hovered' );
|
|
|
|
},
|
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $renderedList
|
|
|
|
*/
|
|
|
|
adjustRevisionSizes: function ( $renderedList ) {
|
|
|
|
var revs = this.revisionList.getRevisions(),
|
|
|
|
maxChangeSizeLogged = Math.log( this.revisionList.getBiggestChangeSize() ),
|
|
|
|
i, diffSize, relativeChangeSize;
|
2017-04-20 12:57:48 +00:00
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
diffSize = revs[ i ].getRelativeSize();
|
2017-04-20 12:57:48 +00:00
|
|
|
relativeChangeSize = this.calcRelativeChangeSize( diffSize, maxChangeSizeLogged );
|
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
$renderedList.find( '.mw-revslider-revision[data-pos="' + ( i + 1 ) + '"]' ).css( {
|
|
|
|
height: relativeChangeSize + 'px',
|
|
|
|
top: diffSize > 0 ? '-' + relativeChangeSize + 'px' : 0
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-04 20:57:38 +00:00
|
|
|
calcRelativeChangeSize: function ( diffSize, maxChangeSizeLogged ) {
|
2017-04-20 12:57:48 +00:00
|
|
|
if ( diffSize === 0 ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Math.ceil(
|
2017-07-14 10:28:45 +00:00
|
|
|
( this.maxRevisionHeight - this.minRevisionHeight ) *
|
|
|
|
Math.log( Math.abs( diffSize ) ) / maxChangeSizeLogged ) +
|
|
|
|
this.minRevisionHeight;
|
2017-04-20 12:57:48 +00:00
|
|
|
},
|
|
|
|
|
2016-06-24 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* Hides the current tooltip immediately
|
|
|
|
*/
|
|
|
|
hideCurrentTooltip: function () {
|
2016-08-31 15:03:57 +00:00
|
|
|
var $highlightedRevisionWrapper = $( '.mw-revslider-revision-wrapper-hovered' ),
|
|
|
|
$currentTooltip = $( '.mw-revslider-revision-tooltip' );
|
2016-08-31 13:42:23 +00:00
|
|
|
if ( this.tooltipTimeout !== -1 ) {
|
2016-06-24 13:13:20 +00:00
|
|
|
window.clearTimeout( this.tooltipTimeout );
|
2016-08-31 13:42:23 +00:00
|
|
|
}
|
2016-08-31 15:03:57 +00:00
|
|
|
if ( $highlightedRevisionWrapper.length !== 0 ) {
|
|
|
|
$highlightedRevisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
2016-08-31 13:42:23 +00:00
|
|
|
}
|
2016-08-31 15:03:57 +00:00
|
|
|
if ( $currentTooltip.length !== 0 ) {
|
|
|
|
$currentTooltip.remove();
|
2016-06-24 13:13:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the tooltip after 500ms
|
|
|
|
*
|
2017-08-17 14:08:49 +00:00
|
|
|
* @param {jQuery} $revisionWrapper
|
2016-06-24 13:13:20 +00:00
|
|
|
*/
|
2017-08-17 14:08:49 +00:00
|
|
|
hideTooltip: function ( $revisionWrapper ) {
|
2016-08-31 15:03:57 +00:00
|
|
|
var $currentTooltip = $( '.mw-revslider-revision-tooltip' );
|
2016-06-24 13:13:20 +00:00
|
|
|
this.tooltipTimeout = window.setTimeout( function () {
|
2017-08-17 14:08:49 +00:00
|
|
|
if ( $revisionWrapper.length !== 0 ) {
|
|
|
|
$revisionWrapper.removeClass( 'mw-revslider-revision-wrapper-hovered' );
|
2016-08-03 12:08:05 +00:00
|
|
|
}
|
2016-08-31 15:03:57 +00:00
|
|
|
if ( $currentTooltip.length !== 0 ) {
|
|
|
|
$currentTooltip.remove();
|
2016-08-03 12:08:05 +00:00
|
|
|
}
|
2016-06-24 13:13:20 +00:00
|
|
|
}, 500 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the previous tooltip and shows the new one
|
|
|
|
*
|
2017-08-17 14:08:49 +00:00
|
|
|
* @param {jQuery} $revisionWrapper
|
2016-06-24 13:13:20 +00:00
|
|
|
*/
|
2017-08-17 14:08:49 +00:00
|
|
|
showTooltip: function ( $revisionWrapper ) {
|
|
|
|
var pos = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' ),
|
|
|
|
revId = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-revid' ),
|
2016-10-13 18:57:36 +00:00
|
|
|
revision = this.getRevisionWithId( revId ),
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltip;
|
|
|
|
if ( revision === null ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-31 13:42:23 +00:00
|
|
|
|
|
|
|
this.hideCurrentTooltip();
|
|
|
|
|
2017-08-17 14:08:49 +00:00
|
|
|
tooltip = this.makeTooltip( revision, $revisionWrapper );
|
2017-03-03 13:55:42 +00:00
|
|
|
tooltip.$element.addClass( 'mw-revslider-revision-tooltip-' + pos );
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
$( 'body' ).append( tooltip.$element );
|
|
|
|
tooltip.toggle( true );
|
|
|
|
|
2017-08-17 14:08:49 +00:00
|
|
|
$revisionWrapper.addClass( 'mw-revslider-revision-wrapper-hovered' );
|
2016-08-03 12:08:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} revId
|
|
|
|
* @return {Revision|null}
|
|
|
|
*/
|
|
|
|
getRevisionWithId: function ( revId ) {
|
|
|
|
var matchedRevision = null;
|
|
|
|
this.revisionList.revisions.forEach( function ( revision ) {
|
|
|
|
if ( revision.getId() === revId ) {
|
|
|
|
matchedRevision = revision;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return matchedRevision;
|
2016-06-24 13:13:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets event handlers on tooltips so they do not disappear when hovering over them
|
|
|
|
*/
|
|
|
|
keepTooltipsOnHover: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
2016-08-31 13:42:23 +00:00
|
|
|
.on( 'mouseenter', '.mw-revslider-revision-tooltip', function () {
|
2016-06-24 13:13:20 +00:00
|
|
|
window.clearTimeout( self.tooltipTimeout );
|
|
|
|
} )
|
2016-08-31 13:42:23 +00:00
|
|
|
.on( 'mouseleave', '.mw-revslider-revision-tooltip', function () {
|
2016-08-31 15:03:57 +00:00
|
|
|
self.hideTooltip( $( '.mw-revslider-revision-wrapper-hovered' ) );
|
2016-06-24 13:13:20 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2016-08-31 15:28:27 +00:00
|
|
|
/**
|
|
|
|
* Sets an event handler to close tooltips when clicking somewhere outside
|
|
|
|
*/
|
|
|
|
closeTooltipsOnClick: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$( document )
|
|
|
|
.on( 'click', function ( event ) {
|
|
|
|
if ( $( event.target ).closest( '.mw-revslider-revision-tooltip' ).length === 0 &&
|
|
|
|
$( event.target ).closest( '.mw-revslider-revisions-container' ).length === 0 ) {
|
|
|
|
self.hideCurrentTooltip();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for a tooltip that appears on hover above each revision on the slider
|
|
|
|
*
|
2017-03-03 13:55:42 +00:00
|
|
|
* @param {Revision} revision
|
2017-08-17 14:08:49 +00:00
|
|
|
* @param {jQuery} $revisionWrapper
|
2016-08-03 12:08:05 +00:00
|
|
|
* @return {OO.ui.PopupWidget}
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2017-08-17 14:08:49 +00:00
|
|
|
makeTooltip: function ( revision, $revisionWrapper ) {
|
2016-05-30 10:06:44 +00:00
|
|
|
var $tooltip = $( '<div>' )
|
2016-05-26 13:21:42 +00:00
|
|
|
.append(
|
2016-06-15 11:56:10 +00:00
|
|
|
$( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-date' ) + mw.msg( 'colon-separator' ) ),
|
2017-08-10 18:49:38 +00:00
|
|
|
$( '<a>' ).attr( 'href', mw.util.getUrl( null, { oldid: revision.id } ) )
|
2017-08-10 15:44:26 +00:00
|
|
|
.text( revision.getFormattedDate() )
|
2016-06-15 11:56:10 +00:00
|
|
|
),
|
2017-03-03 13:55:42 +00:00
|
|
|
this.makeUserLine( revision.getUser(), revision.getUserGender() ),
|
|
|
|
this.makeCommentLine( revision ),
|
|
|
|
this.makePageSizeLine( revision.getSize() ),
|
|
|
|
this.makeChangeSizeLine( revision.getRelativeSize() ),
|
|
|
|
revision.isMinor() ? $( '<p>' ).text( mw.message( 'revisionslider-minoredit' ).text() ) : ''
|
2016-06-29 10:43:46 +00:00
|
|
|
);
|
2016-08-03 12:08:05 +00:00
|
|
|
return new OO.ui.PopupWidget( {
|
|
|
|
$content: $tooltip,
|
2017-08-17 14:08:49 +00:00
|
|
|
$floatableContainer: $revisionWrapper,
|
2016-08-03 12:08:05 +00:00
|
|
|
padded: true,
|
|
|
|
classes: [ 'mw-revslider-tooltip', 'mw-revslider-revision-tooltip' ]
|
|
|
|
} );
|
2016-05-30 12:36:48 +00:00
|
|
|
},
|
|
|
|
|
2016-06-30 12:27:16 +00:00
|
|
|
/**
|
|
|
|
* Generates a link to user page or to contributions page for IP addresses
|
|
|
|
*
|
|
|
|
* @param {string} user
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
getUserPage: function ( user ) {
|
2016-07-26 08:24:44 +00:00
|
|
|
return ( mw.util.isIPAddress( user, false ) ? 'Special:Contributions/' : 'User:' ) + this.stripInvalidCharacters( user );
|
2016-06-30 11:13:44 +00:00
|
|
|
},
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the user label
|
|
|
|
*
|
|
|
|
* @param {string} userString
|
2016-07-25 13:35:41 +00:00
|
|
|
* @param {string} userGender
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
2016-07-25 13:35:41 +00:00
|
|
|
makeUserLine: function ( userString, userGender ) {
|
2016-06-29 10:43:46 +00:00
|
|
|
if ( !userString ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-07-25 13:35:41 +00:00
|
|
|
if ( !userGender ) {
|
|
|
|
userGender = 'unknown';
|
|
|
|
}
|
2016-07-26 09:03:08 +00:00
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-username', userGender ) + mw.msg( 'colon-separator' ) ),
|
2016-07-26 09:03:08 +00:00
|
|
|
$( '<bdi>' ).append(
|
|
|
|
$( '<a>' ).addClass( 'mw-userlink' ).attr( 'href', mw.util.getUrl( this.getUserPage( userString ) ) ).text( this.stripInvalidCharacters( userString ) )
|
|
|
|
)
|
|
|
|
);
|
2016-06-29 10:43:46 +00:00
|
|
|
},
|
|
|
|
|
2016-07-26 08:24:44 +00:00
|
|
|
/**
|
|
|
|
* @param {string} s
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
stripInvalidCharacters: function ( s ) {
|
|
|
|
return s.replace( /[<>&]/g, '' );
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the comment label
|
|
|
|
*
|
|
|
|
* @param {Revision} rev
|
|
|
|
* @return {string|jQuery}
|
|
|
|
*/
|
2016-05-30 12:36:48 +00:00
|
|
|
makeCommentLine: function ( rev ) {
|
|
|
|
if ( rev.hasEmptyComment() ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-07-26 09:03:08 +00:00
|
|
|
return $( '<p>' ).append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-comment' ) + mw.msg( 'colon-separator' ) ),
|
|
|
|
$( '<em>' ).append(
|
|
|
|
$( '<bdi>' ).append(
|
2016-06-15 11:56:10 +00:00
|
|
|
rev.getParsedComment()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
/**
|
|
|
|
* Generates the HTML for the page size label
|
|
|
|
*
|
2016-07-04 21:58:22 +00:00
|
|
|
* @param {number} size
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makePageSizeLine: function ( size ) {
|
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-page-size' ) + mw.msg( 'colon-separator' ) ),
|
2016-07-28 12:49:12 +00:00
|
|
|
mw.msg( 'revisionslider-page-size', mw.language.convertNumber( size ), size )
|
2016-06-29 10:43:46 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the HTML for the change size label
|
|
|
|
*
|
2016-07-04 21:58:22 +00:00
|
|
|
* @param {number} relativeSize
|
2016-06-29 10:43:46 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
makeChangeSizeLine: function ( relativeSize ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
var changeSizeClass = 'mw-revslider-change-none',
|
2016-06-15 11:56:10 +00:00
|
|
|
leadingSign = '',
|
|
|
|
$changeNumber;
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
if ( relativeSize > 0 ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
changeSizeClass = 'mw-revslider-change-positive';
|
2016-06-15 11:56:10 +00:00
|
|
|
leadingSign = '+';
|
2016-06-29 10:43:46 +00:00
|
|
|
} else if ( relativeSize < 0 ) {
|
2016-07-01 10:13:53 +00:00
|
|
|
changeSizeClass = 'mw-revslider-change-negative';
|
2016-06-15 11:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$changeNumber = $( '<span>' )
|
|
|
|
.addClass( changeSizeClass )
|
2016-07-16 18:56:57 +00:00
|
|
|
.attr( {
|
|
|
|
dir: 'ltr' // Make sure that minus/plus is on the left
|
|
|
|
} )
|
2016-06-29 10:43:46 +00:00
|
|
|
.text( leadingSign + mw.language.convertNumber( relativeSize ) );
|
2016-06-15 11:56:10 +00:00
|
|
|
|
|
|
|
return $( '<p>' ).append(
|
2016-07-26 17:02:31 +00:00
|
|
|
$( '<strong>' ).text( mw.msg( 'revisionslider-label-change-size' ) + mw.msg( 'colon-separator' ) ),
|
2016-07-28 12:49:12 +00:00
|
|
|
mw.message( 'revisionslider-change-size', $changeNumber, relativeSize, Math.abs( relativeSize ) ).parse()
|
2016-05-30 12:36:48 +00:00
|
|
|
);
|
2017-03-03 13:55:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set direction for the view
|
|
|
|
*
|
|
|
|
* @param {string} dir
|
|
|
|
*/
|
|
|
|
setDir: function ( dir ) {
|
|
|
|
this.dir = dir;
|
2017-04-13 15:01:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2017-05-04 20:57:38 +00:00
|
|
|
getElement: function () {
|
2017-04-13 15:01:02 +00:00
|
|
|
return this.$html;
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.RevisionListView = RevisionListView;
|
|
|
|
}( mediaWiki, jQuery ) );
|