| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
( function () { |
| 18 |
const revCache = {}; |
| 19 |
|
| 20 |
mw.libs.ve = mw.libs.ve || {}; |
| 21 |
|
| 22 |
mw.libs.ve.diffLoader = { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
getModelFromResponse: function ( response, section ) { |
| 31 |
|
| 32 |
const targetClass = ve.init.mw.ArticleTarget, |
| 33 |
data = response ? ( response.visualeditor || response.visualeditoredit ) : null; |
| 34 |
if ( data && typeof data.content === 'string' ) { |
| 35 |
const doc = targetClass.static.parseDocument( data.content, 'visual', section, section !== null ); |
| 36 |
mw.libs.ve.stripRestbaseIds( doc ); |
| 37 |
return targetClass.static.createModelFromDom( doc, 'visual' ); |
| 38 |
} |
| 39 |
return null; |
| 40 |
}, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
fetchRevision: function ( revId, pageName, section, parseDocumentModulePromise ) { |
| 52 |
pageName = pageName || mw.config.get( 'wgRelevantPageName' ); |
| 53 |
parseDocumentModulePromise = parseDocumentModulePromise || $.Deferred().resolve().promise(); |
| 54 |
section = section !== undefined ? section : null; |
| 55 |
|
| 56 |
const cacheKey = revId + ( section !== null ? '/' + section : '' ); |
| 57 |
|
| 58 |
revCache[ cacheKey ] = revCache[ cacheKey ] || |
| 59 |
mw.libs.ve.targetLoader.requestParsoidData( |
| 60 |
pageName, |
| 61 |
{ oldId: revId, targetName: 'diff' }, |
| 62 |
false, |
| 63 |
|
| 64 |
true |
| 65 |
).then( |
| 66 |
( response ) => parseDocumentModulePromise.then( () => mw.libs.ve.diffLoader.getModelFromResponse( response, section ) ), |
| 67 |
() => { |
| 68 |
|
| 69 |
delete revCache[ cacheKey ]; |
| 70 |
|
| 71 |
return $.Deferred().rejectWith( this, arguments ); |
| 72 |
} |
| 73 |
); |
| 74 |
|
| 75 |
return revCache[ cacheKey ]; |
| 76 |
}, |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
getVisualDiffGeneratorPromise: function ( oldIdOrPromise, newIdOrPromise, parseDocumentModulePromise, oldPageName, newPageName ) { |
| 89 |
parseDocumentModulePromise = parseDocumentModulePromise || $.Deferred().resolve().promise(); |
| 90 |
oldPageName = oldPageName || mw.config.get( 'wgRelevantPageName' ); |
| 91 |
|
| 92 |
const oldRevPromise = typeof oldIdOrPromise === 'number' ? this.fetchRevision( oldIdOrPromise, oldPageName, null, parseDocumentModulePromise ) : oldIdOrPromise; |
| 93 |
const newRevPromise = typeof newIdOrPromise === 'number' ? this.fetchRevision( newIdOrPromise, newPageName, null, parseDocumentModulePromise ) : newIdOrPromise; |
| 94 |
|
| 95 |
return $.when( oldRevPromise, newRevPromise, parseDocumentModulePromise ).then( ( oldDoc, newDoc ) => { |
| 96 |
|
| 97 |
|
| 98 |
newDoc.getStore().merge( oldDoc.getStore() ); |
| 99 |
return () => new ve.dm.VisualDiff( oldDoc, newDoc ); |
| 100 |
} ); |
| 101 |
} |
| 102 |
|
| 103 |
}; |
| 104 |
}() ); |