mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-14 19:24:42 +00:00
Merge "Use parsed comment instead of custom parsing"
This commit is contained in:
commit
04df38c25f
|
@ -67,22 +67,12 @@
|
|||
return this.parsedComment;
|
||||
},
|
||||
|
||||
getComment: function () {
|
||||
return this.comment;
|
||||
hasEmptyComment: function () {
|
||||
return this.getComment().trim().length === 0;
|
||||
},
|
||||
|
||||
getSection: function () {
|
||||
var comment = this.getComment();
|
||||
comment = comment.match(
|
||||
new RegExp( '(/\\* [^\\*]* \\*/)', 'gi' )
|
||||
);
|
||||
if ( !comment ) {
|
||||
return '';
|
||||
}
|
||||
return comment[ 0 ].replace(
|
||||
new RegExp( ' \\*/|/\\* ', 'gi' ),
|
||||
''
|
||||
);
|
||||
getComment: function () {
|
||||
return this.comment;
|
||||
},
|
||||
|
||||
formatDate: function ( rawDate ) {
|
||||
|
|
|
@ -61,13 +61,7 @@
|
|||
mw.msg( 'revisionslider-label-user', mw.html.escape( rev.getUser() ) )
|
||||
) )
|
||||
: '',
|
||||
rev.getComment() ?
|
||||
$( '<bdi>' ).append(
|
||||
$( '<p>' ).append( $( '<i>' ).text(
|
||||
mw.msg( 'revisionslider-label-comment', mw.html.escape( rev.getComment() ) )
|
||||
) )
|
||||
)
|
||||
: '',
|
||||
this.makeCommentLine( rev ),
|
||||
$( '<p>' ).text(
|
||||
mw.msg( 'revisionslider-label-article-size', mw.msg( 'revisionslider-revision-bytes', rev.getSize() ) )
|
||||
),
|
||||
|
@ -77,6 +71,19 @@
|
|||
rev.isMinor() ? $( '<p>' ).text( mw.message( 'minoredit' ).text() ) : '' );
|
||||
|
||||
return $tooltip.html();
|
||||
},
|
||||
|
||||
makeCommentLine: function ( rev ) {
|
||||
if ( rev.hasEmptyComment() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $( '<bdi>' ).append(
|
||||
$( '<p>' ).append(
|
||||
$( '<i>' ).html(
|
||||
mw.msg( 'revisionslider-label-comment', rev.getParsedComment() )
|
||||
) )
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
|
|
|
@ -66,24 +66,6 @@
|
|||
assert.equal( rev.isMinor(), true );
|
||||
} );
|
||||
|
||||
QUnit.test( 'get Revision with section', function ( assert ) {
|
||||
var data = {
|
||||
comment: '/* section */ comment'
|
||||
},
|
||||
rev = new mw.libs.revisionSlider.Revision( data );
|
||||
|
||||
assert.equal( rev.getSection(), 'section' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'get Revision without section', function ( assert ) {
|
||||
var data = {
|
||||
comment: 'no section comment'
|
||||
},
|
||||
rev = new mw.libs.revisionSlider.Revision( data );
|
||||
|
||||
assert.equal( rev.getSection(), '' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'get and set relative size', function ( assert ) {
|
||||
var size = 5,
|
||||
rev = new mw.libs.revisionSlider.Revision( {} );
|
||||
|
@ -124,5 +106,29 @@
|
|||
assert.equal( rev.getFormattedDate(), '12:27, 26 Apr 2016' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'hasEmptyComment comment with whitespaces', function ( assert ) {
|
||||
var rev = new mw.libs.revisionSlider.Revision( {
|
||||
comment: ' '
|
||||
} );
|
||||
|
||||
assert.ok( rev.hasEmptyComment() );
|
||||
} );
|
||||
|
||||
QUnit.test( 'hasEmptyComment comment with chars', function ( assert ) {
|
||||
var rev = new mw.libs.revisionSlider.Revision( {
|
||||
comment: ' comment '
|
||||
} );
|
||||
|
||||
assert.notOk( rev.hasEmptyComment() );
|
||||
} );
|
||||
|
||||
QUnit.test( 'hasEmptyComment comment with unicode chars', function ( assert ) {
|
||||
var rev = new mw.libs.revisionSlider.Revision( {
|
||||
comment: 'ברוכים'
|
||||
} );
|
||||
|
||||
assert.notOk( rev.hasEmptyComment() );
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
|
||||
|
|
Loading…
Reference in a new issue