2017-06-09 13:45:59 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki DiffPage init.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2017-06-09 13:45:59 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function () {
|
2018-03-04 14:45:33 +00:00
|
|
|
var reviewModeButtonSelect, diffElement, lastDiff, $wikitextDiff,
|
|
|
|
$visualDiffContainer = $( '<div>' ),
|
|
|
|
$visualDiff = $( '<div>' ),
|
|
|
|
progress = new OO.ui.ProgressBarWidget( { classes: [ 've-init-mw-diffPage-loading' ] } ),
|
2017-07-27 12:26:55 +00:00
|
|
|
uri = new mw.Uri(),
|
2017-08-10 15:24:54 +00:00
|
|
|
mode = uri.query.diffmode || 'source',
|
2017-06-09 13:45:59 +00:00
|
|
|
conf = mw.config.get( 'wgVisualEditorConfig' ),
|
|
|
|
pluginModules = conf.pluginModules.filter( mw.loader.getState );
|
|
|
|
|
2018-02-22 17:48:37 +00:00
|
|
|
if ( mode !== 'visual' ) {
|
|
|
|
// Enforce a valid mode, to avoid visual glitches in button-selection.
|
|
|
|
mode = 'source';
|
|
|
|
}
|
|
|
|
|
2018-03-04 14:45:33 +00:00
|
|
|
$visualDiffContainer.append(
|
|
|
|
progress.$element.addClass( 'oo-ui-element-hidden' ),
|
|
|
|
$visualDiff
|
|
|
|
);
|
|
|
|
|
2017-06-09 13:45:59 +00:00
|
|
|
function onReviewModeButtonSelectSelect( item ) {
|
2018-03-04 14:45:33 +00:00
|
|
|
var modulePromise, oldPageName, newPageName, isVisual,
|
2017-06-09 13:45:59 +00:00
|
|
|
$revSlider = $( '.mw-revslider-container' ),
|
2017-07-03 21:23:52 +00:00
|
|
|
oldId = mw.config.get( 'wgDiffOldId' ),
|
|
|
|
newId = mw.config.get( 'wgDiffNewId' );
|
2017-06-09 13:45:59 +00:00
|
|
|
|
2017-07-27 12:26:55 +00:00
|
|
|
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'ComparePages' ) {
|
|
|
|
oldPageName = newPageName = mw.config.get( 'wgRelevantPageName' );
|
|
|
|
} else {
|
|
|
|
oldPageName = uri.query.page1;
|
|
|
|
newPageName = uri.query.page2;
|
|
|
|
}
|
|
|
|
|
2017-06-09 13:45:59 +00:00
|
|
|
mode = item.getData();
|
2018-03-04 14:45:33 +00:00
|
|
|
isVisual = mode === 'visual';
|
|
|
|
|
|
|
|
$visualDiffContainer.toggleClass( 'oo-ui-element-hidden', !isVisual );
|
|
|
|
$wikitextDiff.toggleClass( 'oo-ui-element-hidden', isVisual );
|
|
|
|
$revSlider.toggleClass( 've-init-mw-diffPage-revSlider-visual', isVisual );
|
2017-06-09 13:45:59 +00:00
|
|
|
|
2018-03-04 14:45:33 +00:00
|
|
|
if ( isVisual && !(
|
|
|
|
lastDiff && lastDiff.oldId === oldId && lastDiff.newId === newId &&
|
|
|
|
lastDiff.oldPageName === oldPageName && lastDiff.newPageName === newPageName
|
|
|
|
) ) {
|
|
|
|
$visualDiff.empty();
|
|
|
|
progress.$element.removeClass( 'oo-ui-element-hidden' );
|
2017-06-09 13:45:59 +00:00
|
|
|
// TODO: Load a smaller subset of VE for computing the visual diff
|
|
|
|
modulePromise = mw.loader.using( [ 'ext.visualEditor.desktopArticleTarget' ].concat( pluginModules ) );
|
2017-07-13 13:48:32 +00:00
|
|
|
mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( oldId, newId, modulePromise, oldPageName, newPageName ).then( function ( visualDiffGenerator ) {
|
2018-03-04 14:45:33 +00:00
|
|
|
diffElement = new ve.ui.DiffElement( visualDiffGenerator(), { classes: [ 've-init-mw-diffPage-diff' ] } );
|
2017-06-09 13:45:59 +00:00
|
|
|
|
2018-03-04 14:45:33 +00:00
|
|
|
progress.$element.addClass( 'oo-ui-element-hidden' );
|
|
|
|
$visualDiff.append( diffElement.$element );
|
|
|
|
lastDiff = {
|
|
|
|
oldId: oldId,
|
|
|
|
newId: newId,
|
|
|
|
oldPageName: oldPageName,
|
|
|
|
newPageName: newPageName
|
|
|
|
};
|
2017-06-09 13:45:59 +00:00
|
|
|
|
|
|
|
diffElement.positionDescriptions();
|
|
|
|
} );
|
|
|
|
}
|
2017-08-10 15:24:54 +00:00
|
|
|
|
|
|
|
if ( history.replaceState ) {
|
|
|
|
uri.query.diffmode = mode;
|
|
|
|
history.replaceState( '', document.title, uri );
|
|
|
|
}
|
|
|
|
|
2017-06-09 13:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mw.hook( 'wikipage.diff' ).add( function () {
|
2018-03-04 14:45:33 +00:00
|
|
|
$wikitextDiff = $( 'table.diff[data-mw="interface"]' );
|
|
|
|
$wikitextDiff.before( $visualDiffContainer );
|
2017-06-09 13:45:59 +00:00
|
|
|
// The PHP widget was a ButtonGroupWidget, so replace with a
|
|
|
|
// ButtonSelectWidget instead of infusing.
|
|
|
|
reviewModeButtonSelect = new OO.ui.ButtonSelectWidget( {
|
|
|
|
items: [
|
|
|
|
new OO.ui.ButtonOptionWidget( { data: 'visual', icon: 'eye', label: mw.msg( 'visualeditor-savedialog-review-visual' ) } ),
|
|
|
|
new OO.ui.ButtonOptionWidget( { data: 'source', icon: 'wikiText', label: mw.msg( 'visualeditor-savedialog-review-wikitext' ) } )
|
|
|
|
]
|
|
|
|
} );
|
|
|
|
reviewModeButtonSelect.on( 'select', onReviewModeButtonSelectSelect );
|
|
|
|
$( '.ve-init-mw-diffPage-diffMode' ).empty().append( reviewModeButtonSelect.$element );
|
|
|
|
reviewModeButtonSelect.selectItemByData( mode );
|
|
|
|
} );
|
|
|
|
}() );
|