2020-05-07 20:35:52 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWIncludesContextItem class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2020-05-07 20:35:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWIncludesContextItem.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinearContextItem
|
|
|
|
*
|
|
|
|
* @constructor
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
|
|
|
* @param {ve.dm.Model} model Model the item is related to
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2020-05-07 20:35:52 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWIncludesContextItem = function VeUiMWIncludesContextItem() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWIncludesContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwIncludesContextItem' );
|
|
|
|
|
|
|
|
this.setLabel( this.getLabelMessage() );
|
|
|
|
|
|
|
|
this.$actions.remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWIncludesContextItem, ve.ui.LinearContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWIncludesContextItem.static.editable = false;
|
|
|
|
|
|
|
|
ve.ui.MWIncludesContextItem.static.name = 'mwIncludes';
|
|
|
|
|
|
|
|
ve.ui.MWIncludesContextItem.static.icon = 'markup';
|
|
|
|
|
|
|
|
ve.ui.MWIncludesContextItem.static.modelClasses = [
|
|
|
|
ve.dm.MWIncludesNode
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-10-25 15:51:29 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-05-07 20:35:52 +00:00
|
|
|
ve.ui.MWIncludesContextItem.prototype.getLabelMessage = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const key = {
|
2021-08-31 13:58:44 +00:00
|
|
|
'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-start',
|
|
|
|
'mw:Includes/NoInclude/End': 'visualeditor-includes-noinclude-end',
|
|
|
|
'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-start',
|
|
|
|
'mw:Includes/OnlyInclude/End': 'visualeditor-includes-onlyinclude-end',
|
|
|
|
'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly'
|
|
|
|
}[ this.model.getAttribute( 'type' ) ];
|
|
|
|
// eslint-disable-next-line mediawiki/msg-doc
|
|
|
|
return key ? mw.message( key ).text() : '';
|
2020-05-07 20:35:52 +00:00
|
|
|
};
|
|
|
|
|
2021-10-25 15:51:29 +00:00
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2020-05-07 20:35:52 +00:00
|
|
|
ve.ui.MWIncludesContextItem.prototype.getDescriptionMessage = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const key = {
|
2021-08-31 13:58:44 +00:00
|
|
|
'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-description',
|
|
|
|
'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-description',
|
|
|
|
'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly-description'
|
|
|
|
}[ this.model.getAttribute( 'type' ) ];
|
|
|
|
// eslint-disable-next-line mediawiki/msg-doc
|
2021-10-25 15:51:29 +00:00
|
|
|
return key ? mw.message( key ).parseDom() : $( [] );
|
2020-05-07 20:35:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWIncludesContextItem.prototype.renderBody = function () {
|
|
|
|
this.$body.empty();
|
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const $desc = this.getDescriptionMessage();
|
2021-10-25 15:51:29 +00:00
|
|
|
this.$body.append( $desc, $( document.createTextNode( mw.msg( 'word-separator' ) ) ) );
|
2020-05-07 20:35:52 +00:00
|
|
|
|
|
|
|
if ( this.model.getAttribute( 'mw' ) ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
let wikitext = this.model.getAttribute( 'mw' ).src;
|
2020-05-07 20:35:52 +00:00
|
|
|
// The opening and closing tags are included, eww
|
2020-06-08 19:05:42 +00:00
|
|
|
wikitext = wikitext.replace( /^<includeonly>\s*([\s\S]*)\s*<\/includeonly>$/, '$1' );
|
2020-05-07 20:35:52 +00:00
|
|
|
this.$body.append( $( '<pre>' )
|
|
|
|
// The following classes are used here:
|
|
|
|
// * mw-editfont-monospace
|
|
|
|
// * mw-editfont-sans-serif
|
|
|
|
// * mw-editfont-serif
|
|
|
|
.addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) )
|
|
|
|
.text( wikitext )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const $docMsg = mw.message( 'visualeditor-includes-documentation' ).parseDom();
|
2021-10-25 15:51:29 +00:00
|
|
|
this.$body.append( $docMsg );
|
2020-05-07 20:35:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWIncludesContextItem );
|