From bdb4a8a149cd8985932db651aef4d45196b96986 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 23 Jan 2014 15:07:13 +0000 Subject: [PATCH] Simplify toDataElement in MW As per I54943588c5cc2 in core. Change-Id: Ia40e7327c4ce07a79d64a6d5b1ff0d7acec55171 --- .../ve-mw/dm/annotations/ve.dm.MWExternalLinkAnnotation.js | 1 - .../ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js | 2 +- modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js | 2 +- modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js | 2 +- modules/ve-mw/dm/metaitems/ve.dm.MWLanguageMetaItem.js | 2 +- modules/ve-mw/dm/metaitems/ve.dm.MWNoEditSectionMetaItem.js | 4 ---- modules/ve-mw/dm/metaitems/ve.dm.MWTOCDisableMetaItem.js | 4 ---- modules/ve-mw/dm/metaitems/ve.dm.MWTOCForceMetaItem.js | 4 ---- modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js | 2 +- modules/ve-mw/dm/nodes/ve.dm.MWHeadingNode.js | 6 ------ modules/ve-mw/dm/nodes/ve.dm.MWImageCaptionNode.js | 5 ----- modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js | 2 +- modules/ve-mw/dm/nodes/ve.dm.MWPreformattedNode.js | 4 ---- 13 files changed, 6 insertions(+), 34 deletions(-) diff --git a/modules/ve-mw/dm/annotations/ve.dm.MWExternalLinkAnnotation.js b/modules/ve-mw/dm/annotations/ve.dm.MWExternalLinkAnnotation.js index 07f170012f..92f7f2d329 100644 --- a/modules/ve-mw/dm/annotations/ve.dm.MWExternalLinkAnnotation.js +++ b/modules/ve-mw/dm/annotations/ve.dm.MWExternalLinkAnnotation.js @@ -37,7 +37,6 @@ ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = [ 'mw:ExtLink' ]; ve.dm.MWExternalLinkAnnotation.static.toDataElement = function ( domElements ) { var parentResult = ve.dm.LinkAnnotation.static.toDataElement.apply( this, arguments ); - parentResult.type = 'link/mwExternal'; parentResult.attributes.rel = domElements[0].getAttribute( 'rel' ); return parentResult; }; diff --git a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js index 7255a53ac1..242cac6c76 100644 --- a/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js +++ b/modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js @@ -64,7 +64,7 @@ ve.dm.MWInternalLinkAnnotation.static.toDataElement = function ( domElements, co normalizedTitle = ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( matches[2] ); return { - 'type': 'link/mwInternal', + 'type': this.name, 'attributes': { 'hrefPrefix': matches[1], 'title': decodeURIComponent( matches[2] ).replace( /_/g, ' ' ), diff --git a/modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js b/modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js index 9cb8981e19..bffb974b70 100644 --- a/modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js +++ b/modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js @@ -33,7 +33,7 @@ ve.dm.MWNowikiAnnotation.static.matchRdfaTypes = [ 'mw:Nowiki' ]; ve.dm.MWNowikiAnnotation.static.toDataElement = function ( domElements ) { return { - 'type': 'mwNowiki', + 'type': this.name, 'attributes': { 'originalDomElements': ve.copy( domElements ) } diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js index eec6ce1880..b5ef93b921 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWCategoryMetaItem.js @@ -38,7 +38,7 @@ ve.dm.MWCategoryMetaItem.static.toDataElement = function ( domElements ) { matches = href.match( /^((?:\.\.?\/)*)(.*?)(?:#(.*))?$/ ), rawSortkey = matches[3] || ''; return { - 'type': 'mwCategory', + 'type': this.name, 'attributes': { 'hrefPrefix': matches[1], 'category': decodeURIComponent( matches[2] ).replace( /_/g, ' ' ), diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWLanguageMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWLanguageMetaItem.js index c0b92d6e94..c93ad7d044 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWLanguageMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWLanguageMetaItem.js @@ -33,7 +33,7 @@ ve.dm.MWLanguageMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/Language' ]; ve.dm.MWLanguageMetaItem.static.toDataElement = function ( domElements ) { var href = domElements[0].getAttribute( 'href' ); return { - 'type': 'mwLanguage', + 'type': this.name, 'attributes': { 'href': href } diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWNoEditSectionMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWNoEditSectionMetaItem.js index 9aea0cc02f..2d7dba8a24 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWNoEditSectionMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWNoEditSectionMetaItem.js @@ -32,10 +32,6 @@ ve.dm.MWNoEditSectionMetaItem.static.matchTagNames = [ 'meta' ]; ve.dm.MWNoEditSectionMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/noeditsection' ]; -ve.dm.MWNoEditSectionMetaItem.static.toDataElement = function () { - return { 'type': this.name }; -}; - ve.dm.MWNoEditSectionMetaItem.static.toDomElements = function ( dataElement, doc ) { var meta = doc.createElement( 'meta' ); meta.setAttribute( 'property', 'mw:PageProp/noeditsection' ); diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWTOCDisableMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWTOCDisableMetaItem.js index 301130bd2b..987754c703 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWTOCDisableMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWTOCDisableMetaItem.js @@ -32,10 +32,6 @@ ve.dm.MWTOCDisableMetaItem.static.matchTagNames = [ 'meta' ]; ve.dm.MWTOCDisableMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/notoc' ]; -ve.dm.MWTOCDisableMetaItem.static.toDataElement = function () { - return { 'type': this.name }; -}; - ve.dm.MWTOCDisableMetaItem.static.toDomElements = function ( dataElement, doc ) { var meta = doc.createElement( 'meta' ); meta.setAttribute( 'property', 'mw:PageProp/notoc' ); diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWTOCForceMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWTOCForceMetaItem.js index 5943031b50..d57452386e 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWTOCForceMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWTOCForceMetaItem.js @@ -32,10 +32,6 @@ ve.dm.MWTOCForceMetaItem.static.matchTagNames = [ 'meta' ]; ve.dm.MWTOCForceMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/forcetoc' ]; -ve.dm.MWTOCForceMetaItem.static.toDataElement = function () { - return { 'type': this.name }; -}; - ve.dm.MWTOCForceMetaItem.static.toDomElements = function ( dataElement, doc ) { var meta = doc.createElement( 'meta' ); meta.setAttribute( 'property', 'mw:PageProp/forcetoc' ); diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js index f41da422cf..c4a820d7ba 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js @@ -34,7 +34,7 @@ ve.dm.MWEntityNode.static.matchTagNames = [ 'span' ]; ve.dm.MWEntityNode.static.matchRdfaTypes = [ 'mw:Entity' ]; ve.dm.MWEntityNode.static.toDataElement = function ( domElements ) { - return { 'type': 'mwEntity', 'attributes': { 'character': domElements[0].textContent } }; + return { 'type': this.name, 'attributes': { 'character': domElements[0].textContent } }; }; ve.dm.MWEntityNode.static.toDomElements = function ( dataElement, doc ) { diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWHeadingNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWHeadingNode.js index c61d2d3264..773d281b00 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWHeadingNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWHeadingNode.js @@ -29,12 +29,6 @@ ve.dm.MWHeadingNode.static.name = 'mwHeading'; ve.dm.MWHeadingNode.static.suggestedParentNodeTypes = [ 'document' ]; -ve.dm.MWHeadingNode.static.toDataElement = function () { - var parentElement = ve.dm.HeadingNode.static.toDataElement.apply( this, arguments ); - parentElement.type = 'mwHeading'; - return parentElement; -}; - /* Registration */ ve.dm.modelRegistry.register( ve.dm.MWHeadingNode ); diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWImageCaptionNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWImageCaptionNode.js index a4d2c1f54f..de7c8d9e9e 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWImageCaptionNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWImageCaptionNode.js @@ -27,11 +27,6 @@ ve.dm.MWImageCaptionNode.static.matchTagNames = []; ve.dm.MWImageCaptionNode.static.parentNodeTypes = [ 'mwBlockImage' ]; -ve.dm.MWImageCaptionNode.static.toDataElement = function () { - // Probably not needed - return { 'type': 'mwImageCaption' }; -}; - ve.dm.MWImageCaptionNode.static.toDomElements = function ( dataElement, doc ) { return [ doc.createElement( 'figcaption' ) ]; }; diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js index bf41f7d834..e11368c965 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js @@ -40,7 +40,7 @@ ve.dm.MWNumberedExternalLinkNode.static.matchFunction = function ( element ) { ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements ) { return { - 'type': 'link/mwNumberedExternal', + 'type': this.name, 'attributes': { 'href': domElements[0].getAttribute( 'href' ) } diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWPreformattedNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWPreformattedNode.js index 403c425df7..aaa73dda0d 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWPreformattedNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWPreformattedNode.js @@ -29,10 +29,6 @@ ve.dm.MWPreformattedNode.static.name = 'mwPreformatted'; ve.dm.MWPreformattedNode.static.suggestedParentNodeTypes = [ 'document' ]; -ve.dm.MWPreformattedNode.static.toDataElement = function () { - return { 'type': 'mwPreformatted' }; -}; - /* Registration */ ve.dm.modelRegistry.register( ve.dm.MWPreformattedNode );