mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 11:40:43 +00:00
dc838bc87d
This changes the previous behaviour of fetching always up to 500 most recent revisions. Now the extensions fetches N revisions including the newer revision selected to diff as the most recent revision. N is number of revisions that would fit in the current window when rendered as bars. When user is close to either "end" of the slider, extensions fetches another batch of up to N older or newer revisions, as long as user does not reach the oldest or the newest revision of the page. Among others, this removes the limitations of the previous approach: showing only 500 revisions, and failing to show anything when any of selected revisions was older than 500 recent revisions. This change also simplifies usage of Api class. Bug: T135005 Change-Id: Ib3f4a6ac57ff17008f9d8784c4716bd294443096
66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
( function ( mw, $ ) {
|
|
var api = new mw.libs.revisionSlider.Api( mw.util.wikiScript( 'api' ) );
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.init' );
|
|
mw.libs.revisionSlider.userOffset = mw.user.options.values.timecorrection ? mw.user.options.values.timecorrection.split( '|' )[ 1 ] : mw.config.values.extRevisionSliderTimeOffset;
|
|
|
|
api.fetchRevisionData( mw.config.get( 'wgPageName' ), {
|
|
startId: mw.config.values.extRevisionSliderNewRev,
|
|
limit: mw.libs.revisionSlider.calculateRevisionsPerWindow( 120, 16 ),
|
|
|
|
success: function ( data ) {
|
|
var revs,
|
|
revisionList,
|
|
$container,
|
|
slider;
|
|
|
|
try {
|
|
revs = data.revisions;
|
|
revs.reverse();
|
|
|
|
revisionList = new mw.libs.revisionSlider.RevisionList( mw.libs.revisionSlider.makeRevisions( revs ) );
|
|
|
|
$container = $( '#mw-revslider-container' );
|
|
slider = new mw.libs.revisionSlider.Slider( revisionList );
|
|
slider.getView().render( $container );
|
|
|
|
if ( !mw.user.options.get( 'userjs-revslider-hidehelp' ) ) {
|
|
mw.libs.revisionSlider.HelpDialog.show();
|
|
( new mw.Api() ).saveOption( 'userjs-revslider-hidehelp', true );
|
|
}
|
|
|
|
$container.append(
|
|
$( '<button>' )
|
|
.click( function () {
|
|
mw.libs.revisionSlider.HelpDialog.show();
|
|
} )
|
|
.text( mw.message( 'revisionslider-show-help' ).text() )
|
|
.addClass( 'mw-revslider-show-help' )
|
|
.tipsy( {
|
|
gravity: $( 'body' ).hasClass( 'ltr' ) ? 'se' : 'sw',
|
|
offset: 15,
|
|
title: function () {
|
|
return mw.msg( 'revisionslider-show-help-tooltip' );
|
|
}
|
|
} )
|
|
);
|
|
|
|
$( '#mw-revslider-placeholder' ).remove();
|
|
} catch ( err ) {
|
|
$( '#mw-revslider-placeholder' )
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
|
console.log( err );
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
|
}
|
|
|
|
},
|
|
error: function ( err ) {
|
|
$( '#mw-revslider-placeholder' )
|
|
.text( mw.message( 'revisionslider-loading-failed' ).text() );
|
|
console.log( err );
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.error.init' );
|
|
}
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|