File: ve.ui.MWIncludesContextItem.js

package info (click to toggle)
mediawiki 1%3A1.39.13-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 320,416 kB
  • sloc: php: 815,516; javascript: 601,264; sql: 11,218; python: 4,863; xml: 3,080; sh: 990; ruby: 82; makefile: 78
file content (105 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*!
 * VisualEditor MWIncludesContextItem class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */

/**
 * Context item for a MWIncludesContextItem.
 *
 * @class
 * @extends ve.ui.LinearContextItem
 *
 * @constructor
 * @param {ve.ui.Context} context Context item is in
 * @param {ve.dm.Model} model Model item is related to
 * @param {Object} config Configuration options
 */
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 */

/**
 * @return {string}
 */
ve.ui.MWIncludesContextItem.prototype.getLabelMessage = function () {
	var key = {
		'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() : '';
};

/**
 * @return {jQuery}
 */
ve.ui.MWIncludesContextItem.prototype.getDescriptionMessage = function () {
	var key = {
		'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
	return key ? mw.message( key ).parseDom() : $( [] );
};

/**
 * @inheritdoc
 */
ve.ui.MWIncludesContextItem.prototype.renderBody = function () {
	this.$body.empty();

	var $desc = this.getDescriptionMessage();
	this.$body.append( $desc, $( document.createTextNode( mw.msg( 'word-separator' ) ) ) );

	if ( this.model.getAttribute( 'mw' ) ) {
		var wikitext = this.model.getAttribute( 'mw' ).src;
		// The opening and closing tags are included, eww
		wikitext = wikitext.replace( /^<includeonly>\s*([\s\S]*)\s*<\/includeonly>$/, '$1' );
		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 )
		);
	}

	var $docMsg = mw.message( 'visualeditor-includes-documentation' ).parseDom();
	this.$body.append( $docMsg );
};

/* Registration */

ve.ui.contextItemFactory.register( ve.ui.MWIncludesContextItem );