mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-14 19:24:42 +00:00
Use parsed comment instead of custom parsing
Bug: T135740 Change-Id: I49757b5bcf2c47f459538bd4383325882a15336f
This commit is contained in:
parent
45a72df594
commit
f8446590cb
|
@ -67,22 +67,12 @@
|
||||||
return this.parsedComment;
|
return this.parsedComment;
|
||||||
},
|
},
|
||||||
|
|
||||||
getComment: function () {
|
hasEmptyComment: function () {
|
||||||
return this.comment;
|
return this.getComment().trim().length === 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSection: function () {
|
getComment: function () {
|
||||||
var comment = this.getComment();
|
return this.comment;
|
||||||
comment = comment.match(
|
|
||||||
new RegExp( '(/\\* [^\\*]* \\*/)', 'gi' )
|
|
||||||
);
|
|
||||||
if ( !comment ) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return comment[ 0 ].replace(
|
|
||||||
new RegExp( ' \\*/|/\\* ', 'gi' ),
|
|
||||||
''
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
formatDate: function ( rawDate ) {
|
formatDate: function ( rawDate ) {
|
||||||
|
|
|
@ -61,19 +61,26 @@
|
||||||
mw.msg( 'revisionslider-label-user', mw.html.escape( rev.getUser() ) )
|
mw.msg( 'revisionslider-label-user', mw.html.escape( rev.getUser() ) )
|
||||||
) )
|
) )
|
||||||
: '',
|
: '',
|
||||||
rev.getComment() ?
|
this.makeCommentLine( rev ),
|
||||||
$( '<bdi>' ).append(
|
|
||||||
$( '<p>' ).append( $( '<i>' ).text(
|
|
||||||
mw.msg( 'revisionslider-label-comment', mw.html.escape( rev.getComment() ) )
|
|
||||||
) )
|
|
||||||
)
|
|
||||||
: '',
|
|
||||||
$( '<p>' ).text(
|
$( '<p>' ).text(
|
||||||
mw.msg( 'revisionslider-label-article-size', mw.msg( 'revisionslider-revision-bytes', rev.getSize() ) )
|
mw.msg( 'revisionslider-label-article-size', mw.msg( 'revisionslider-revision-bytes', rev.getSize() ) )
|
||||||
),
|
),
|
||||||
rev.isMinor() ? $( '<p>' ).text( mw.message( 'minoredit' ).text() ) : '' );
|
rev.isMinor() ? $( '<p>' ).text( mw.message( 'minoredit' ).text() ) : '' );
|
||||||
|
|
||||||
return $tooltip.html();
|
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 );
|
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 ) {
|
QUnit.test( 'get and set relative size', function ( assert ) {
|
||||||
var size = 5,
|
var size = 5,
|
||||||
rev = new mw.libs.revisionSlider.Revision( {} );
|
rev = new mw.libs.revisionSlider.Revision( {} );
|
||||||
|
@ -124,5 +106,29 @@
|
||||||
assert.equal( rev.getFormattedDate(), '12:27, 26 Apr 2016' );
|
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 );
|
} )( mediaWiki );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue