Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface MWTemplatePage class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Template dialog content pane header for a template. Includes informational
10 * messages about the template, such as a link to the page where it's defined.
11 *
12 * @class
13 * @extends OO.ui.PageLayout
14 *
15 * @constructor
16 * @param {ve.dm.MWTemplateModel} template Template model
17 * @param {string} name Unique symbolic name of page
18 * @param {Object} [config] Configuration options
19 * @param {jQuery} [config.$overlay] Overlay to render dropdowns in
20 * @param {boolean} [config.isReadOnly] Page is read-only
21 */
22 ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
23 const link = template.getTemplateDataQueryTitle();
24
25 // Configuration initialization
26 config = ve.extendObject( {
27 scrollable: false
28 }, config );
29
30 // Parent constructor
31 ve.ui.MWTemplatePage.super.call( this, name, config );
32
33 // Properties
34 this.template = template;
35 this.spec = template.getSpec();
36 this.$description = $( '<div>' )
37 .addClass( 've-ui-mwTemplatePage-description' );
38 this.infoFieldset = new OO.ui.FieldsetLayout( {
39 label: this.spec.getLabel(),
40 icon: 'puzzle'
41 } );
42
43 // Initialization
44 const description = this.spec.getDescription();
45 if ( description ) {
46 this.$description.append(
47 $( '<p>' ).text( description )
48 );
49 }
50
51 // The transcluded page may be dynamically generated or unspecified in the DOM
52 // for other reasons (T68724). In that case we can't tell the user what the
53 // template is called, nor link to the template page. However, if we know for
54 // certain that the template doesn't exist, be explicit about it (T162694).
55 const linkData = ve.init.platform.linkCache.getCached( '_missing/' + link ),
56 knownAsMissing = link && linkData && linkData.missing;
57
58 let key,
59 messageStyle = 've-ui-mwTemplatePage-description-missing';
60 if ( description ) {
61 key = 'visualeditor-dialog-transclusion-see-template';
62 messageStyle = 've-ui-mwTemplatePage-description-extra';
63 } else if ( !link || knownAsMissing ) {
64 let title;
65 try {
66 title = link && new mw.Title( link );
67 } catch ( e ) {
68 }
69 // When {{User:Foo}} can be parsed as "Foo", we know the ":" is not syntax.
70 key = title && title.getMain().indexOf( ':' ) === -1 ?
71 'visualeditor-dialog-transclusion-template-title-nonexistent' :
72 'visualeditor-dialog-transclusion-template-title-modifier';
73 } else {
74 key = 'visualeditor-dialog-transclusion-no-template-description';
75 }
76
77 if ( key ) {
78 const $addMessageHere = $( '<p>' );
79 // The following messages are used here:
80 // * visualeditor-dialog-transclusion-no-template-description
81 // * visualeditor-dialog-transclusion-see-template
82 // * visualeditor-dialog-transclusion-template-title-modifier
83 // * visualeditor-dialog-transclusion-template-title-nonexistent
84 const $msg = mw.message( key, this.spec.getLabel(), link ).parseDom();
85 // The following classes are used here:
86 // * ve-ui-mwTemplatePage-description-extra
87 // * ve-ui-mwTemplatePage-description-missing
88 $addMessageHere.addClass( messageStyle ).append( $msg );
89 ve.targetLinksToNewWindow( $addMessageHere[ 0 ] );
90 this.$description.append( $addMessageHere );
91 }
92
93 this.$description.find( 'a[href]' )
94 .on( 'click', () => {
95 ve.track( 'activity.transclusion', { action: 'template-doc-link-click' } );
96 } );
97
98 this.infoFieldset.$element
99 .append( this.$description );
100
101 if ( !knownAsMissing ) {
102 let noticeWidget;
103
104 if ( this.template.getSpec().getDocumentedParameterOrder().length &&
105 !this.template.getSpec().isDocumented()
106 ) {
107 noticeWidget = new OO.ui.MessageWidget( {
108 label: mw.message( 'visualeditor-dialog-transclusion-no-template-data-description', link ).parseDom(),
109 classes: [ 've-ui-mwTransclusionDialog-template-note' ],
110 type: 'warning'
111 } );
112 }
113
114 if ( noticeWidget && noticeWidget.$element ) {
115 ve.targetLinksToNewWindow( noticeWidget.$element[ 0 ] );
116 this.infoFieldset.$element.append( noticeWidget.$element );
117 }
118 }
119
120 this.$element
121 .addClass( 've-ui-mwTemplatePage' )
122 .append( this.infoFieldset.$element );
123 };
124
125 /* Inheritance */
126
127 OO.inheritClass( ve.ui.MWTemplatePage, OO.ui.PageLayout );
128
129 /* Methods */
130
131 ve.ui.MWTemplatePage.prototype.addPlaceholderParameter = function () {
132 this.template.addParameter( new ve.dm.MWParameterModel( this.template ) );
133 };