From 5104f63cf3a3a4878bd71c629065111646057aae Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 27 Jul 2017 13:26:55 +0100 Subject: [PATCH] Support visual diffs on Special:ComparePages Bug: T171821 Change-Id: I13fe8349ab2d078b172637c931f1b80f7108c927 --- extension.json | 3 ++- .../ve-mw/init/ve.init.mw.DiffPage.init.js | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/extension.json b/extension.json index cb88de19d6..41984bb529 100644 --- a/extension.json +++ b/extension.json @@ -1877,7 +1877,8 @@ "dependencies": [ "oojs-ui", "oojs-ui.styles.icons-alerts", - "oojs-ui.styles.icons-editing-advanced" + "oojs-ui.styles.icons-editing-advanced", + "mediawiki.Uri" ], "messages": [ "visualeditor-savedialog-review-visual", diff --git a/modules/ve-mw/init/ve.init.mw.DiffPage.init.js b/modules/ve-mw/init/ve.init.mw.DiffPage.init.js index 8ec60eb0e1..8fd83226b4 100644 --- a/modules/ve-mw/init/ve.init.mw.DiffPage.init.js +++ b/modules/ve-mw/init/ve.init.mw.DiffPage.init.js @@ -9,7 +9,7 @@ var $visualDiff, reviewModeButtonSelect, revCache = {}, - pageName = mw.config.get( 'wgRelevantPageName' ), + uri = new mw.Uri(), mode = 'source', conf = mw.config.get( 'wgVisualEditorConfig' ), pluginModules = conf.pluginModules.filter( mw.loader.getState ); @@ -25,28 +25,37 @@ return null; } - function fetchRevision( revId ) { - if ( !revCache[ revId ] ) { - revCache[ revId ] = mw.libs.ve.targetLoader.requestParsoidData( pageName, revId, 'diff' ); + function fetchRevision( pageName, revId ) { + revCache[ pageName ] = revCache[ pageName ] || {}; + if ( !revCache[ pageName ][ revId ] ) { + revCache[ pageName ][ revId ] = mw.libs.ve.targetLoader.requestParsoidData( pageName, revId, 'diff' ); } - return revCache[ revId ]; + return revCache[ pageName ][ revId ]; } function onReviewModeButtonSelectSelect( item ) { var oldRevPromise, newRevPromise, modulePromise, progress, + oldPageName, newPageName, $revSlider = $( '.mw-revslider-container' ), $wikitextDiff = $( 'table.diff[data-mw="interface"]' ), oldId = mw.config.get( 'wgDiffOldId' ), newId = mw.config.get( 'wgDiffNewId' ); + if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'ComparePages' ) { + oldPageName = newPageName = mw.config.get( 'wgRelevantPageName' ); + } else { + oldPageName = uri.query.page1; + newPageName = uri.query.page2; + } + mode = item.getData(); if ( mode === 'visual' ) { progress = new OO.ui.ProgressBarWidget( { classes: [ 've-init-mw-diffPage-loading' ] } ); $wikitextDiff.addClass( 'oo-ui-element-hidden' ); $wikitextDiff.before( progress.$element ); - oldRevPromise = fetchRevision( oldId ); - newRevPromise = fetchRevision( newId ); + oldRevPromise = fetchRevision( oldPageName, oldId ); + newRevPromise = fetchRevision( newPageName, newId ); // TODO: Load a smaller subset of VE for computing the visual diff modulePromise = mw.loader.using( [ 'ext.visualEditor.desktopArticleTarget' ].concat( pluginModules ) ); $.when( oldRevPromise, newRevPromise, modulePromise ).then( function ( oldResponse, newResponse ) {