Merge "Handle annotation tags as nodes rather than metaitems."

This commit is contained in:
jenkins-bot 2021-10-21 22:52:31 +00:00 committed by Gerrit Code Review
commit c78556c083
11 changed files with 337 additions and 2 deletions

View file

@ -1651,6 +1651,7 @@
"ext.visualEditor.mwcore": {
"group": "visualEditorA",
"scripts": [
"modules/ve-mw/dm/nodes/ve.dm.MWAnnotationNode.js",
"modules/ve-mw/dm/nodes/ve.dm.MWIncludesNode.js",
"modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js",
"modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js",
@ -1660,6 +1661,8 @@
"modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js",
"modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js",
"modules/ve-mw/dm/metaitems/ve.dm.MWAlienMetaItem.js",
"modules/ve-mw/dm/nodes/ve.dm.MWAlienAnnotationNode.js",
"modules/ve-mw/ce/nodes/ve.ce.MWAnnotationNode.js",
"modules/ve-mw/ce/nodes/ve.ce.MWIncludesNode.js",
"modules/ve-mw/ce/nodes/ve.ce.MWEntityNode.js",
"modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js",
@ -1668,6 +1671,7 @@
"modules/ve-mw/ce/nodes/ve.ce.MWPreNode.js",
"modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js",
"modules/ve-mw/ce/annotations/ve.ce.MWNowikiAnnotation.js",
"modules/ve-mw/ce/nodes/ve.ce.MWAlienAnnotationNode.js",
"modules/ve-mw/ui/ve.ui.MWCommandRegistry.js",
"modules/ve-mw/ui/ve.ui.MWSequenceRegistry.js",
"modules/ve-mw/ui/ve.ui.MWSurface.js",
@ -1694,6 +1698,8 @@
"modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js",
"modules/ve-mw/ui/actions/ve.ui.MWLinkAction.js",
"modules/ve-mw/ui/contextitems/ve.ui.MWPreContextItem.js",
"modules/ve-mw/ui/contextitems/ve.ui.MWAnnotationContextItem.js",
"modules/ve-mw/ui/contextitems/ve.ui.MWAlienAnnotationContextItem.js",
"modules/ve-mw/ui/contextitems/ve.ui.MWIncludesContextItem.js",
"modules/ve-mw/ui/widgets/ve.ui.MWEducationPopupWidget.js",
"modules/ve-mw/ui/inspectors/ve.ui.MWCommentInspector.js"
@ -1701,6 +1707,7 @@
"styles": [
"modules/ve-mw/ce/styles/nodes/ve.ce.MWEntityNode.css",
"modules/ve-mw/ce/styles/nodes/ve.ce.MWIncludesNode.css",
"modules/ve-mw/ce/styles/nodes/ve.ce.MWAnnotationNode.css",
"modules/ve-mw/ce/styles/nodes/ve.ce.MWTableNode.css",
"modules/ve-mw/ui/styles/dialogs/ve.ui.MWPreDialog.css",
"modules/ve-mw/ui/styles/inspectors/ve.ui.MWExtensionInspector.css",
@ -1765,6 +1772,10 @@
"visualeditor-includes-onlyinclude-description",
"visualeditor-includes-onlyinclude-end",
"visualeditor-includes-onlyinclude-start",
"visualeditor-annotations-default-start",
"visualeditor-annotations-default-end",
"visualeditor-annotations-default-description",
"visualeditor-annotations-extended-documentation",
"visualeditor-mwpredialog-convert",
"visualeditor-mwpredialog-title",
"visualeditor-tooltip-non-breaking-space",

View file

@ -27,6 +27,10 @@
"tooltip-ca-editsource": "Edit the source code of this page",
"tooltip-ca-ve-edit": "Edit this page",
"visualeditor-advancedsettings-tool": "Advanced settings",
"visualeditor-annotations-default-description": "This part of the page is part of an annotation range.",
"visualeditor-annotations-default-end": "End of the annotated range",
"visualeditor-annotations-default-start": "Start of the annotated range",
"visualeditor-annotations-extended-documentation": "This annotation range has been extended because the content it enclosed was not well-nested. It is recommended to ensure that the annotated content is well-nested before editing it; otherwise, a larger range than expected might get annotated.",
"visualeditor-autosave-modified-prompt-accept": "Resume edit",
"visualeditor-autosave-modified-prompt-message": "This page was edited since you last loaded it. Would {{GENDER:|you}} like to resume {{GENDER:|your}} edit of the old version, or start a new edit of the latest version?",
"visualeditor-autosave-modified-prompt-reject": "Start a new edit",

View file

@ -45,6 +45,10 @@
"tooltip-ca-editsource": "Tooltip of the {{msg-mw|Visualeditor-ca-editsource}} tab, used if the page already exists.\n\nSee also:\n* {{msg-mw|Tooltip-ca-createsource}} - tooltip of the {{msg-mw|Visualeditor-ca-createsource}} tab, used if the page does not exist",
"tooltip-ca-ve-edit": "Tooltip of the dedicated VisualEditor \"Edit\" tab.\n{{Identical|Edit this page}}",
"visualeditor-advancedsettings-tool": "Tool for opening the advanced settings section of the meta dialog.\n{{Identical|Advanced settings}}",
"visualeditor-annotations-default-description": "Default description for annotated ranges",
"visualeditor-annotations-default-end": "Label of the context item for a closing annotation tag without message",
"visualeditor-annotations-default-start": "Label of the context item for an opening annotation tag without message",
"visualeditor-annotations-extended-documentation": "Message indicating that extended ranges should be avoided",
"visualeditor-autosave-modified-prompt-accept": "Button label in prompt to accept recovering their changes.",
"visualeditor-autosave-modified-prompt-message": "Contents of prompt shown when recovering changes against an old document version.",
"visualeditor-autosave-modified-prompt-reject": "Button label in prompt to reject recovering their changes, and start a new edit.",

View file

@ -0,0 +1,34 @@
/*!
* VisualEditor ContentEditable MWAlienAnnotationNode class.
*
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MediaWiki alien annotation node.
*
* @class
* @abstract
* @extends ve.ce.MWAnnotationNode
*
* @constructor
* @param {ve.dm.MWAlienAnnotationNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWAlienAnnotationNode = function VeCeMWAlienAnnotationNode() {
// Parent constructor
ve.ce.MWAlienAnnotationNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWAlienAnnotationNode, ve.ce.MWAnnotationNode );
/* Static members */
ve.ce.MWAlienAnnotationNode.static.name = 'mwAlienAnnotation';
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWAlienAnnotationNode );

View file

@ -0,0 +1,29 @@
/*!
* VisualEditor ContentEditable MWAnnotationNode class.
*
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MW node for annotation tags.
*
* @class
* @extends ve.ce.AlienInlineNode
* @constructor
* @param {ve.dm.MWAnnotationNode} model
* @param {Object} [config]
*/
ve.ce.MWAnnotationNode = function VeCeMWAnnotationNode() {
// Parent constructor
ve.ce.MWAnnotationNode.super.apply( this, arguments );
// DOM changes
this.$element
.addClass( 've-ce-mwAnnotationNode' )
.text( this.model.getWikitextTag() );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWAnnotationNode, ve.ce.AlienInlineNode );

View file

@ -0,0 +1,14 @@
/*!
* VisualEditor ContentEditable MediaWiki MWAnnotationNode styles.
*
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
.ve-ce-mwAnnotationNode {
display: inline-block;
opacity: 0.5;
/* Support: Blink, Gecko, Webkit */
/* Specify a valid second value to fix size, see T176636 */
font-family: monospace, monospace;
}

View file

@ -28,8 +28,8 @@ OO.inheritClass( ve.dm.MWAlienMetaItem, ve.dm.AlienMetaItem );
ve.dm.MWAlienMetaItem.static.name = 'mwAlienMeta';
ve.dm.MWAlienMetaItem.static.matchRdfaTypes = [
// HACK: Avoid matching things that are better handled by MWAlienExtensionNode or MWIncludesNode
/^mw:(?!Extension|Includes)/
// HACK: Avoid matching things that are better handled by MWAlienExtensionNode or MWIncludesNode or MWAnnotationNode
/^mw:(?!Extension|Includes|Annotation)/
];
// toDataElement inherited from AlienMetaItem, will return regular alienMeta elements but

View file

@ -0,0 +1,56 @@
/*!
* VisualEditor DataModel MWAlienAnnotationNode class.
*
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MediaWiki alien annotation node.
*
* @class
* @abstract
* @extends ve.dm.MWAnnotationNode
*
* @constructor
* @param {Object} [element] Reference to element in linear model
* @param {ve.dm.Node[]} [children]
*/
ve.dm.MWAlienAnnotationNode = function VeDmMWAlienAnnotationNode() {
// Parent constructor
ve.dm.MWAlienAnnotationNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWAlienAnnotationNode, ve.dm.MWAnnotationNode );
/* Static members */
ve.dm.MWAlienAnnotationNode.static.name = 'mwAlienAnnotation';
ve.dm.MWAlienAnnotationNode.static.matchRdfaTypes = [
/^mw:Annotation\//
];
/* Methods */
ve.dm.MWAlienAnnotationNode.static.toDataElement = function ( domElements ) {
// 'Parent' method
var element = ve.dm.MWAlienAnnotationNode.super.static.toDataElement.call( this, domElements );
element.type = 'mwAlienAnnotation';
return element;
};
ve.dm.MWAlienAnnotationNode.prototype.getWikitextTag = function () {
var type = this.getAttribute( 'type' );
if ( type.indexOf( '/End', type.length - 4 ) !== -1 ) {
return '</UNKNOWN>';
}
return '<UNKNOWN>';
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWAlienAnnotationNode );

View file

@ -0,0 +1,65 @@
/*!
* VisualEditor DataModel MWAnnotationNode class.
*
* @copyright 2011-2021 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MW node for mw:Annotation tags.
*
* @class
* @extends ve.dm.AlienInlineNode
* @constructor
* @param {Object} element Reference to element in linear model
*/
ve.dm.MWAnnotationNode = function VeDmMWAnnotationNode() {
// Parent constructor
ve.dm.MWAnnotationNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWAnnotationNode, ve.dm.AlienInlineNode );
/* Static Properties */
ve.dm.MWAnnotationNode.static.name = 'mwAnnotation';
ve.dm.MWAnnotationNode.static.preserveHtmlAttributes = true;
/* Static Methods */
/**
* @inheritdoc
*/
ve.dm.MWAnnotationNode.static.toDataElement = function ( domElements ) {
var dataElement,
mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
type = domElements[ 0 ].getAttribute( 'typeof' );
dataElement = {
type: 'mwAnnotation',
attributes: {
type: type
}
};
if ( mwDataJSON !== null ) {
dataElement.attributes.mw = JSON.parse( mwDataJSON );
}
return dataElement;
};
ve.dm.MWAnnotationNode.static.toDomElements = function ( dataElement, doc ) {
var el;
el = doc.createElement( 'meta' );
el.setAttribute( 'typeof', dataElement.attributes.type );
if ( dataElement.attributes.mw ) {
el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
}
return [ el ];
};

View file

@ -0,0 +1,54 @@
/*!
* VisualEditor MWAlienAnnotationContextItem class.
*
* @copyright 2011-2021 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* Context item for a MWAlienAnnotation
*
* @class
* @extends ve.ui.MWAnnotationContextItem
*
* @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.MWAlienAnnotationContextItem = function VeUiMWAlienAnnotationContextItem() {
// Parent constructor
ve.ui.MWAlienAnnotationContextItem.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWAlienAnnotationContextItem, ve.ui.MWAnnotationContextItem );
/* Static Properties */
ve.ui.MWAlienAnnotationContextItem.static.name = 'mwAlienAnnotation';
ve.ui.MWAlienAnnotationContextItem.static.modelClasses = [
ve.dm.MWAlienAnnotationNode
];
/* Methods */
ve.ui.MWAlienAnnotationContextItem.prototype.getLabelMessage = function () {
var type = this.model.getAttribute( 'type' );
if ( type.indexOf( '/End', type.length - 4 ) !== -1 ) {
return mw.message( 'visualeditor-annotations-default-end' ).text();
} else {
return mw.message( 'visualeditor-annotations-default-start' ).text();
}
};
ve.ui.MWAlienAnnotationContextItem.prototype.getDescriptionMessage = function () {
var type = this.model.getAttribute( 'type' );
if ( type.indexOf( '/End', type.length - 4 ) !== -1 ) {
return '';
}
return mw.message( 'visualeditor-annotations-default-description' ).parseDom();
};
ve.ui.contextItemFactory.register( ve.ui.MWAlienAnnotationContextItem );

View file

@ -0,0 +1,64 @@
/*!
* VisualEditor MWAnnotationContextItem class.
*
* @copyright 2011-2021 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* Context item for a MWAnnotation
*
* @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.MWAnnotationContextItem = function VeUiMWAnnotationContextItem() {
// Parent constructor
ve.ui.MWAnnotationContextItem.super.apply( this, arguments );
// Initialization
this.$element.addClass( 've-ui-mwAnnotationContextItem' );
this.setLabel( this.getLabelMessage() );
this.$actions.remove();
};
/* Inheritance */
OO.inheritClass( ve.ui.MWAnnotationContextItem, ve.ui.LinearContextItem );
/* Static Properties */
ve.ui.MWAnnotationContextItem.static.editable = false;
ve.ui.MWAnnotationContextItem.static.name = 'mwAnnotation';
ve.ui.MWAnnotationContextItem.static.icon = 'markup';
ve.ui.MWAnnotationContextItem.static.modelClasses = [
ve.dm.MWAnnotationNode
];
/* Methods */
/**
* @inheritdoc
*/
ve.ui.MWAnnotationContextItem.prototype.renderBody = function () {
this.$body.empty();
var $desc = this.getDescriptionMessage();
if ( $desc ) {
this.$body.append( $desc ).append( mw.msg( 'word-separator' ) );
}
if ( this.model.getAttribute( 'mw' ) ) {
if ( this.model.getAttribute( 'mw' ).extendedRange ) {
this.$body.append( mw.message( 'visualeditor-annotations-extended-documentation' ).parseDom() );
}
}
};