2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePage class.
|
|
|
|
*
|
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
|
2015-08-19 18:33:59 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template Template model
|
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-24 12:38:03 +00:00
|
|
|
* @cfg {boolean} [isReadOnly] Page is read-only
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
|
2021-09-21 10:47:02 +00:00
|
|
|
var link = template.getTemplateDataQueryTitle(),
|
2021-05-14 11:57:28 +00:00
|
|
|
veConfig = mw.config.get( 'wgVisualEditorConfig' );
|
2014-03-06 23:40:43 +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-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWTemplatePage.super.call( this, name, config );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.template = template;
|
2014-02-27 23:58:37 +00:00
|
|
|
this.spec = template.getSpec();
|
2021-08-26 13:34:39 +00:00
|
|
|
this.$description = $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwTemplatePage-description' );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.infoFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: this.spec.getLabel(),
|
2017-07-06 16:52:56 +00:00
|
|
|
icon: 'puzzle'
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
2021-08-26 13:34:39 +00:00
|
|
|
this.$description
|
|
|
|
.text( this.spec.getDescription() );
|
2021-08-23 14:08:51 +00:00
|
|
|
|
2021-08-26 13:34:39 +00:00
|
|
|
// The transcluded page may be dynamically generated or unspecified in the DOM
|
|
|
|
// for other reasons (T68724). In that case we can't tell the user what the
|
|
|
|
// template is called, nor link to the template page. However, if we know for
|
|
|
|
// certain that the template doesn't exist, be explicit about it (T162694).
|
2021-08-23 14:08:51 +00:00
|
|
|
var linkData = ve.init.platform.linkCache.getCached( '_missing/' + link ),
|
2021-09-21 13:25:43 +00:00
|
|
|
knownAsMissing = link && linkData && linkData.missing;
|
2021-08-23 14:08:51 +00:00
|
|
|
|
2021-09-21 13:25:43 +00:00
|
|
|
var key,
|
|
|
|
messageStyle = 've-ui-mwTemplatePage-description-missing',
|
|
|
|
$addMessageHere = this.$description;
|
|
|
|
if ( this.spec.getDescription() ) {
|
|
|
|
key = !veConfig.transclusionDialogNewSidebar ?
|
|
|
|
'visualeditor-dialog-transclusion-more-template-description' :
|
|
|
|
'visualeditor-dialog-transclusion-see-template';
|
|
|
|
messageStyle = 've-ui-mwTemplatePage-description-extra';
|
|
|
|
$addMessageHere = $( '<span>' );
|
|
|
|
this.$description.append( $( '<hr>' ), $addMessageHere );
|
|
|
|
} else if ( !veConfig.transclusionDialogNewSidebar ) {
|
|
|
|
if ( knownAsMissing ) {
|
|
|
|
key = 'visualeditor-dialog-transclusion-absent-template';
|
|
|
|
} else if ( link ) {
|
|
|
|
key = 'visualeditor-dialog-transclusion-no-template-description';
|
|
|
|
}
|
|
|
|
// Note this leaves dynamic template names like {{ {{foo}} }} without a message.
|
|
|
|
} else if ( !link || knownAsMissing ) {
|
|
|
|
var title;
|
|
|
|
try {
|
|
|
|
title = link && new mw.Title( link );
|
|
|
|
} catch ( e ) {
|
2014-07-02 19:38:29 +00:00
|
|
|
}
|
2021-09-21 13:25:43 +00:00
|
|
|
// When {{User:Foo}} can be parsed as "Foo", we know the ":" is not syntax.
|
|
|
|
key = title && title.getMain().indexOf( ':' ) === -1 ?
|
|
|
|
'visualeditor-dialog-transclusion-template-title-nonexistent' :
|
|
|
|
'visualeditor-dialog-transclusion-template-title-modifier';
|
2021-09-21 14:12:00 +00:00
|
|
|
} else {
|
2021-09-21 13:25:43 +00:00
|
|
|
key = 'visualeditor-dialog-transclusion-no-template-description';
|
2014-03-06 23:40:43 +00:00
|
|
|
}
|
2021-09-21 13:25:43 +00:00
|
|
|
|
|
|
|
if ( key ) {
|
|
|
|
// The following classes are used here:
|
|
|
|
// * ve-ui-mwTemplatePage-description-extra
|
|
|
|
// * ve-ui-mwTemplatePage-description-missing
|
|
|
|
$addMessageHere.addClass( messageStyle )
|
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-dialog-transclusion-absent-template
|
|
|
|
// * visualeditor-dialog-transclusion-more-template-description
|
|
|
|
// * visualeditor-dialog-transclusion-no-template-description
|
|
|
|
// * visualeditor-dialog-transclusion-see-template
|
|
|
|
// * visualeditor-dialog-transclusion-template-title-modifier
|
|
|
|
// * visualeditor-dialog-transclusion-template-title-nonexistent
|
|
|
|
.append( mw.message( key, this.spec.getLabel(), link ).parseDom() );
|
|
|
|
ve.targetLinksToNewWindow( $addMessageHere[ 0 ] );
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:49:17 +00:00
|
|
|
this.$description.find( 'a[href]' )
|
|
|
|
.on( 'click', function () {
|
|
|
|
ve.track( 'activity.transclusion', { action: 'template-doc-link-click' } );
|
|
|
|
} );
|
2014-07-09 20:09:05 +00:00
|
|
|
|
2021-08-23 14:08:51 +00:00
|
|
|
this.infoFieldset.$element
|
|
|
|
.append( this.$description );
|
|
|
|
|
2021-09-21 13:25:43 +00:00
|
|
|
if ( veConfig.transclusionDialogNewSidebar && !knownAsMissing ) {
|
2021-08-31 11:04:27 +00:00
|
|
|
var noticeWidget;
|
|
|
|
|
2021-08-23 14:08:51 +00:00
|
|
|
if ( !this.template.getSpec().getDocumentedParameterOrder().length ) {
|
2021-08-31 11:04:27 +00:00
|
|
|
noticeWidget = new OO.ui.MessageWidget( {
|
2021-08-23 14:08:51 +00:00
|
|
|
label: mw.message( 'visualeditor-dialog-transclusion-no-parameters-description' ).parseDom(),
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-template-note' ]
|
|
|
|
} );
|
|
|
|
} else if ( !this.template.getSpec().isDocumented() ) {
|
2021-08-31 11:04:27 +00:00
|
|
|
noticeWidget = new OO.ui.MessageWidget( {
|
2021-08-23 14:08:51 +00:00
|
|
|
label: mw.message( 'visualeditor-dialog-transclusion-no-template-data-description', link ).parseDom(),
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-template-note' ],
|
|
|
|
type: 'warning'
|
|
|
|
} );
|
2021-08-31 11:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( noticeWidget && noticeWidget.$element ) {
|
|
|
|
ve.targetLinksToNewWindow( noticeWidget.$element[ 0 ] );
|
|
|
|
this.infoFieldset.$element.append( noticeWidget.$element );
|
2021-08-23 14:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTemplatePage' )
|
2019-02-24 12:38:03 +00:00
|
|
|
.append( this.infoFieldset.$element );
|
2021-06-04 10:45:25 +00:00
|
|
|
|
2019-02-24 12:38:03 +00:00
|
|
|
if ( !config.isReadOnly ) {
|
2021-07-15 08:49:06 +00:00
|
|
|
if ( !veConfig.transclusionDialogBackButton &&
|
|
|
|
!veConfig.transclusionDialogNewSidebar
|
|
|
|
) {
|
2021-06-04 10:45:25 +00:00
|
|
|
var removeButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'trash',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
flags: [ 'destructive' ],
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-removeButton' ]
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
|
|
|
removeButton.$element.appendTo( this.$element );
|
2021-05-14 11:57:28 +00:00
|
|
|
}
|
2021-06-04 10:45:25 +00:00
|
|
|
|
2021-08-18 11:00:53 +00:00
|
|
|
if ( !veConfig.transclusionDialogNewSidebar ) {
|
|
|
|
// This button is only shown as a last resort when this …TemplatePage is neither followed by
|
|
|
|
// a …ParameterPage (i.e. the template doesn't have parameters) 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.
|
|
|
|
var addButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' )
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'addPlaceholderParameter' } );
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 've-ui-mwTemplatePage-more' )
|
|
|
|
.append( addButton.$element )
|
|
|
|
.appendTo( this.$element );
|
|
|
|
}
|
2019-02-24 12:38:03 +00:00
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplatePage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWTemplatePage.prototype.setupOutlineItem = function () {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'puzzle' )
|
|
|
|
.setMovable( true )
|
|
|
|
.setRemovable( true )
|
|
|
|
.setLabel( this.spec.getLabel() );
|
2014-02-15 01:37:32 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.template.remove();
|
|
|
|
};
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2021-07-16 12:26:07 +00:00
|
|
|
ve.ui.MWTemplatePage.prototype.addPlaceholderParameter = function () {
|
2014-03-04 22:56:14 +00:00
|
|
|
this.template.addParameter( new ve.dm.MWParameterModel( this.template ) );
|
|
|
|
};
|