diff --git a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js index bd01fdb984..01843db06b 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js @@ -136,7 +136,8 @@ ve.dm.MWImageModel.static.createImageNode = function ( attributes, imageType ) { align: 'default', width: defaultThumbSize, mediaType: 'BITMAP', - defaultSize: true + defaultSize: true, + imageClassAttr: 'mw-file-element' }, attributes ); if ( attrs.defaultSize ) { diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js index aefd10a6bf..5813297091 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js @@ -185,8 +185,7 @@ ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter ) imgWrapper.setAttribute( 'href', attributes.href ); } - // At the moment, preserving this is only relevant on mw:Error spans - if ( attributes.isError && attributes.imageClassAttr ) { + if ( attributes.imageClassAttr ) { // eslint-disable-next-line mediawiki/class-doc img.className = attributes.imageClassAttr; } diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js index cd55a493bb..a356d8f53e 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js @@ -113,7 +113,9 @@ ve.dm.MWGalleryImageNode.static.toDataElement = function ( domElements, converte width: width !== null && width !== '' ? +width : null, height: height !== null && height !== '' ? +height : null, isError: isError, - errorText: errorText + errorText: errorText, + imageClassAttr: img.getAttribute( 'class' ), + imgWrapperClassAttr: a.getAttribute( 'class' ) } }; @@ -150,12 +152,20 @@ ve.dm.MWGalleryImageNode.static.toDomElements = function ( data, doc, converter a.setAttribute( 'href', attributes.href ); } else { a.setAttribute( 'href', attributes.resource ); - a.setAttribute( 'class', 'mw-file-description' ); + } + + if ( attributes.imageClassAttr ) { + // eslint-disable-next-line mediawiki/class-doc + img.className = attributes.imageClassAttr; + } + + if ( attributes.imgWrapperClassAttr ) { + // eslint-disable-next-line mediawiki/class-doc + a.className = attributes.imgWrapperClassAttr; } img.setAttribute( 'resource', attributes.resource ); if ( attributes.isError ) { - img.classList.add( 'mw-broken-media' ); var filename = mw.libs.ve.normalizeParsoidResourceName( attributes.resource || '' ); img.appendChild( doc.createTextNode( attributes.errorText ? attributes.errorText : filename ) ); } else { diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js index dd3e441c00..2a44aef3b6 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js @@ -207,25 +207,26 @@ ve.dm.MWInlineImageNode.static.toDomElements = function ( dataElement, doc, conv if ( attributes.href ) { firstChild = doc.createElement( 'a' ); firstChild.setAttribute( 'href', attributes.href ); - if ( attributes.imgWrapperClassAttr ) { - // eslint-disable-next-line mediawiki/class-doc - firstChild.className = attributes.imgWrapperClassAttr; - } } else { firstChild = doc.createElement( 'span' ); } + if ( attributes.imgWrapperClassAttr ) { + // eslint-disable-next-line mediawiki/class-doc + firstChild.className = attributes.imgWrapperClassAttr; + } + + if ( attributes.imageClassAttr ) { + // eslint-disable-next-line mediawiki/class-doc + img.className = attributes.imageClassAttr; + } + if ( attributes.isError ) { if ( converter.isForPreview() ) { firstChild.classList.add( 'new' ); } var filename = mw.libs.ve.normalizeParsoidResourceName( attributes.resource || '' ); img.appendChild( doc.createTextNode( attributes.errorText ? attributes.errorText : filename ) ); - // At the moment, preserving this is only relevant on mw:Error spans - if ( attributes.imageClassAttr ) { - // eslint-disable-next-line mediawiki/class-doc - img.className = attributes.imageClassAttr; - } } container.appendChild( firstChild ); diff --git a/modules/ve-mw/tests/dm/ve.dm.mwExample.js b/modules/ve-mw/tests/dm/ve.dm.mwExample.js index f965e1ad88..d2dd8222ec 100644 --- a/modules/ve-mw/tests/dm/ve.dm.mwExample.js +++ b/modules/ve-mw/tests/dm/ve.dm.mwExample.js @@ -876,6 +876,8 @@ ve.dm.mwExample.domToDataCases = { height: 120, resource: './File:!Example.jpg', href: './Special:FilePath/!Example.jpg', + imageClassAttr: 'mw-broken-media', + imgWrapperClassAttr: null, src: null, isError: true, errorText: 'File:!Example.jpg' @@ -924,6 +926,8 @@ ve.dm.mwExample.domToDataCases = { height: 120, resource: './File:Example.jpg', href: null, + imageClassAttr: null, + imgWrapperClassAttr: 'mw-file-description', src: ve.ce.minImgDataUri, isError: false, errorText: null @@ -972,6 +976,8 @@ ve.dm.mwExample.domToDataCases = { height: 120, resource: './File:Example.jpg', href: null, + imageClassAttr: null, + imgWrapperClassAttr: 'mw-file-description', src: ve.ce.minImgDataUri, isError: false, errorText: null @@ -1020,6 +1026,8 @@ ve.dm.mwExample.domToDataCases = { height: 120, resource: './Foo', href: null, + imageClassAttr: null, + imgWrapperClassAttr: 'mw-file-description', src: ve.ce.minImgDataUri, isError: false, errorText: null @@ -1058,6 +1066,8 @@ ve.dm.mwExample.domToDataCases = { height: 120, resource: './Foo', href: null, + imageClassAttr: null, + imgWrapperClassAttr: 'mw-file-description', src: ve.ce.minImgDataUri, isError: false, errorText: null diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js index a9b18ed08c..e69c31258d 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js @@ -436,7 +436,9 @@ ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) { captionDocument: this.createCaptionDocument( imageCaptionNode ), tagName: image.getAttribute( 'tagName' ), isError: image.getAttribute( 'isError' ), - errorText: image.getAttribute( 'errorText' ) + errorText: image.getAttribute( 'errorText' ), + imageClassAttr: image.getAttribute( 'imageClassAttr' ), + imgWrapperClassAttr: image.getAttribute( 'imgWrapperClassAttr' ) } ); } @@ -683,7 +685,8 @@ ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) { thumbUrl: thumbUrls[ title ].thumbUrl, captionDocument: this.createCaptionDocument( null ), isError: false, - errorText: null + errorText: null, + imageClassAttr: 'mw-file-element' }, config ) ); delete this.selectedFilenames[ title ]; } @@ -1049,7 +1052,9 @@ ve.ui.MWGalleryDialog.prototype.insertOrUpdateNode = function () { width: size.width, tagName: galleryItem.tagName, isError: galleryItem.isError, - errorText: galleryItem.errorText + errorText: galleryItem.errorText, + imageClassAttr: galleryItem.imageClassAttr, + imgWrapperClassAttr: galleryItem.imgWrapperClassAttr }; return [ diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index 5e920405c4..30453bce13 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -899,7 +899,8 @@ ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () { mediaType: info.mediatype, type: 'thumb', align: 'default', - defaultSize: true + defaultSize: true, + imageClassAttr: 'mw-file-element' }, this.getFragment().getDocument() ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWGalleryItemWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWGalleryItemWidget.js index 37541ba3a7..8745c281f8 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWGalleryItemWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWGalleryItemWidget.js @@ -33,6 +33,8 @@ ve.ui.MWGalleryItemWidget = function VeUiMWGalleryItemWidget( imageInfo, config this.highlighted = false; this.tagName = imageInfo.tagName; this.isError = imageInfo.isError; + this.imageClassAttr = imageInfo.imageClassAttr; + this.imgWrapperClassAttr = imageInfo.imgWrapperClassAttr; // Configuration initialization config = config || {};