Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/268854

Change subject: Use widgets for wiki-template-namep, boolean and URL template 
fields
......................................................................

Use widgets for wiki-template-namep, boolean and URL template fields

Bug: T55613
Change-Id: If1a9720a17c0418db280218918b270a4dc920289
---
M extension.json
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js
4 files changed, 79 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/54/268854/1

diff --git a/extension.json b/extension.json
index 7ed11cc..24058b2 100644
--- a/extension.json
+++ b/extension.json
@@ -1581,6 +1581,7 @@
                                "visualeditor-dialog-transclusion-param-info",
                                
"visualeditor-dialog-transclusion-param-info-missing",
                                "visualeditor-dialog-transclusion-placeholder",
+                               "visualeditor-dialog-transclusion-raw-fallback",
                                
"visualeditor-dialog-transclusion-remove-content",
                                "visualeditor-dialog-transclusion-remove-param",
                                
"visualeditor-dialog-transclusion-remove-template",
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index 7ae811a..dc6e5f6 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -213,6 +213,7 @@
        "visualeditor-dialog-transclusion-param-info": "Field description",
        "visualeditor-dialog-transclusion-param-info-missing": "No field 
description available",
        "visualeditor-dialog-transclusion-placeholder": "Add a template",
+       "visualeditor-dialog-transclusion-raw-fallback": "Fall back to plain 
wikitext",
        "visualeditor-dialog-transclusion-remove-content": "Remove content",
        "visualeditor-dialog-transclusion-remove-param": "Remove field",
        "visualeditor-dialog-transclusion-remove-template": "Remove template",
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index 2a38f31..f12ef52 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -223,6 +223,7 @@
        "visualeditor-dialog-transclusion-param-info": "Title of button that 
hides and shows parameter descriptions",
        "visualeditor-dialog-transclusion-param-info-missing": "Title of button 
that hides and shows parameter descriptions when no description is available",
        "visualeditor-dialog-transclusion-placeholder": "Label for section with 
options for adding a new template to a multi part 
transclusion.\n{{Identical|Add template}}",
+       "visualeditor-dialog-transclusion-raw-fallback": "Label of the button 
that converts complex validation-required type-based inputs back into plain 
wikitext inputs.",
        "visualeditor-dialog-transclusion-remove-content": "Label for button 
that removes content between transclusion parts",
        "visualeditor-dialog-transclusion-remove-param": "Label for button that 
removes a parameter from a template",
        "visualeditor-dialog-transclusion-remove-template": "Label for button 
that removes a template from a transclusion.\n{{Identical|Remove template}}",
diff --git a/modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js 
b/modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js
index ac48606..e3641c2 100644
--- a/modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js
+++ b/modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js
@@ -28,7 +28,9 @@
        OO.ui.PageLayout.call( this, name, config );
 
        // Properties
+       this.edited = false;
        this.parameter = parameter;
+       this.originalValue = parameter.getValue();
        this.spec = parameter.getTemplate().getSpec();
        this.defaultValue = parameter.getDefaultValue();
        this.exampleValue = parameter.getExampleValue();
@@ -39,6 +41,12 @@
        this.$field = $( '<div>' );
        this.$more = $( '<div>' );
        this.$description = $( '<div>' );
+
+       this.rawFallbackButton = new OO.ui.ButtonWidget( {
+               framed: false,
+               icon: 'advanced',
+               title: ve.msg( 'visualeditor-dialog-transclusion-raw-fallback' )
+       } ).connect( this, { click: 'onRawFallbackButtonClick' } );
 
        this.valueInput = this.createValueInput()
                .setValue( this.parameter.getValue() )
@@ -73,8 +81,6 @@
                classes: [ 've-ui-mwParameterPage-statusIndicator' ]
        } );
 
-       // TODO: Use spec.type
-
        // Events
        this.$labelElement.on( 'click', this.onLabelClick.bind( this ) );
 
@@ -84,7 +90,10 @@
                .append( this.$labelElement, this.statusIndicator.$element );
        this.$actions
                .addClass( 've-ui-mwParameterPage-actions' )
-               .append( this.infoButton.$element, this.removeButton.$element );
+               .append(
+                       this.infoButton.$element,
+                       this.removeButton.$element
+               );
        this.$labelElement
                .addClass( 've-ui-mwParameterPage-label' )
                .text( this.spec.getParameterLabel( paramName ) );
@@ -173,14 +182,12 @@
 /* Methods */
 
 /**
- * Create a value input widget based on the parameter type and whether it is
- * required or not.
+ * Get default configuration for an input widget.
  *
- * @return {OO.ui.InputWidget}
+ * @return {object}
  */
-ve.ui.MWParameterPage.prototype.createValueInput = function () {
-       var type = this.parameter.getType(),
-               required = this.parameter.isRequired(),
+ve.ui.MWParameterPage.prototype.getDefaultInputConfig = function () {
+       var required = this.parameter.isRequired(),
                valueInputConfig = {
                        autosize: true,
                        required: required,
@@ -199,11 +206,57 @@
                );
        }
 
+       return valueInputConfig;
+};
+
+/**
+ * Create a value input widget based on the parameter type and whether it is
+ * required or not.
+ *
+ * @return {OO.ui.InputWidget}
+ */
+ve.ui.MWParameterPage.prototype.createValueInput = function () {
+       var type = this.parameter.getType(),
+               value = this.parameter.getValue(),
+               valueInputConfig = this.getDefaultInputConfig();
+
+       /**
+        * TODO:
+        *  wiki-file-name
+        *  date - T100206
+        *  number - T124850
+        *  unbalanced-wikitext/content - T106242
+        *  string? - T124917
+        */
        if ( type === 'wiki-page-name' ) {
                return new mw.widgets.TitleInputWidget( valueInputConfig );
        } else if ( type === 'wiki-user-name' ) {
                return new mw.widgets.UserInputWidget( valueInputConfig );
-       } else if ( type !== 'line' ) {
+       } else if ( type === 'wiki-template-name' ) {
+               return new mw.widgets.TitleInputWidget( $.extend( {}, 
valueInputConfig, {
+                       namespace: mw.config.get( 'wgNamespaceIds' ).template
+               } ) );
+       } else if ( type === 'boolean' && ( value === '' || value === true || 
value === false ) ) {
+               this.$actions.prepend( this.rawFallbackButton.$element );
+               return new OO.ui.CheckboxInputWidget( valueInputConfig );
+       } else if (
+               type === 'url' &&
+               (
+                       
ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( value.trim() ) ||
+                       value === ''
+               )
+       ) {
+               this.$actions.prepend( this.rawFallbackButton.$element );
+               // From 
ve.ui.MWExternalLinkAnnotationWidget.prototype.createInputWidget
+               return new OO.ui.TextInputWidget( $.extend( {}, 
valueInputConfig, {
+                       icon: 'linkExternal',
+                       validate: function ( text ) {
+                               return 
!!ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( text.trim() );
+                       }
+               } ) );
+       } else if ( type === 'line' ) {
+               this.$actions.prepend( this.rawFallbackButton.$element );
+       } else {
                valueInputConfig.multiline = true;
        }
 
@@ -227,6 +280,7 @@
 ve.ui.MWParameterPage.prototype.onValueInputChange = function () {
        var value = this.valueInput.getValue();
 
+       this.edited = true;
        this.parameter.setValue( value );
 
        if ( this.outlineItem ) {
@@ -242,6 +296,18 @@
 };
 
 /**
+ * Handle click events from the raw fallback button
+ */
+ve.ui.MWParameterPage.prototype.onRawFallbackButtonClick = function () {
+       this.valueInput.$element.detach();
+       this.valueInput = new OO.ui.TextInputWidget( 
this.getDefaultInputConfig() )
+               .setValue( this.edited ? this.valueInput.getValue() : 
this.originalValue )
+               .connect( this, { change: 'onValueInputChange' } );
+       this.$field.append( this.valueInput.$element );
+       this.rawFallbackButton.setDisabled( true );
+};
+
+/**
  * Handle click events from the add button
  */
 ve.ui.MWParameterPage.prototype.onAddButtonFocus = function () {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1a9720a17c0418db280218918b270a4dc920289
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to