File: ve.dm.MWIncludesNode.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 (102 lines) | stat: -rw-r--r-- 2,643 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
/*!
 * VisualEditor DataModel MWIncludesNode class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
 */

/**
 * DataModel MW node for noinclude, includeonly and onlyinclude tags.
 *
 * @class
 * @extends ve.dm.AlienInlineNode
 * @constructor
 * @param {Object} element Reference to element in linear model
 */
ve.dm.MWIncludesNode = function VeDmMWIncludesNode() {
	// Parent constructor
	ve.dm.MWIncludesNode.super.apply( this, arguments );
};

/* Inheritance */

OO.inheritClass( ve.dm.MWIncludesNode, ve.dm.AlienInlineNode );

/* Static Properties */

ve.dm.MWIncludesNode.static.name = 'mwIncludes';

ve.dm.MWIncludesNode.static.matchRdfaTypes = [
	/^mw:Includes\//
];

/* Static Methods */

/**
 * @inheritdoc
 */
ve.dm.MWIncludesNode.static.toDataElement = function ( domElements ) {
	var mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
		type = domElements[ 0 ].getAttribute( 'typeof' );

	var dataElement = {
		type: 'mwIncludes',
		attributes: {
			type: type
		}
	};

	if ( mwDataJSON !== null ) {
		dataElement.attributes.mw = JSON.parse( mwDataJSON );
	}

	if ( type === 'mw:Includes/IncludeOnly/End' ) {
		// We don't want to allow typing between this and the opening tag, as the content is stored in
		// data-mw as wikitext. Therefore pretend that includeonly nodes have an implicit closing tag.
		// This should be fine since the closing tag directly follows the opening tag.
		return [];
	}

	return dataElement;
};

/**
 * @inheritdoc
 */
ve.dm.MWIncludesNode.static.toDomElements = function ( dataElement, doc, converter ) {
	var el = doc.createElement( 'meta' );
	el.setAttribute( 'typeof', dataElement.attributes.type );
	if ( dataElement.attributes.mw ) {
		el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
	}

	var els = [ el ];
	if ( dataElement.attributes.type === 'mw:Includes/IncludeOnly' ) {
		// includeonly nodes have an implicit closing tag
		els = els.concat( ve.dm.MWIncludesNode.static.toDomElements( {
			type: 'mwIncludes',
			attributes: {
				type: 'mw:Includes/IncludeOnly/End'
			}
		}, doc, converter ) );
	}

	return els;
};

/* Methods */

ve.dm.MWIncludesNode.prototype.getWikitextTag = function () {
	var map = {
		'mw:Includes/NoInclude': '<noinclude>',
		'mw:Includes/NoInclude/End': '</noinclude>',
		'mw:Includes/OnlyInclude': '<onlyinclude>',
		'mw:Includes/OnlyInclude/End': '</onlyinclude>',
		'mw:Includes/IncludeOnly': '<includeonly>…</includeonly>'
	};
	return map[ this.getAttribute( 'type' ) ];
};

/* Registration */

ve.dm.modelRegistry.register( ve.dm.MWIncludesNode );