/*! * VisualEditor DataModel MediaWiki-specific example data sets. * * @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * @class * @singleton * @ignore */ ve.dm.mwExample = {}; ve.dm.mwExample.createExampleDocument = function ( name, store ) { return ve.dm.example.createExampleDocumentFromObject( name, store, ve.dm.mwExample ); }; ve.dm.mwExample.MWTransclusion = { blockOpen: '
Hello, world!
', blockContentClipboard: 'Hello, world!
', inlineOpen: '', inlineOpenModified: '', inlineOpenFromData: '', inlineOpenClipboard: '', inlineOpenFromDataModified: '', inlineOpenModifiedClipboard: '' + ' ', inlineContent: '$1,234.00', inlineClose: '', mixed: '' + 'Foo', mixedFromData: '', mixedClipboard: ' ' + 'Foo', pairOne: 'foo
', pairTwo: 'foo
', pairFromData: '', pairClipboard: 'foo
', meta: '' + '\n' + '', metaFromData: '', metaClipboard: ' ' }; ve.dm.mwExample.MWTransclusion.blockData = { type: 'mwTransclusionBlock', attributes: { mw: { parts: [ { template: { target: { wt: 'Test', href: './Template:Test' }, params: { 1: { wt: 'Hello, world!' } }, i: 0 } } ] }, originalMw: '{"parts":[{"template":{"target":{"wt":"Test","href":"./Template:Test"},"params":{"1":{"wt":"Hello, world!"}},"i":0}}]}' } }; ve.dm.mwExample.MWTransclusion.inlineData = { type: 'mwTransclusionInline', attributes: { mw: { parts: [ { template: { target: { wt: 'Inline', href: './Template:Inline' }, params: { 1: { wt: '1,234' } }, i: 0 } } ] }, originalMw: '{"parts":[{"template":{"target":{"wt":"Inline","href":"./Template:Inline"},"params":{"1":{"wt":"1,234"}},"i":0}}]}' } }; ve.dm.mwExample.MWTransclusion.mixedDataOpen = { type: 'mwTransclusionInline', attributes: { mw: { parts: [ { template: { target: { wt: 'Inline', href: './Template:Inline' }, params: { 1: { wt: '5,678' } }, i: 0 } } ] }, originalMw: '{"parts":[{"template":{"target":{"wt":"Inline","href":"./Template:Inline"},"params":{"1":{"wt":"5,678"}},"i":0}}]}' } }; ve.dm.mwExample.MWTransclusion.mixedDataClose = { type: '/mwTransclusionInline' }; ve.dm.mwExample.MWTransclusion.blockParamsHash = OO.getHash( [ ve.dm.MWTransclusionNode.static.getHashObject( ve.dm.mwExample.MWTransclusion.blockData ), undefined ] ); ve.dm.mwExample.MWTransclusion.blockStoreItems = {}; ve.dm.mwExample.MWTransclusion.blockStoreItems[ ve.dm.IndexValueStore.prototype.indexOfValue( null, ve.dm.mwExample.MWTransclusion.blockParamsHash ) ] = $( ve.dm.mwExample.MWTransclusion.blockOpen + ve.dm.mwExample.MWTransclusion.blockContent ).toArray(); ve.dm.mwExample.MWTransclusion.inlineParamsHash = OO.getHash( [ ve.dm.MWTransclusionNode.static.getHashObject( ve.dm.mwExample.MWTransclusion.inlineData ), undefined ] ); ve.dm.mwExample.MWTransclusion.inlineStoreItems = {}; ve.dm.mwExample.MWTransclusion.inlineStoreItems[ ve.dm.IndexValueStore.prototype.indexOfValue( null, ve.dm.mwExample.MWTransclusion.inlineParamsHash ) ] = $( ve.dm.mwExample.MWTransclusion.inlineOpen + ve.dm.mwExample.MWTransclusion.inlineContent + ve.dm.mwExample.MWTransclusion.inlineClose ).toArray(); ve.dm.mwExample.MWTransclusion.mixedParamsHash = OO.getHash( [ ve.dm.MWTransclusionNode.static.getHashObject( ve.dm.mwExample.MWTransclusion.mixedDataOpen ), undefined ] ); ve.dm.mwExample.MWTransclusion.mixedStoreItems = {}; ve.dm.mwExample.MWTransclusion.mixedStoreItems[ ve.dm.IndexValueStore.prototype.indexOfValue( null, ve.dm.mwExample.MWTransclusion.mixedParamsHash ) ] = $( ve.dm.mwExample.MWTransclusion.mixed ).toArray(); ve.dm.mwExample.MWInternalLink = { absoluteHref: ve.resolveUrl( '/wiki/Foo/Bar', ve.dm.example.base ) }; ve.dm.mwExample.MWInternalLink.absoluteOpen = ''; ve.dm.mwExample.MWInternalLink.absoluteData = { type: 'link/mwInternal', attributes: { title: 'Foo/Bar', origTitle: 'Foo/Bar', normalizedTitle: 'Foo/Bar', lookupTitle: 'Foo/Bar', hrefPrefix: '' } }; ve.dm.mwExample.MWInternalSectionLink = { absoluteHref: ve.resolveUrl( '/wiki/Foo#Bar', ve.dm.example.base ) }; ve.dm.mwExample.MWInternalSectionLink.absoluteOpen = ''; ve.dm.mwExample.MWInternalSectionLink.absoluteData = { type: 'link/mwInternal', attributes: { title: 'Foo#Bar', origTitle: 'Foo#Bar', normalizedTitle: 'Foo#Bar', lookupTitle: 'Foo', hrefPrefix: '' } }; ve.dm.mwExample.MWBlockImage = { html: '', data: [ { type: 'mwBlockImage', attributes: { type: 'thumb', align: 'right', href: 'Foo', mediaClass: 'Image', src: ve.ce.minImgDataUri, width: 1, height: 2, resource: 'FooBar', originalClasses: 'mw-halign-right foobar', unrecognizedClasses: [ 'foobar' ] } }, { type: 'mwImageCaption' }, { type: 'paragraph', internal: { generated: 'wrapper' } }, 'a', 'b', 'c', { type: '/paragraph' }, { type: '/mwImageCaption' }, { type: '/mwBlockImage' } ], storeItems: { h5ca4c84da870e58f: ve.ce.minImgDataUri } }; ve.dm.mwExample.MWInlineImage = { html: 'Foo[[Bar]]Baz
'; ve.dm.mwExample.mwNowikiHtmlFromData = 'Foo[[Bar]]Baz
'; ve.dm.mwExample.withMeta = [ { type: 'paragraph', internal: { generated: 'wrapper' } }, { type: 'comment', attributes: { text: ' No content conversion ' } }, { type: '/comment' }, { type: '/paragraph' }, { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() }, { type: '/mwAlienMeta' }, { type: 'paragraph' }, 'F', 'o', 'o', { type: 'mwCategory', attributes: { hrefPrefix: './', category: 'Category:Bar', origCategory: 'Category:Bar', sortkey: '', origSortkey: '' } }, { type: '/mwCategory' }, 'B', 'a', 'r', { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() }, { type: '/mwAlienMeta' }, 'B', 'a', { type: 'comment', attributes: { text: ' inline ' } }, { type: '/comment' }, 'z', { type: '/paragraph' }, { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() }, { type: '/mwAlienMeta' }, { type: 'paragraph', internal: { generated: 'wrapper' } }, { type: 'comment', attributes: { text: 'barbaz' } }, { type: '/comment' }, { type: '/paragraph' }, { type: 'mwCategory', attributes: { hrefPrefix: './', category: 'Category:Foo foo', origCategory: 'Category:Foo_foo', sortkey: 'Bar baz#quux', origSortkey: 'Bar baz%23quux' } }, { type: '/mwCategory' }, { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() }, { type: '/mwAlienMeta' }, { type: 'internalList' }, { type: '/internalList' } ]; ve.dm.mwExample.withMetaPlainData = [ { type: 'paragraph' }, 'F', 'o', 'o', 'B', 'a', 'r', 'B', 'a', 'z', { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ]; ve.dm.mwExample.withMetaMetaData = [ [ { type: 'alienMeta', originalDomElements: $( '' ).toArray() }, { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() } ], undefined, undefined, undefined, [ { type: 'mwCategory', attributes: { hrefPrefix: './', category: 'Category:Bar', origCategory: 'Category:Bar', sortkey: '', origSortkey: '' } } ], undefined, undefined, [ { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() } ], undefined, [ { type: 'alienMeta', originalDomElements: $( '' ).toArray() } ], undefined, [ { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() }, { type: 'comment', attributes: { text: 'barbaz' } }, { type: 'mwCategory', attributes: { hrefPrefix: './', category: 'Category:Foo foo', origCategory: 'Category:Foo_foo', sortkey: 'Bar baz#quux', origSortkey: 'Bar baz%23quux' } }, { type: 'mwAlienMeta', originalDomElements: $( '' ).toArray() } ], undefined, undefined ]; ve.dm.mwExample.domToDataCases = { 'adjacent annotations (data-parsoid)': { preserveAnnotationDomElements: true, body: 'abc ' + 'dd', data: [ { type: 'paragraph', internal: { generated: 'wrapper' } }, [ 'a', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], [ 'b', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'b' ).toArray() } ] ], [ 'c', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'c' ).toArray() } ] ], ' ', [ 'd', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], [ 'd', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], modify: function ( model ) { var data = [ 'x', [ ve.dm.example.bold ] ], linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() ); model.data.data.splice( 3, 0, linearData.data[ 0 ] ); }, normalizedBody: 'abxc ' + 'dd', fromDataBody: 'abxc ' + 'dd' }, 'adjacent annotations (Parsoid IDs)': { preserveAnnotationDomElements: true, body: 'abc ' + 'dd', data: [ { type: 'paragraph', internal: { generated: 'wrapper' } }, [ 'a', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], [ 'b', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'b' ).toArray() } ] ], [ 'c', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'c' ).toArray() } ] ], ' ', [ 'd', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], [ 'd', [ { type: 'textStyle/bold', attributes: { nodeName: 'b' }, originalDomElements: $( 'a' ).toArray() } ] ], { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], modify: function ( model ) { var data = [ 'x', [ ve.dm.example.bold ] ], linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() ); model.data.data.splice( 3, 0, linearData.data[ 0 ] ); }, normalizedBody: 'abxc ' + 'dd', fromDataBody: 'abxc ' + 'dd' }, mwImage: { body: '' + ve.dm.mwExample.MWInlineImage.html + '
', data: [ { type: 'paragraph' }, ve.dm.mwExample.MWInlineImage.data, { type: '/mwInlineImage' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], ceHtml: '' + '' + '' + '' + '' + ve.dm.example.inlineSlug + '
', storeItems: ve.dm.mwExample.MWInlineImage.storeItems }, 'mwHeading and mwPreformatted nodes': { body: 'Bar', data: [ { type: 'mwHeading', attributes: { level: 2 } }, 'F', 'o', 'o', { type: '/mwHeading' }, { type: 'mwPreformatted' }, 'B', 'a', 'r', { type: '/mwPreformatted' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'mwTable with duplicate class attributes': { body: '
Foo |
Foo |
foo
' ).toArray() } }, 'mw:Transclusion containing only meta data': { body: ve.dm.mwExample.MWTransclusion.meta, fromDataBody: ve.dm.mwExample.MWTransclusion.metaFromData, clipboardBody: ve.dm.mwExample.MWTransclusion.metaClipboard, data: [ { internal: { generated: 'wrapper' }, type: 'paragraph' }, { type: 'mwTransclusionInline', attributes: { mw: { parts: [ { template: { target: { wt: 'Template:Echo', href: './Template:Echo' }, params: { 1: { wt: '[[Category:Page]]\n[[Category:Book]]' } }, i: 0 } } ] }, originalMw: '{"parts":[{"template":{"target":{"wt":"Template:Echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Page]]\\n[[Category:Book]]"}},"i":0}}]}' } }, { type: '/mwTransclusionInline' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'mw:Transclusion which is also a language annotation': { body: 'content', data: [ { type: 'paragraph', internal: { generated: 'wrapper' } }, { type: 'mwTransclusionInline', attributes: { mw: {}, originalMw: '{}' }, originalDomElements: $( 'content' ).toArray() }, { type: '/mwTransclusionInline' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], clipboardBody: 'content' }, 'mw:AlienBlockExtension': { body: '' + '' + '
', normalizedBody: '' + '' + '
', data: [ { type: 'paragraph' }, { type: 'mwAlienInlineExtension', attributes: { mw: { name: 'score', attrs: {}, body: { extsrc: '\\relative c\' { e d c d e e e }' } }, originalMw: '{"name":"score","attrs":{},"body":{"extsrc":"\\\\relative c\' { e d c d e e e }"}}' }, originalDomElements: $( '' ).toArray() }, { type: '/mwAlienInlineExtension' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], modify: function ( model ) { model.data.data[ 1 ].attributes.mw.body.extsrc = '\\relative c\' { d d d e e e }'; } }, 'internal link with ./ and ../': { body: '', head: '' + ve.dm.mwExample.MWInternalLink.absoluteOpen + 'Foo
', data: [ { type: 'paragraph' }, [ 'F', [ ve.dm.mwExample.MWInternalLink.absoluteData ] ], [ 'o', [ ve.dm.mwExample.MWInternalLink.absoluteData ] ], [ 'o', [ ve.dm.mwExample.MWInternalLink.absoluteData ] ], { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], normalizedBody: '', mwConfig: { wgArticlePath: '/wiki/$1' } }, 'internal link with absolute path and section': { body: '' + ve.dm.mwExample.MWInternalSectionLink.absoluteOpen + 'Foo
', data: [ { type: 'paragraph' }, [ 'F', [ ve.dm.mwExample.MWInternalSectionLink.absoluteData ] ], [ 'o', [ ve.dm.mwExample.MWInternalSectionLink.absoluteData ] ], [ 'o', [ ve.dm.mwExample.MWInternalSectionLink.absoluteData ] ], { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ], normalizedBody: '', mwConfig: { wgArticlePath: '/wiki/$1' } }, 'internal link with href set to ./': { body: '', head: 'Foo[1]Bar
' }, 'URL link': { body: '', data: [ { type: 'paragraph' }, [ 'm', [ { type: 'link/mwExternal', attributes: { href: 'http://www.mediawiki.org/', rel: 'mw:ExtLink' } } ] ], [ 'w', [ { type: 'link/mwExternal', attributes: { href: 'http://www.mediawiki.org/', rel: 'mw:ExtLink' } } ] ], { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, /* FIXME T185902: Temporarily commented out failing test case 'whitespace preservation with wrapped comments and language links': { body: 'Foo\n' + '\n' + '', data: [ { type: 'paragraph', internal: { generated: 'wrapper', metaItems: [ { originalDomElementsIndex: 'h188ab6af88887790', type: 'mwLanguage', attributes: { href: 'http://de.wikipedia.org/wiki/Foo' }, internal: { loadMetaParentIndex: 'hbc66e1df10d058e6', loadMetaParentOffset: 3 } }, { originalDomElementsIndex: 'h188ab6ff88887790', type: 'mwLanguage', attributes: { href: 'http://fr.wikipedia.org/wiki/Foo' }, internal: { loadMetaParentIndex: 'h4e7ce2a82b7ce627', loadMetaParentOffset: 6 } } ], whitespace: [ undefined, undefined, undefined, '\n' ] } }, 'F', 'o', 'o', { type: '/paragraph' }, { type: 'mwLanguage', attributes: { href: 'http://de.wikipedia.org/wiki/Foo' }, internal: { whitespace: [ '\n', undefined, undefined, '\n' ] } }, { type: '/mwLanguage' }, { type: 'mwLanguage', attributes: { href: 'http://fr.wikipedia.org/wiki/Foo' }, internal: { whitespace: [ '\n' ] } }, { type: '/mwLanguage' }, { type: 'internalList' }, { type: '/internalList' } ] },*/ 'document with meta elements': { body: 'Foo' + 'Bar' + 'Baz
' + '' + '' + '', clipboardBody: 'Foo' + 'Bar' + 'Ba z
' + ' ' + '' + '', head: 'a¢b¥™
', data: [ { type: 'paragraph' }, 'a', { type: 'mwEntity', attributes: { character: '¢' } }, { type: '/mwEntity' }, 'b', { type: 'mwEntity', attributes: { character: '¥' } }, { type: '/mwEntity' }, { type: 'mwEntity', attributes: { character: '™' } }, { type: '/mwEntity' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'wrapping with mw:Entity': { body: 'a¢b¥™', data: [ { type: 'paragraph', internal: { generated: 'wrapper' } }, 'a', { type: 'mwEntity', attributes: { character: '¢' } }, { type: '/mwEntity' }, 'b', { type: 'mwEntity', attributes: { character: '¥' } }, { type: '/mwEntity' }, { type: 'mwEntity', attributes: { character: '™' } }, { type: '/mwEntity' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'whitespace preservation with mw:Entity': { body: 'a b ¥\t™
', data: [ { type: 'paragraph', internal: { whitespace: [ undefined, ' ' ] } }, 'a', ' ', ' ', { type: 'mwEntity', attributes: { character: ' ' } }, { type: '/mwEntity' }, ' ', ' ', ' ', 'b', ' ', ' ', ' ', ' ', { type: 'mwEntity', attributes: { character: '¥' } }, { type: '/mwEntity' }, '\t', { type: 'mwEntity', attributes: { character: '™' } }, { type: '/mwEntity' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'category default sort key': { body: '', data: [ { type: 'mwDefaultSort', attributes: { content: 'foo' } }, { type: '/mwDefaultSort' }, { type: 'paragraph', internal: { generated: 'empty' } }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] }, 'thumb image': { body: ve.dm.mwExample.MWBlockImage.html, data: ve.dm.mwExample.MWBlockImage.data.concat( [ { type: 'internalList' }, { type: '/internalList' } ] ), storeItems: ve.dm.mwExample.MWBlockImage.storeItems }, 'attribute preservation does not crash due to text node split': { body: '', fromDataBody: '', head: 'Foo[[Bzr]]Baz
' }, 'mw:Nowiki unwraps when annotations modified': { data: ve.dm.mwExample.mwNowiki, modify: function ( model ) { model.data.data[ 7 ][ 1 ].push( model.getStore().index( ve.dm.example.createAnnotation( ve.dm.example.bold ) ) ); }, normalizedBody: 'Foo[[Bar]]Baz
' }, 'mwHeading with no content': { data: [ { type: 'mwHeading', attributes: { level: 1 } }, { type: '/mwHeading' }, { type: 'internalList' }, { type: '/internalList' } ], normalizedBody: '' }, 'mwHeading with whitespace content': { data: [ { type: 'mwHeading', attributes: { level: 2 } }, ' ', ' ', '\t', ' ', { type: '/mwHeading' }, { type: 'internalList' }, { type: '/internalList' } ], normalizedBody: '\t
' }, 'mwHeading containing metadata': { data: [ { type: 'mwHeading', attributes: { level: 3 } }, { type: 'alienMeta', originalDomElements: $( '' ).toArray() }, { type: '/alienMeta' }, { type: '/mwHeading' }, { type: 'internalList' }, { type: '/internalList' } ], normalizedBody: '' }, 'mwHeading containing alienated text': { data: [ { type: 'mwHeading', attributes: { level: 4 } }, { type: 'alienInline', originalDomElements: $( 'Alien' ).toArray() }, { type: '/alienInline' }, { type: '/mwHeading' }, { type: 'internalList' }, { type: '/internalList' } ], body: '