Merge "Adding extendsRef to reference model"

This commit is contained in:
jenkins-bot 2023-05-30 10:20:55 +00:00 committed by Gerrit Code Review
commit fc1e14cae7
7 changed files with 42 additions and 1 deletions

View file

@ -155,6 +155,7 @@
"cite-ve-citationneeded-title",
"cite-ve-dialog-reference-editing-reused",
"cite-ve-dialog-reference-editing-reused-long",
"cite-ve-dialog-reference-editing-extends",
"cite-ve-dialog-reference-options-group-label",
"cite-ve-dialog-reference-options-group-placeholder",
"cite-ve-dialog-reference-options-name-label",

View file

@ -36,6 +36,7 @@
"cite-ve-citationneeded-title": "Citation needed",
"cite-ve-dialog-reference-editing-reused": "This reference is used {{PLURAL:$1|once|2=twice|$1 times}} on this page.",
"cite-ve-dialog-reference-editing-reused-long": "This reference is used {{PLURAL:$1|once|2=twice|$1 times}} on this page. Changes made here will be applied in all places where this reference is reused.",
"cite-ve-dialog-reference-editing-extends": "This is an extension of another reference.",
"cite-ve-dialog-reference-options-group-label": "Use this group",
"cite-ve-dialog-reference-options-group-placeholder": "General references",
"cite-ve-dialog-reference-options-name-label": "Re-use by this name",

View file

@ -50,6 +50,7 @@
"cite-ve-citationneeded-title": "Title of citation needed context",
"cite-ve-dialog-reference-editing-reused": "Text shown in reference context menu when editing a reference that is used multiple times. This is a shorter version of {{msg-mw|cite-ve-dialog-reference-editing-reused-long}}.\n\nParameters:\n* $1 - Number of times used. This is always greater than 1.\n\nNote that the explicit '2' value is useful in English, but not necessarily for other languages. Don't translate the 2 value if it's not useful for your language.",
"cite-ve-dialog-reference-editing-reused-long": "Text shown at the top of the reference dialog when editing a reference that is used multiple times. This is a more detailed version of {{msg-mw|cite-ve-dialog-reference-editing-reused}}.\n\nParameters:\n* $1 - Number of times used. This is always greater than 1.\n\nNote that the explicit '2' value is useful in English, but not necessarily for other languages. Don't translate the 2 value if it's not useful for your language.",
"cite-ve-dialog-reference-editing-extends": "{{notranslate}}\\n\\nText shown in reference context menu when editing a reference that extends another reference.",
"cite-ve-dialog-reference-options-group-label": "Label for the reference group input",
"cite-ve-dialog-reference-options-group-placeholder": "Placeholder for the reference group input",
"cite-ve-dialog-reference-options-name-label": "Label for the reference name input",

View file

@ -19,6 +19,7 @@ ve.dm.MWReferenceModel = function VeDmMWReferenceModel( parentDoc ) {
OO.EventEmitter.call( this );
// Properties
this.extendsRef = null;
this.listKey = '';
this.listGroup = '';
this.listIndex = null;
@ -46,6 +47,7 @@ ve.dm.MWReferenceModel.static.newFromReferenceNode = function ( node ) {
attr = node.getAttributes(),
ref = new ve.dm.MWReferenceModel( doc );
ref.setExtendsRef( attr.extendsRef );
ref.setListKey( attr.listKey );
ref.setListGroup( attr.listGroup );
ref.setListIndex( attr.listIndex );
@ -158,6 +160,7 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
*/
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceFragment, placeholder ) {
var attributes = {
extendsRef: this.extendsRef,
listKey: this.listKey,
listGroup: this.listGroup,
listIndex: this.listIndex,
@ -246,6 +249,15 @@ ve.dm.MWReferenceModel.prototype.setListKey = function ( listKey ) {
this.listKey = listKey;
};
/**
* Set the name of the parent reference that is being extended by the current reference.
*
* @param {string} extendsRef References parent
*/
ve.dm.MWReferenceModel.prototype.setExtendsRef = function ( extendsRef ) {
this.extendsRef = extendsRef;
};
/**
* Set name of the group a references list is in.
*

View file

@ -74,6 +74,7 @@ ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter )
var body = ( mwData.body && mwData.body.html ) ||
( reflistItemId && getReflistItemHtml( reflistItemId ) ) ||
'';
var extendsRef = mw.config.get( 'wgCiteBookReferencing' ) && mwData.attrs && mwData.attrs.extends;
var refGroup = mwData.attrs && mwData.attrs.group || '';
var listGroup = this.name + '/' + refGroup;
var autoKeyed = !mwData.attrs || mwData.attrs.name === undefined;
@ -96,6 +97,9 @@ ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter )
contentsUsed: contentsUsed
}
};
if ( extendsRef ) {
dataElement.attributes.extendsRef = extendsRef;
}
if ( reflistItemId ) {
dataElement.attributes.refListItemId = reflistItemId;
}
@ -194,6 +198,11 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
el.setAttribute( 'data-ve-ignore', 'true' );
}
// Set extends
if ( dataElement.attributes.extendsRef ) {
ve.setProp( mwData, 'attrs', 'extends', dataElement.attributes.extendsRef );
}
// Generate name
var name;
var listKeyParts = dataElement.attributes.listKey.match( this.listKeyRegex );

View file

@ -86,6 +86,22 @@ ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
}
};
/**
* Get a DOM rendering of a warning if this reference is an extension.
*
* @private
* @return {jQuery|null}
*/
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
if ( refModel.extendsRef ) {
return $( '<div>' )
.addClass( 've-ui-mwReferenceContextItem-muted' )
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) );
}
};
/**
* Get the reference node in the containing document (not the internal list document)
*
@ -113,7 +129,7 @@ ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
* @inheritdoc
*/
ve.ui.MWReferenceContextItem.prototype.renderBody = function () {
this.$body.empty().append( this.getRendering(), this.getReuseWarning() );
this.$body.empty().append( this.getRendering(), this.getReuseWarning(), this.getExtendsWarning() );
};
/**

View file

@ -47,6 +47,7 @@ class CiteHooks implements
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
$vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
$vars['wgCiteResponsiveReferences'] = $config->get( 'CiteResponsiveReferences' );
$vars['wgCiteBookReferencing'] = $config->get( 'CiteBookReferencing' );
}
/**