| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) { |
| 23 |
const link = template.getTemplateDataQueryTitle(); |
| 24 |
|
| 25 |
|
| 26 |
config = ve.extendObject( { |
| 27 |
scrollable: false |
| 28 |
}, config ); |
| 29 |
|
| 30 |
|
| 31 |
ve.ui.MWTemplatePage.super.call( this, name, config ); |
| 32 |
|
| 33 |
|
| 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 |
|
| 44 |
const description = this.spec.getDescription(); |
| 45 |
if ( description ) { |
| 46 |
this.$description.append( |
| 47 |
$( '<p>' ).text( description ) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 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 |
|
| 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 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
const $msg = mw.message( key, this.spec.getLabel(), link ).parseDom(); |
| 85 |
|
| 86 |
|
| 87 |
|
| 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 |
|
| 126 |
|
| 127 |
OO.inheritClass( ve.ui.MWTemplatePage, OO.ui.PageLayout ); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.ui.MWTemplatePage.prototype.addPlaceholderParameter = function () { |
| 132 |
this.template.addParameter( new ve.dm.MWParameterModel( this.template ) ); |
| 133 |
}; |