Merge "Preserve classes on all file elements, not just broken images"

This commit is contained in:
jenkins-bot 2023-05-12 10:30:52 +00:00 committed by Gerrit Code Review
commit 5751edb0e0
8 changed files with 48 additions and 19 deletions

View file

@ -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 ) {

View file

@ -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;
}

View file

@ -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 {

View file

@ -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 );

View file

@ -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

View file

@ -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 [

View file

@ -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()
);

View file

@ -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 || {};