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

Change subject: [BREAKING CHANGE] Make MWExtensionInspector inherit from 
NodeInspector
......................................................................


[BREAKING CHANGE] Make MWExtensionInspector inherit from NodeInspector

Also fix up logic duplicated between ExtensionInspector
and LiveExtensionInspector.

BREAKING CHANGE:
* nodeModel property no longer exists, use NodeInspector's modelClasses
  property, which is an array.

Bug: T93592
Change-Id: Ib0131c9485a903d73b770090bf8a938056782ba3
---
M modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js
M modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js
M modules/ve-mw/ui/inspectors/ve.ui.MWGalleryInspector.js
M modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
4 files changed, 53 insertions(+), 82 deletions(-)

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



diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js
index 74924b8..17ea0f5 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js
@@ -33,7 +33,7 @@
 
 ve.ui.MWAlienExtensionInspector.static.icon = 'alienextension';
 
-ve.ui.MWAlienExtensionInspector.static.nodeModel = ve.dm.MWAlienExtensionNode;
+ve.ui.MWAlienExtensionInspector.static.modelClasses = [ 
ve.dm.MWAlienExtensionNode ];
 
 /* Methods */
 
@@ -55,7 +55,7 @@
        return 
ve.ui.MWAlienExtensionInspector.super.prototype.getSetupProcess.call( this, 
data )
                .next( function () {
                        var key, attributeInput, field,
-                               attributes = 
this.getFragment().getSelectedNode().getAttribute( 'mw' ).attrs;
+                               attributes = this.selectedNode.getAttribute( 
'mw' ).attrs;
 
                        if ( attributes && !ve.isEmptyObject( attributes ) ) {
                                for ( key in attributes ) {
@@ -76,7 +76,7 @@
                                }
                        }
 
-                       this.title.setLabel( 
this.getFragment().getSelectedNode().getExtensionName() );
+                       this.title.setLabel( 
this.selectedNode.getExtensionName() );
                }, this );
 };
 
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js
index f201c0e..a9afbf6 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js
@@ -10,32 +10,23 @@
  *
  * @class
  * @abstract
- * @extends ve.ui.FragmentInspector
+ * @extends ve.ui.NodeInspector
  *
  * @constructor
  * @param {Object} [config] Configuration options
  */
-ve.ui.MWExtensionInspector = function VeUiMWExtensionInspector( config ) {
+ve.ui.MWExtensionInspector = function VeUiMWExtensionInspector() {
        // Parent constructor
-       ve.ui.FragmentInspector.call( this, config );
+       ve.ui.MWExtensionInspector.super.apply( this, arguments );
 };
 
 /* Inheritance */
 
-OO.inheritClass( ve.ui.MWExtensionInspector, ve.ui.FragmentInspector );
+OO.inheritClass( ve.ui.MWExtensionInspector, ve.ui.NodeInspector );
 
 /* Static properties */
 
 ve.ui.MWExtensionInspector.static.placeholder = null;
-
-/**
- * Node class that this inspector inspects. Subclass of ve.dm.Node.
- * @property {Function}
- * @abstract
- * @static
- * @inheritable
- */
-ve.ui.MWExtensionInspector.static.nodeModel = null;
 
 /**
  * Extension is allowed to have empty contents
@@ -75,8 +66,6 @@
        } );
        this.input.$element.addClass( 've-ui-mwExtensionInspector-input' );
 
-       this.isBlock = !this.constructor.static.nodeModel.static.isContent;
-
        // Initialization
        this.form.$element.append( this.input.$element );
 };
@@ -100,17 +89,12 @@
                        var dir;
 
                        // Initialization
-                       this.node = this.getFragment().getSelectedNode();
                        this.whitespace = [ '', '' ];
 
-                       // Make sure we're inspecting the right type of node
-                       if ( !( this.node instanceof 
this.constructor.static.nodeModel ) ) {
-                               this.node = null;
-                       }
-                       if ( this.node ) {
-                               this.input.setValueAndWhitespace( 
this.node.getAttribute( 'mw' ).body.extsrc );
+                       if ( this.selectedNode ) {
+                               this.input.setValueAndWhitespace( 
this.selectedNode.getAttribute( 'mw' ).body.extsrc );
                        } else {
-                               if ( this.isBlock ) {
+                               if ( 
!this.constructor.static.modelClasses[0].static.isContent ) {
                                        // New nodes should use linebreaks for 
blocks
                                        this.input.setWhitespace( [ '\n', '\n' 
] );
                                }
@@ -143,7 +127,7 @@
                .first( function () {
                        if ( this.constructor.static.allowedEmpty || 
this.input.getInnerValue() !== '' ) {
                                this.insertOrUpdateNode();
-                       } else if ( this.node && 
!this.constructor.static.allowedEmpty ) {
+                       } else if ( this.selectedNode && 
!this.constructor.static.allowedEmpty ) {
                                // Content has been emptied on a node which 
isn't allowed to
                                // be empty, so delete it.
                                this.removeNode();
@@ -152,38 +136,52 @@
 };
 
 /**
+ * Create an new data element for the model class associated with this 
inspector
+ *
+ * @returns {Object} Element data
+ */
+ve.ui.MWExtensionInspector.prototype.getNewElement = function () {
+       // Extension inspectors which create elements should either match
+       // a single modelClass or override this method.
+       var modelClass = this.constructor.static.modelClasses[0];
+       return {
+               type: modelClass.static.name,
+               attributes: {
+                       mw: {
+                               name: modelClass.static.extensionName,
+                               attrs: {},
+                               body: {
+                                       extsrc: ''
+                               }
+                       }
+               }
+       };
+};
+
+/**
  * Insert or update the node in the document model from the new values
  */
 ve.ui.MWExtensionInspector.prototype.insertOrUpdateNode = function () {
-       var mwData,
+       var mwData, element,
                surfaceModel = this.getFragment().getSurface();
-       if ( this.node ) {
-               mwData = ve.copy( this.node.getAttribute( 'mw' ) );
+       if ( this.selectedNode ) {
+               mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) );
                this.updateMwData( mwData );
                surfaceModel.change(
                        ve.dm.Transaction.newFromAttributeChanges(
                                surfaceModel.getDocument(),
-                               this.node.getOuterRange().start,
+                               this.selectedNode.getOuterRange().start,
                                { mw: mwData }
                        )
                );
        } else {
-               mwData = {
-                       name: 
this.constructor.static.nodeModel.static.extensionName,
-                       attrs: {},
-                       body: {}
-               };
-               this.updateMwData( mwData );
+               element = this.getNewElement();
+               this.updateMwData( element.attributes.mw );
                // Collapse returns a new fragment, so update this.fragment
                this.fragment = this.getFragment().collapseToEnd();
                this.getFragment().insertContent( [
-                       {
-                               type: 
this.constructor.static.nodeModel.static.name,
-                               attributes: {
-                                       mw: mwData
-                               }
-                       },
-                       { type: '/' + 
this.constructor.static.nodeModel.static.name }
+                       element,
+                       { type: '/' + element.type }
                ] );
        }
 };
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWGalleryInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWGalleryInspector.js
index 7172090..d8ec8f0 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWGalleryInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWGalleryInspector.js
@@ -14,9 +14,9 @@
  * @constructor
  * @param {Object} [config] Configuration options
  */
-ve.ui.MWGalleryInspector = function VeUiMWGalleryInspector( config ) {
+ve.ui.MWGalleryInspector = function VeUiMWGalleryInspector() {
        // Parent constructor
-       ve.ui.MWExtensionInspector.call( this, config );
+       ve.ui.MWGalleryInspector.super.apply( this, arguments );
 
        this.$element.addClass( 've-ui-mwGalleryInspector' );
 };
@@ -36,7 +36,7 @@
 ve.ui.MWGalleryInspector.static.title =
        OO.ui.deferMsg( 'visualeditor-mwgalleryinspector-title' );
 
-ve.ui.MWGalleryInspector.static.nodeModel = ve.dm.MWGalleryNode;
+ve.ui.MWGalleryInspector.static.modelClasses = [ ve.dm.MWGalleryNode ];
 
 /* Methods */
 
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
index e536341..23de26a 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
@@ -15,9 +15,9 @@
  * @constructor
  * @param {Object} [config] Configuration options
  */
-ve.ui.MWLiveExtensionInspector = function VeUiMWLiveExtensionInspector( config 
) {
+ve.ui.MWLiveExtensionInspector = function VeUiMWLiveExtensionInspector() {
        // Parent constructor
-       ve.ui.MWExtensionInspector.call( this, config );
+       ve.ui.MWLiveExtensionInspector.super.apply( this, arguments );
 
        // Late bind onChangeHandler to a debounced updatePreview
        this.onChangeHandler = ve.debounce( this.updatePreview.bind( this ), 
250 );
@@ -27,32 +27,7 @@
 
 OO.inheritClass( ve.ui.MWLiveExtensionInspector, ve.ui.MWExtensionInspector );
 
-/* Static properties */
-
-/**
- * Name of extension in the mw data, if different from inspector name
- *
- * @static
- * @property {string}
- * @inheritable
- */
-ve.ui.MWLiveExtensionInspector.static.mwName = null;
-
 /* Methods */
-
-/**
- * Create an MW data object for a new node
- * @returns {Object} MW data
- */
-ve.ui.MWLiveExtensionInspector.prototype.getNewMwData = function () {
-       return {
-               name: this.constructor.static.mwName || 
this.constructor.static.name,
-               attrs: {},
-               body: {
-                       extsrc: ''
-               }
-       };
-};
 
 /**
  * @inheritdoc
@@ -60,25 +35,23 @@
 ve.ui.MWLiveExtensionInspector.prototype.getSetupProcess = function ( data ) {
        return 
ve.ui.MWLiveExtensionInspector.super.prototype.getSetupProcess.call( this, data 
)
                .next( function () {
+                       var element = this.getNewElement();
                        // Initialization
                        this.getFragment().getSurface().pushStaging();
 
-                       if ( !this.node ) {
+                       if ( !this.selectedNode ) {
                                // Create a new node
                                // collapseToEnd returns a new fragment
                                this.fragment = 
this.getFragment().collapseToEnd().insertContent( [
-                                       {
-                                               type: 
this.constructor.static.nodeModel.static.name,
-                                               attributes: { mw: 
this.getNewMwData() }
-                                       },
-                                       { type: '/' + 
this.constructor.static.nodeModel.static.name }
+                                       element,
+                                       { type: '/' + element.type }
                                ] );
                                // Check if the node was inserted at a 
structural offset and wrapped in a paragraph
                                if ( 
this.getFragment().getSelection().getRange().getLength() === 4 ) {
                                        this.fragment = 
this.getFragment().adjustLinearSelection( 1, -1 );
                                }
                                this.getFragment().select();
-                               this.node = 
this.getFragment().getSelectedNode();
+                               this.selectedNode = 
this.getFragment().getSelectedNode();
                        }
                        this.input.on( 'change', this.onChangeHandler );
                }, this );
@@ -115,7 +88,7 @@
  * Update the node rendering to reflect the current content in the inspector.
  */
 ve.ui.MWLiveExtensionInspector.prototype.updatePreview = function () {
-       var mwData = ve.copy( this.node.getAttribute( 'mw' ) );
+       var mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) );
 
        mwData.body.extsrc = this.input.getValue();
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib0131c9485a903d73b770090bf8a938056782ba3
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@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