jenkins-bot has submitted this change and it was merged.

Change subject: Representation of red-linked images in VE
......................................................................


Representation of red-linked images in VE

The red-linked images in VE are now identifited as red links and image errors.
They can be changed and thereby be modified just as any other image on the 
editor.

Bug: T52788
Change-Id: I9cbb992c34d71b7073157fe276fee04e901845b1
---
M modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
M modules/ve-mw/dm/models/ve.dm.MWImageModel.js
M modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
3 files changed, 44 insertions(+), 17 deletions(-)

Approvals:
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
index 03fe2ea..b510646 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js
@@ -17,13 +17,14 @@
  * @param {Object} [config] Configuration options
  */
 ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
-       var type, align;
+       var type, align, isError;
 
        // Parent constructor
        ve.ce.BranchNode.call( this, model, config );
 
        type = this.model.getAttribute( 'type' );
        align = this.model.getAttribute( 'align' );
+       isError = this.model.getAttribute( 'isError' );
 
        // Properties
        this.captionVisible = false;
@@ -36,13 +37,19 @@
        //     <figcaption> this.caption.view.$element
 
        // Build DOM:
-       this.$a = $( '<a>' )
-               .addClass( 'image' )
-               .attr( 'href', this.getResolvedAttribute( 'href' ) );
-
        this.$image = $( '<img>' )
-               .attr( 'src', this.getResolvedAttribute( 'src' ) )
-               .appendTo( this.$a );
+               .attr( 'src', this.getResolvedAttribute( 'src' ) );
+
+       if ( isError ) {
+               this.$a = $( '<a>' )
+                       .addClass( 'new' )
+                       .text( this.model.getFilename() );
+       } else {
+               this.$a = $( '<a>' )
+                       .addClass( 'image' )
+                       .attr( 'href', this.getResolvedAttribute( 'href' ) )
+                       .append( this.$image );
+       }
 
        this.$element
                .append( this.$a )
diff --git a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js 
b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js
index 69c8ffb..f9c7905 100644
--- a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js
+++ b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js
@@ -448,6 +448,8 @@
        // Remove old classes
        delete editAttributes.originalClasses;
        delete editAttributes.unrecognizedClasses;
+       // Newly created images must have valid URLs, so remove the error 
attribute
+       delete editAttributes.isError;
 
        contentToInsert = [
                {
diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js 
b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
index c2d926f..0b5e5b5 100644
--- a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js
@@ -63,8 +63,18 @@
 
 ve.dm.MWBlockImageNode.static.blacklistedAnnotationTypes = [ 'link' ];
 
-ve.dm.MWBlockImageNode.static.getMatchRdfaTypes = function () {
-       return Object.keys( this.rdfaToType );
+ve.dm.MWBlockImageNode.static.matchRdfaTypes = [
+       // We're interested in all nodes that have mw:Image, even if they also 
have other mw:
+       // types. So we match all mw: types, then use a matchFunction to assert 
that mw:Image
+       // is in there.
+       /^mw:/
+];
+
+ve.dm.MWBlockImageNode.static.matchFunction = function ( domElement ) {
+       var nodetypes = ( domElement.getAttribute( 'typeof' ) || '' ).split( ' 
' ),
+               matchTypes = Object.keys( this.rdfaToType ),
+               storeType = OO.simpleArrayIntersection( nodetypes, matchTypes );
+       return storeType.length !== 0;
 };
 
 ve.dm.MWBlockImageNode.static.classAttributes = {
@@ -85,26 +95,34 @@
                } );
        }
 
-       var dataElement, newDimensions,
+       var dataElement, newDimensions, attributes,
                figure = domElements[0],
                imgWrapper = findChildren( figure, [ 'a', 'span' ] )[0] || null,
                img = imgWrapper && findChildren( imgWrapper, [ 'img' ] )[0] || 
null,
                caption = findChildren( figure, [ 'figcaption' ] )[0] || null,
                classAttr = figure.getAttribute( 'class' ),
-               typeofAttr = figure.getAttribute( 'typeof' ),
-               attributes = {
-                       type: this.rdfaToType[typeofAttr],
-                       href: imgWrapper && imgWrapper.getAttribute( 'href' ) 
|| '',
-                       src: img && img.getAttribute( 'src' ),
-                       resource: img && img.getAttribute( 'resource' )
-               },
+               typeofAttrs = figure.getAttribute( 'typeof' ).split( ' ' ),
+               errorIndex = typeofAttrs.indexOf( 'mw:Error' ),
                width = img && img.getAttribute( 'width' ),
                height = img && img.getAttribute( 'height' ),
                altText = img && img.getAttribute( 'alt' );
 
+       if ( errorIndex !== -1 ) {
+               typeofAttrs.splice( errorIndex, 1 );
+       }
+       attributes = {
+               type: this.rdfaToType[typeofAttrs[0]],
+               href: imgWrapper && imgWrapper.getAttribute( 'href' ) || '',
+               src: img && img.getAttribute( 'src' ),
+               resource: img && img.getAttribute( 'resource' )
+       };
+
        if ( altText !== null ) {
                attributes.alt = altText;
        }
+       if ( errorIndex !== -1 ) {
+               attributes.isError = true;
+       }
 
        this.setClassAttributes( attributes, classAttr );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/210625
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9cbb992c34d71b7073157fe276fee04e901845b1
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: SuchetaG <sucheta.ghos...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to