2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
2014-02-24 21:49:48 +00:00
|
|
|
* VisualEditor user interface MWParameterPage class.
|
2013-12-02 20:10:55 +00:00
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog template page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} parameter Template parameter
|
2013-12-02 20:10:55 +00:00
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
2018-04-04 20:37:32 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2019-02-08 19:18:22 +00:00
|
|
|
* @cfg {boolean} [readOnly] Parameter is read-only
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2014-02-28 00:00:10 +00:00
|
|
|
ve.ui.MWParameterPage = function VeUiMWParameterPage( parameter, name, config ) {
|
2021-03-11 16:12:45 +00:00
|
|
|
var paramName = parameter.getName(),
|
|
|
|
veConfig = mw.config.get( 'wgVisualEditorConfig' );
|
2014-02-12 21:45:37 +00:00
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, config );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
2016-09-07 02:16:24 +00:00
|
|
|
ve.ui.MWParameterPage.super.call( this, name, config );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-10-29 21:50:14 +00:00
|
|
|
this.edited = false;
|
2013-12-02 20:10:55 +00:00
|
|
|
this.parameter = parameter;
|
2014-10-29 21:50:14 +00:00
|
|
|
this.originalValue = parameter.getValue();
|
2014-02-26 00:29:13 +00:00
|
|
|
this.spec = parameter.getTemplate().getSpec();
|
2014-10-26 15:22:09 +00:00
|
|
|
this.defaultValue = parameter.getDefaultValue();
|
2015-03-04 23:31:05 +00:00
|
|
|
this.exampleValue = parameter.getExampleValue();
|
2014-10-22 22:46:20 +00:00
|
|
|
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$info = $( '<div>' );
|
|
|
|
this.$actions = $( '<div>' );
|
|
|
|
this.$labelElement = $( '<div>' );
|
|
|
|
this.$field = $( '<div>' );
|
2014-10-29 21:50:14 +00:00
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
// Temporary feature flags
|
|
|
|
this.useInlineDescriptions = veConfig.transclusionDialogInlineDescriptions;
|
|
|
|
this.useSuggestedValues = veConfig.transclusionDialogSuggestedValues;
|
|
|
|
this.useNewSidebar = veConfig.transclusionDialogNewSidebar;
|
|
|
|
|
2016-12-20 13:21:07 +00:00
|
|
|
// Note: Calling createValueInput() sets some properties we rely on later in this function
|
2014-10-29 21:50:14 +00:00
|
|
|
this.valueInput = this.createValueInput()
|
2014-10-22 22:46:20 +00:00
|
|
|
.setValue( this.parameter.getValue() )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { change: 'onValueInputChange' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2019-02-08 19:18:22 +00:00
|
|
|
if ( config.readOnly && this.valueInput.setReadOnly ) {
|
|
|
|
this.valueInput.setReadOnly( true );
|
|
|
|
}
|
|
|
|
|
2021-04-26 08:41:56 +00:00
|
|
|
// Construct the field docs
|
2014-02-26 00:29:13 +00:00
|
|
|
|
2021-04-26 09:13:14 +00:00
|
|
|
var $doc = $( '<div>' )
|
2021-04-26 08:41:56 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-doc' )
|
2021-04-26 09:13:14 +00:00
|
|
|
.append( $( '<p>' )
|
|
|
|
.text( this.spec.getParameterDescription( paramName ) || '' ) );
|
2014-03-06 22:00:43 +00:00
|
|
|
|
2021-09-14 13:28:49 +00:00
|
|
|
var statusIndicator;
|
2014-03-06 22:00:43 +00:00
|
|
|
if ( this.parameter.isRequired() ) {
|
2021-09-14 13:28:49 +00:00
|
|
|
if ( !this.useNewSidebar ) {
|
|
|
|
statusIndicator = new OO.ui.IndicatorWidget( {
|
|
|
|
classes: [ 've-ui-mwParameterPage-statusIndicator' ],
|
|
|
|
indicator: 'required',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
|
|
|
|
} );
|
|
|
|
}
|
2021-04-26 09:13:14 +00:00
|
|
|
$doc.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2021-04-26 08:41:56 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-doc-required' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.text(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter-description' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else if ( this.parameter.isDeprecated() ) {
|
2021-09-14 13:28:49 +00:00
|
|
|
statusIndicator = new OO.ui.IndicatorWidget( {
|
|
|
|
classes: [ 've-ui-mwParameterPage-statusIndicator' ],
|
|
|
|
indicator: 'alert',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
|
|
|
|
} );
|
2021-04-26 09:13:14 +00:00
|
|
|
$doc.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2021-04-26 08:41:56 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-doc-deprecated' )
|
2014-04-25 23:50:21 +00:00
|
|
|
.text(
|
|
|
|
ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-deprecated-parameter-description',
|
|
|
|
this.spec.getParameterDeprecationDescription( paramName )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2015-03-04 23:31:05 +00:00
|
|
|
|
|
|
|
if ( this.defaultValue ) {
|
2021-04-26 09:13:14 +00:00
|
|
|
$doc.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2021-04-26 08:41:56 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-doc-default' )
|
2015-03-04 23:31:05 +00:00
|
|
|
.text(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-param-default', this.defaultValue )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.exampleValue ) {
|
2021-04-26 09:13:14 +00:00
|
|
|
$doc.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<p>' )
|
2021-04-26 08:41:56 +00:00
|
|
|
.addClass( 've-ui-mwParameterPage-doc-example' )
|
2015-03-04 23:31:05 +00:00
|
|
|
.text(
|
2021-04-20 09:13:48 +00:00
|
|
|
ve.msg(
|
2021-08-26 15:25:09 +00:00
|
|
|
this.useInlineDescriptions ?
|
2021-04-20 09:13:48 +00:00
|
|
|
'visualeditor-dialog-transclusion-param-example-long' :
|
|
|
|
'visualeditor-dialog-transclusion-param-example',
|
|
|
|
this.exampleValue
|
|
|
|
)
|
2015-03-04 23:31:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:21:07 +00:00
|
|
|
// Construct the action buttons
|
|
|
|
|
2021-08-26 15:47:14 +00:00
|
|
|
if ( !this.rawValueInput && !this.useNewSidebar ) {
|
2016-12-20 13:21:07 +00:00
|
|
|
this.rawFallbackButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'wikiText',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-raw-fallback' )
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'onRawFallbackButtonClick' } );
|
|
|
|
|
|
|
|
this.$actions.append( this.rawFallbackButton.$element );
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( !this.useInlineDescriptions ) {
|
2021-04-26 09:13:14 +00:00
|
|
|
if ( $doc.text().trim() === '' ) {
|
2021-04-15 10:55:09 +00:00
|
|
|
this.infoButton = new OO.ui.ButtonWidget( {
|
|
|
|
disabled: true,
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-param-info-missing' ),
|
|
|
|
framed: false,
|
|
|
|
icon: 'info',
|
|
|
|
classes: [ 've-ui-mwParameterPage-infoButton' ]
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
this.infoButton = new OO.ui.PopupButtonWidget( {
|
|
|
|
$overlay: config.$overlay,
|
|
|
|
popup: {
|
2021-04-26 09:13:14 +00:00
|
|
|
$content: $doc
|
2021-04-15 10:55:09 +00:00
|
|
|
},
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-param-info' ),
|
|
|
|
framed: false,
|
|
|
|
icon: 'info',
|
|
|
|
classes: [ 've-ui-mwParameterPage-infoButton' ]
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$actions.append( this.infoButton.$element );
|
2016-12-20 13:21:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( !this.parameter.isRequired() && !config.readOnly && !this.useNewSidebar ) {
|
2021-07-15 08:49:06 +00:00
|
|
|
var removeButton = new OO.ui.ButtonWidget( {
|
2016-12-20 13:21:07 +00:00
|
|
|
framed: false,
|
2017-06-12 18:39:30 +00:00
|
|
|
icon: 'trash',
|
2016-12-20 13:21:07 +00:00
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
|
|
|
flags: [ 'destructive' ],
|
|
|
|
classes: [ 've-ui-mwParameterPage-removeButton' ]
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
|
|
|
|
2021-07-15 08:49:06 +00:00
|
|
|
this.$actions.append( removeButton.$element );
|
2014-03-06 22:00:43 +00:00
|
|
|
}
|
2016-12-20 13:21:07 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.$labelElement.on( 'click', this.onLabelClick.bind( this ) );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$info
|
|
|
|
.addClass( 've-ui-mwParameterPage-info' )
|
2021-09-14 13:28:49 +00:00
|
|
|
.append( this.$labelElement );
|
|
|
|
if ( statusIndicator ) {
|
|
|
|
this.$info.append( ' ', statusIndicator.$element );
|
|
|
|
}
|
2016-12-20 13:21:07 +00:00
|
|
|
this.$actions
|
|
|
|
.addClass( 've-ui-mwParameterPage-actions' );
|
|
|
|
this.$labelElement
|
|
|
|
.addClass( 've-ui-mwParameterPage-label' )
|
|
|
|
.text( this.spec.getParameterLabel( paramName ) );
|
|
|
|
this.$field
|
|
|
|
.addClass( 've-ui-mwParameterPage-field' )
|
|
|
|
.append(
|
|
|
|
this.valueInput.$element
|
|
|
|
);
|
2021-07-15 12:47:21 +00:00
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( this.useNewSidebar && !this.parameter.isDocumented() ) {
|
2021-07-15 12:47:21 +00:00
|
|
|
var undocumentedLabel = new OO.ui.LabelWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-param-undocumented' ),
|
|
|
|
classes: [ 've-ui-mwParameterPage-undocumentedLabel' ]
|
|
|
|
} );
|
|
|
|
this.$labelElement.after( undocumentedLabel.$element );
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( this.useSuggestedValues && this.parameter.getSuggestedValues().length ) {
|
2021-03-11 16:12:45 +00:00
|
|
|
this.warningMessage = new OO.ui.MessageWidget( {
|
|
|
|
inline: true,
|
|
|
|
classes: [ 've-ui-mwParameterPage-warning' ]
|
|
|
|
} ).toggle( false );
|
|
|
|
this.$field.append( this.warningMessage.$element );
|
|
|
|
}
|
2016-12-20 13:21:07 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwParameterPage' )
|
2019-02-08 19:18:22 +00:00
|
|
|
.append( this.$info, this.$field, this.$actions );
|
2021-04-15 10:55:09 +00:00
|
|
|
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( this.useInlineDescriptions ) {
|
2021-04-20 16:27:03 +00:00
|
|
|
this.$field.addClass( 've-ui-mwParameterPage-inlineDescription' );
|
2021-04-22 16:59:30 +00:00
|
|
|
this.collapsibleDoc = new ve.ui.MWExpandableContentElement( {
|
|
|
|
classes: [ 've-ui-mwParameterPage-inlineDescription' ],
|
|
|
|
$content: $doc
|
|
|
|
} );
|
|
|
|
this.$info.after( this.collapsibleDoc.$element );
|
2021-04-15 10:55:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 11:00:53 +00:00
|
|
|
// FIXME this and the addPlaceholderParameter can be remove when the feature flag is gone
|
2021-08-26 15:25:09 +00:00
|
|
|
if ( !config.readOnly && !this.useNewSidebar ) {
|
2021-07-16 12:26:07 +00:00
|
|
|
// This button is only shown when this …ParameterPage is neither followed by another
|
|
|
|
// …TemplatePage (i.e. it's the last template in the transclusion) nor a
|
|
|
|
// …ParameterPlaceholderPage (i.e. the parameter search widget isn't shown). This state
|
|
|
|
// should be unreachable, but isn't. Hiding this is done via CSS.
|
2021-06-04 10:45:25 +00:00
|
|
|
var addButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
2021-08-26 15:25:09 +00:00
|
|
|
label: this.useNewSidebar ?
|
2021-08-06 11:56:40 +00:00
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-add-undocumented-param' ) :
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-add-param' )
|
2021-06-04 10:45:25 +00:00
|
|
|
} )
|
2021-07-16 12:26:07 +00:00
|
|
|
.connect( this, { click: 'addPlaceholderParameter' } );
|
2021-06-04 10:45:25 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 've-ui-mwParameterPage-addUndocumented' )
|
|
|
|
.append( addButton.$element )
|
|
|
|
.appendTo( this.$element );
|
2019-02-08 19:18:22 +00:00
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-02-24 21:49:48 +00:00
|
|
|
OO.inheritClass( ve.ui.MWParameterPage, OO.ui.PageLayout );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-10-29 21:50:14 +00:00
|
|
|
/**
|
|
|
|
* Get default configuration for an input widget.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPage.prototype.getDefaultInputConfig = function () {
|
|
|
|
var required = this.parameter.isRequired(),
|
|
|
|
valueInputConfig = {
|
|
|
|
autosize: true,
|
|
|
|
required: required,
|
|
|
|
validate: required ? 'non-empty' : null
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( this.defaultValue ) {
|
|
|
|
valueInputConfig.placeholder = ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-param-default',
|
|
|
|
this.defaultValue
|
|
|
|
);
|
2021-08-26 15:25:09 +00:00
|
|
|
} else if ( this.exampleValue && !this.useInlineDescriptions ) {
|
2014-10-29 21:50:14 +00:00
|
|
|
valueInputConfig.placeholder = ve.msg(
|
2021-08-26 15:25:09 +00:00
|
|
|
this.useInlineDescriptions ?
|
2021-04-20 09:13:48 +00:00
|
|
|
'visualeditor-dialog-transclusion-param-example-long' :
|
|
|
|
'visualeditor-dialog-transclusion-param-example',
|
2014-10-29 21:50:14 +00:00
|
|
|
this.exampleValue
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2021-08-26 15:25:09 +00:00
|
|
|
valueInputConfig = this.getDefaultInputConfig();
|
2014-10-29 21:50:14 +00:00
|
|
|
|
|
|
|
this.rawValueInput = false;
|
|
|
|
delete valueInputConfig.validate;
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// * date - T100206
|
|
|
|
// * number - T124850
|
|
|
|
// * unbalanced-wikitext/content - T106242
|
|
|
|
// * string? - T124917
|
|
|
|
if (
|
|
|
|
type === 'wiki-page-name' &&
|
|
|
|
( value === '' || mw.Title.newFromText( value ) )
|
|
|
|
) {
|
2020-08-31 15:19:36 +00:00
|
|
|
return new mw.widgets.TitleInputWidget( $.extend( {
|
|
|
|
api: ve.init.target.getContentApi()
|
|
|
|
}, valueInputConfig ) );
|
2020-08-27 16:21:23 +00:00
|
|
|
} else if (
|
|
|
|
type === 'wiki-file-name' &&
|
|
|
|
( value === '' || mw.Title.newFromText( value ) )
|
|
|
|
) {
|
|
|
|
return new mw.widgets.TitleInputWidget( $.extend( {}, valueInputConfig, {
|
|
|
|
api: ve.init.target.getContentApi(),
|
|
|
|
namespace: 6,
|
|
|
|
showImages: true
|
|
|
|
} ) );
|
2014-10-29 21:50:14 +00:00
|
|
|
} else if (
|
|
|
|
type === 'wiki-user-name' &&
|
|
|
|
( value === '' || mw.Title.newFromText( value ) )
|
|
|
|
) {
|
2020-08-18 12:16:49 +00:00
|
|
|
valueInputConfig.validate = function ( val ) {
|
2014-10-29 21:50:14 +00:00
|
|
|
// TODO: Check against wgMaxNameChars
|
2020-06-10 15:19:50 +00:00
|
|
|
// TODO: Check against unicode validation regex from MW core's User::isValidUserName
|
2020-08-18 12:16:49 +00:00
|
|
|
return !!mw.Title.newFromText( val );
|
2014-10-29 21:50:14 +00:00
|
|
|
};
|
2020-08-31 15:19:36 +00:00
|
|
|
return new mw.widgets.UserInputWidget( $.extend( {
|
|
|
|
api: ve.init.target.getContentApi()
|
|
|
|
}, valueInputConfig ) );
|
2014-10-29 21:50:14 +00:00
|
|
|
} else if (
|
|
|
|
type === 'wiki-template-name' &&
|
|
|
|
( value === '' || mw.Title.newFromText( value ) )
|
|
|
|
) {
|
2020-08-31 15:19:36 +00:00
|
|
|
return new mw.widgets.TitleInputWidget( $.extend( {
|
2018-05-04 13:30:10 +00:00
|
|
|
api: ve.init.target.getContentApi()
|
2020-08-31 15:19:36 +00:00
|
|
|
}, valueInputConfig, {
|
|
|
|
namespace: mw.config.get( 'wgNamespaceIds' ).template
|
2014-10-29 21:50:14 +00:00
|
|
|
} ) );
|
|
|
|
} else if ( type === 'boolean' && ( value === '1' || value === '0' ) ) {
|
|
|
|
return new ve.ui.MWParameterCheckboxInputWidget( valueInputConfig );
|
|
|
|
} else if (
|
|
|
|
type === 'url' &&
|
|
|
|
(
|
|
|
|
value === '' ||
|
|
|
|
ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( value.trim() )
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return ve.ui.MWExternalLinkAnnotationWidget.static.createExternalLinkInputWidget( valueInputConfig );
|
2021-03-11 16:12:45 +00:00
|
|
|
} else if (
|
2021-08-26 15:25:09 +00:00
|
|
|
this.useSuggestedValues &&
|
2021-03-11 16:12:45 +00:00
|
|
|
this.parameter.getSuggestedValues().length &&
|
|
|
|
this.isSuggestedValueType( type )
|
|
|
|
) {
|
2021-04-14 11:34:01 +00:00
|
|
|
valueInputConfig.menu = { filterFromInput: true, highlightOnFilter: true };
|
2021-03-11 16:12:45 +00:00
|
|
|
valueInputConfig.options =
|
|
|
|
this.parameter.getSuggestedValues().map( function ( suggestedValue ) {
|
|
|
|
return { data: suggestedValue };
|
|
|
|
} );
|
|
|
|
this.rawValueInput = true;
|
|
|
|
return new OO.ui.ComboBoxInputWidget( valueInputConfig );
|
2018-09-12 17:01:03 +00:00
|
|
|
} else if ( type !== 'line' || value.indexOf( '\n' ) !== -1 ) {
|
|
|
|
// If the type is line, but there are already newlines in the provided
|
|
|
|
// value, don't break the existing content by only providing a single-
|
|
|
|
// line field. (This implies that the TemplateData for the field isn't
|
|
|
|
// complying with its use in practice...)
|
2014-10-29 21:50:14 +00:00
|
|
|
this.rawValueInput = true;
|
2018-08-07 11:39:14 +00:00
|
|
|
return new ve.ui.MWLazyMultilineTextInputWidget( valueInputConfig );
|
2014-10-29 21:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new OO.ui.TextInputWidget( valueInputConfig );
|
|
|
|
};
|
|
|
|
|
2021-03-11 16:12:45 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to show suggested values for a given parameter type
|
|
|
|
*
|
|
|
|
* @param {string} type Parameter type
|
2021-03-01 17:02:38 +00:00
|
|
|
* @return {boolean} True if suggested values should be shown
|
2021-03-11 16:12:45 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPage.prototype.isSuggestedValueType = function ( type ) {
|
|
|
|
return [ 'unknown', 'content', 'line', 'string', 'number', 'unbalanced-wikitext' ].indexOf( type ) > -1;
|
|
|
|
};
|
|
|
|
|
2015-10-03 13:16:16 +00:00
|
|
|
/**
|
2021-08-03 12:44:48 +00:00
|
|
|
* @private
|
|
|
|
* @return {boolean} True if there is either user-provided input or a default value
|
2015-10-03 13:16:16 +00:00
|
|
|
*/
|
2021-08-03 12:44:48 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.containsSomeValue = function () {
|
|
|
|
// Note: For templates that allow overriding a default value with nothing, the empty string is
|
|
|
|
// meaningful user input. For templates that don't, the parameter can never be truly empty.
|
2021-09-11 12:15:32 +00:00
|
|
|
return !!( this.valueInput.getValue() || this.defaultValue );
|
2014-02-26 00:29:13 +00:00
|
|
|
};
|
|
|
|
|
2015-10-03 13:16:16 +00:00
|
|
|
/**
|
|
|
|
* Handle change events from the value input
|
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {string} value
|
2015-10-03 13:16:16 +00:00
|
|
|
*/
|
2014-02-26 00:29:13 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onValueInputChange = function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var value = this.valueInput.getValue();
|
2014-02-26 00:29:13 +00:00
|
|
|
|
2020-11-25 13:51:30 +00:00
|
|
|
if ( !this.edited ) {
|
|
|
|
ve.track( 'activity.transclusion', { action: 'edit-parameter-value' } );
|
|
|
|
}
|
2014-10-29 21:50:14 +00:00
|
|
|
this.edited = true;
|
2014-02-26 00:29:13 +00:00
|
|
|
this.parameter.setValue( value );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
2021-08-03 12:44:48 +00:00
|
|
|
this.outlineItem.setFlags( { empty: !this.containsSomeValue() } );
|
2014-02-26 00:29:13 +00:00
|
|
|
}
|
2021-03-11 16:12:45 +00:00
|
|
|
|
|
|
|
if ( this.warningMessage ) {
|
2021-06-21 08:10:27 +00:00
|
|
|
var isNotSuggestedValue = value &&
|
2021-03-11 16:12:45 +00:00
|
|
|
this.parameter.getSuggestedValues().length > 0 &&
|
|
|
|
this.parameter.getSuggestedValues().indexOf( value ) === -1;
|
|
|
|
if ( isNotSuggestedValue ) {
|
|
|
|
this.warningMessage.setLabel( ve.msg( 'visualeditor-dialog-transclusion-suggestedvalues-warning' ) );
|
|
|
|
}
|
|
|
|
this.warningMessage.toggle( isNotSuggestedValue );
|
|
|
|
}
|
2014-02-26 00:29:13 +00:00
|
|
|
};
|
|
|
|
|
2015-10-03 13:16:16 +00:00
|
|
|
/**
|
|
|
|
* Handle click events from the remove button
|
|
|
|
*/
|
2014-02-26 00:29:13 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.parameter.remove();
|
|
|
|
};
|
|
|
|
|
2014-10-29 21:50:14 +00:00
|
|
|
/**
|
|
|
|
* Handle click events from the raw fallback button
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPage.prototype.onRawFallbackButtonClick = function () {
|
|
|
|
this.valueInput.$element.detach();
|
|
|
|
if ( this.rawValueInput ) {
|
|
|
|
this.valueInput = this.createValueInput()
|
|
|
|
.setValue( this.valueInput.getValue() );
|
|
|
|
} else {
|
|
|
|
this.valueInput = new OO.ui.TextInputWidget( this.getDefaultInputConfig() )
|
|
|
|
.setValue( this.edited ? this.valueInput.getValue() : this.originalValue );
|
|
|
|
this.valueInput.$input.addClass( 've-ui-mwParameter-wikitextFallbackInput' );
|
|
|
|
this.rawValueInput = true;
|
|
|
|
}
|
|
|
|
this.valueInput.connect( this, { change: 'onValueInputChange' } );
|
|
|
|
this.$field.append( this.valueInput.$element );
|
|
|
|
};
|
|
|
|
|
2015-10-03 13:16:16 +00:00
|
|
|
/**
|
|
|
|
* Handle click events from the add button
|
|
|
|
*/
|
2021-07-16 12:26:07 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.addPlaceholderParameter = function () {
|
2014-03-04 22:56:14 +00:00
|
|
|
var template = this.parameter.getTemplate();
|
|
|
|
template.addParameter( new ve.dm.MWParameterModel( template ) );
|
|
|
|
};
|
|
|
|
|
2015-10-03 13:16:16 +00:00
|
|
|
/**
|
|
|
|
* Handle click events from the label element
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e Click event
|
|
|
|
*/
|
2014-02-26 00:29:13 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.onLabelClick = function () {
|
|
|
|
this.valueInput.simulateLabelClick();
|
|
|
|
};
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWParameterPage.prototype.setupOutlineItem = function () {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setMovable( false )
|
2021-09-13 14:28:27 +00:00
|
|
|
.setRemovable( !this.parameter.isRequired() && !this.useNewSidebar )
|
2021-09-15 10:10:56 +00:00
|
|
|
.setLevel( 1 )
|
|
|
|
.setFlags( { empty: !this.containsSomeValue() } )
|
|
|
|
.setLabel( this.spec.getParameterLabel( this.parameter.getName() ) );
|
2014-02-15 01:37:32 +00:00
|
|
|
|
2021-09-15 10:10:56 +00:00
|
|
|
if ( this.parameter.isRequired() ) {
|
2014-02-15 01:37:32 +00:00
|
|
|
this.outlineItem
|
2021-09-15 10:10:56 +00:00
|
|
|
.setIndicator( 'required' )
|
|
|
|
.setTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( this.parameter.isDeprecated() ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIndicator( 'alert' )
|
|
|
|
.setTitle(
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
|
|
|
|
);
|
2014-02-15 01:37:32 +00:00
|
|
|
}
|
|
|
|
};
|
2015-10-03 13:16:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPage.prototype.focus = function () {
|
|
|
|
this.valueInput.focus();
|
|
|
|
};
|
2021-04-22 16:59:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh collapsible children.
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPage.prototype.updateSize = function () {
|
|
|
|
if ( this.collapsibleDoc ) {
|
|
|
|
this.collapsibleDoc.updateSize();
|
|
|
|
}
|
|
|
|
};
|