mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-09-24 10:48:58 +00:00
Merge "Treat template-generated reference lists as real ones"
This commit is contained in:
commit
7554c3688b
|
@ -105,6 +105,7 @@ class CiteHooks {
|
|||
"cite-ve-referenceslist-isempty",
|
||||
"cite-ve-referenceslist-isempty-default",
|
||||
"cite-ve-referenceslist-missingref",
|
||||
"cite-ve-referenceslist-missingreflist",
|
||||
"visualeditor-internal-list-diff-default-group-name-mwreference",
|
||||
"visualeditor-internal-list-diff-group-name-mwreference"
|
||||
],
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
"cite-ve-referenceslist-isempty": "There are no references with the group \"$1\" on this page to include in this list.",
|
||||
"cite-ve-referenceslist-isempty-default": "There are no references on this page to include in this list.",
|
||||
"cite-ve-referenceslist-missingref": "This reference is defined in a template or other generated block, and for now can only be edited in source mode.",
|
||||
"cite-ve-referenceslist-missingreflist": "This reference list is generated by a template, and for now can only be edited in source mode.",
|
||||
"cite-ve-toolbar-group-label": "Cite",
|
||||
"cite-ve-othergroup-item": "$1 reference",
|
||||
"visualeditor-internal-list-diff-default-group-name-mwreference": "References",
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
"cite-ve-referenceslist-isempty": "Message that appears in the references list when there are no references on the page of that group.\n\nParameters:\n* $1 - reference-group name",
|
||||
"cite-ve-referenceslist-isempty-default": "Message that appears in the references list when there are no references on the page in the default group.",
|
||||
"cite-ve-referenceslist-missingref": "Message that appears in the references list, and as a tooltip on the reference itself, for references that are generated by a template or are otherwise uneditable.\n\nSee also:\n* {{msg-mw|visualeditor-dialog-meta-languages-readonlynote}}",
|
||||
"cite-ve-referenceslist-missingreflist": "Message that appears as a tooltip on the reference list for lists that are generated by a template.",
|
||||
"cite-ve-toolbar-group-label": "Label text for the toolbar button for inserting customized references.\n{{Identical|Cite}}",
|
||||
"cite-ve-othergroup-item": "Label text for the toolbar items under the 'Insert' (other) group if VisualEditor is configured that way.\n\nParameters:\n* $1 – citation type label\n** {{msg-mw|cite-ve-dialogbutton-reference-tooltip}}\n** {{msg-mw|cite-ve-dialog-reference-useexisting-tool}})\n{{Identical|Reference}}",
|
||||
"visualeditor-internal-list-diff-default-group-name-mwreference": "Heading in the visual diff for the default reference group.\n{{Identical|Reference}}",
|
||||
|
|
|
@ -18,37 +18,37 @@ ve.dm.citeExample.domToDataCases = {
|
|||
// <references group="g1"><ref group="g1" name="foo">Ref in refs</ref></references>
|
||||
body:
|
||||
'<p>Foo' +
|
||||
'<sup about="#mwt1" class="reference" data-mw="{"name":"ref","attrs":{"name":"bar"}}" id="cite_ref-bar-1-0" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'<sup about="#mwt1" class="reference" data-mw="{"name":"ref","attrs":{"name":"bar"}}" id="cite_ref-bar-1-0" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-bar-1">[1]</a>' +
|
||||
'</sup>' +
|
||||
' Baz' +
|
||||
'<sup about="#mwt2" class="reference" data-mw="{"name":"ref","body":{"html":"Quux"},"attrs":{"group":"g1","name":":0"}}" id="cite_ref-quux-2-0" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'<sup about="#mwt2" class="reference" data-mw="{"name":"ref","body":{"html":"Quux"},"attrs":{"group":"g1","name":":0"}}" id="cite_ref-quux-2-0" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-.3A0-2">[g1 1]</a>' +
|
||||
'</sup>' +
|
||||
' Whee' +
|
||||
'<sup about="#mwt3" class="reference" data-mw="{"name":"ref","body":{"html":"' +
|
||||
'<a rel=\\"mw:WikiLink\\" href=\\"./Bar\\">Bar' +
|
||||
'</a>"},"attrs":{"name":"bar"}}" id="cite_ref-bar-1-1" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'</a>"},"attrs":{"name":"bar"}}" id="cite_ref-bar-1-1" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-bar-1">[1]</a>' +
|
||||
'</sup>' +
|
||||
' Yay' +
|
||||
// This reference has .body.id instead of .body.html
|
||||
'<sup about="#mwt4" class="reference" data-mw="{"name":"ref","body":{"id":"mw-cite-3"},"attrs":{"group":"g1"}}" id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'<sup about="#mwt4" class="reference" data-mw="{"name":"ref","body":{"id":"mw-cite-3"},"attrs":{"group":"g1"}}" id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-3">[g1 2]</a>' +
|
||||
'</sup>' +
|
||||
' Quux' +
|
||||
'<sup about="#mwt5" class="reference" data-mw="{"name":"ref","body":{"html":"Different content"},"attrs":{"name":"bar"}}" id="cite_ref-bar-1-2" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'<sup about="#mwt5" class="reference" data-mw="{"name":"ref","body":{"html":"Different content"},"attrs":{"name":"bar"}}" id="cite_ref-bar-1-2" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-bar-1">[1]</a>' +
|
||||
'</sup>' +
|
||||
' Foo' +
|
||||
'<sup about="#mwt6" class="reference" data-mw="{"name":"ref","attrs":{"group":"g1","name":"foo"}}" ' +
|
||||
'id="cite_ref-foo-4" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'id="cite_ref-foo-4" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_ref-foo-4">[g1 3]</a>' +
|
||||
'</sup>' +
|
||||
'</p>' +
|
||||
// The HTML below is enriched to wrap reference contents in <span id="mw-cite-[...]">
|
||||
// which Parsoid doesn't do yet, but T88290 asks for
|
||||
'<ol class="references" typeof="mw:Extension/references" about="#mwt7" data-parsoid="{}"' +
|
||||
'<ol class="references" typeof="mw:Extension/references" about="#mwt7"' +
|
||||
'data-mw="{"name":"references","body":{' +
|
||||
'"html":"<sup about=\\"#mwt8\\" class=\\"reference\\" ' +
|
||||
'data-mw=\\"{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;Ref in refs&quot;},' +
|
||||
|
@ -242,7 +242,8 @@ ve.dm.citeExample.domToDataCases = {
|
|||
originalMw: '{"name":"references","body":{"html":"<sup about=\\"#mwt8\\" class=\\"reference\\" data-mw=\\"{"name":"ref","body":{"html":"Ref in refs"},"attrs":{"group":"g1","name":"foo"}}\\" rel=\\"dc:references\\" typeof=\\"mw:Extension/ref\\"><a href=\\"#cite_note-foo-3\\">[3]</a></sup>"},"attrs":{"group":"g1"}}',
|
||||
listGroup: 'mwReference/g1',
|
||||
refGroup: 'g1',
|
||||
isResponsive: true
|
||||
isResponsive: true,
|
||||
templateGenerated: false
|
||||
}
|
||||
},
|
||||
{ type: 'paragraph', internal: { generated: 'wrapper' } },
|
||||
|
@ -327,8 +328,8 @@ ve.dm.citeExample.domToDataCases = {
|
|||
body: '<p><sup about="#mwt2" class="reference" ' +
|
||||
'data-mw="{"name":"ref","body":' +
|
||||
'{"html":"Foo<!-- bar -->"},"attrs":{}}" ' +
|
||||
'id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref" data-parsoid="{}">' +
|
||||
'<a href="#cite_note-bar-1" data-parsoid="{}">[1]</a></sup></p>',
|
||||
'id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref">' +
|
||||
'<a href="#cite_note-bar-1">[1]</a></sup></p>',
|
||||
fromDataBody: '<p><sup ' +
|
||||
'data-mw="{"name":"ref","body":' +
|
||||
'{"html":"Foo<!-- bar -->"},"attrs":{}}" ' +
|
||||
|
@ -381,6 +382,75 @@ ve.dm.citeExample.domToDataCases = {
|
|||
{ type: '/internalItem' },
|
||||
{ type: '/internalList' }
|
||||
]
|
||||
},
|
||||
'Template generated reflist (div wrapped)': {
|
||||
body: '<p><sup about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}"><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>' +
|
||||
'<div about="#mwt3" typeof="mw:Transclusion" data-mw="{"parts":[{"template":{"target":{"wt":"reflist","href":"./Template:Reflist"},"params":{},"i":0}}]}">' +
|
||||
'<div typeof="mw:Extension/references" about="#mwt5" data-mw="{"name":"references","attrs":{}}">' +
|
||||
'<ol class="mw-references references">' +
|
||||
'<li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">Foo</span></li>' +
|
||||
'</ol>' +
|
||||
'</div>' +
|
||||
'</div>',
|
||||
fromDataBody: '<p><sup typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}"></sup></p>' +
|
||||
'<span typeof="mw:Transclusion" data-mw="{"name":"references","attrs":{}}"></span>',
|
||||
clipboardBody: '<p><sup typeof="mw:Extension/ref" data-mw="{"attrs":{},"body":{"id":"mw-reference-text-cite_note-1","html":"Foo"},"name":"ref"}" class="mw-ref"><a style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>' +
|
||||
'<div typeof="mw:Extension/references" data-mw="{"name":"references","attrs":{}}">' +
|
||||
'<ol class="mw-references references">' +
|
||||
'<li><a rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a><span class="reference-text"><span class="ve-ce-branchNode ve-ce-internalItemNode">Foo</span></span></li>' +
|
||||
'</ol>' +
|
||||
'</div>',
|
||||
data: [
|
||||
{ type: 'paragraph' },
|
||||
{
|
||||
type: 'mwReference',
|
||||
attributes: {
|
||||
contentsUsed: true,
|
||||
listGroup: 'mwReference/',
|
||||
listIndex: 0,
|
||||
listKey: 'auto/0',
|
||||
mw: {
|
||||
attrs: {},
|
||||
body: {
|
||||
id: 'mw-reference-text-cite_note-1'
|
||||
},
|
||||
name: 'ref'
|
||||
},
|
||||
originalMw: '{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}',
|
||||
refGroup: '',
|
||||
refListItemId: 'mw-reference-text-cite_note-1'
|
||||
}
|
||||
},
|
||||
{ type: '/mwReference' },
|
||||
{ type: '/paragraph' },
|
||||
{
|
||||
type: 'mwReferencesList',
|
||||
attributes: {
|
||||
mw: {
|
||||
name: 'references',
|
||||
attrs: {}
|
||||
},
|
||||
originalMw: '{"name":"references","attrs":{}}',
|
||||
refGroup: '',
|
||||
listGroup: 'mwReference/',
|
||||
isResponsive: true,
|
||||
templateGenerated: true
|
||||
}
|
||||
},
|
||||
{ type: '/mwReferencesList' },
|
||||
{ type: 'internalList' },
|
||||
{ type: 'internalItem', attributes: { originalHtml: 'Foo' } },
|
||||
{
|
||||
internal: {
|
||||
generated: 'wrapper'
|
||||
},
|
||||
type: 'paragraph'
|
||||
},
|
||||
'F', 'o', 'o',
|
||||
{ type: '/paragraph' },
|
||||
{ type: '/internalItem' },
|
||||
{ type: '/internalList' }
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -507,7 +577,8 @@ ve.dm.citeExample.references = [
|
|||
originalMw: '{"name":"references","attrs":{"group":"g1"}"}',
|
||||
listGroup: 'mwReference/',
|
||||
refGroup: '',
|
||||
isResponsive: true
|
||||
isResponsive: true,
|
||||
templateGenerated: false
|
||||
}
|
||||
},
|
||||
{ type: '/mwReferencesList' },
|
||||
|
|
|
@ -30,6 +30,12 @@ OO.inheritClass( ve.dm.MWReferencesListNode, ve.dm.BranchNode );
|
|||
|
||||
OO.mixinClass( ve.dm.MWReferencesListNode, ve.dm.FocusableNode );
|
||||
|
||||
/* Methods */
|
||||
|
||||
ve.dm.MWReferencesListNode.prototype.isEditable = function () {
|
||||
return !this.getAttribute( 'templateGenerated' );
|
||||
};
|
||||
|
||||
/* Static members */
|
||||
|
||||
ve.dm.MWReferencesListNode.static.name = 'mwReferencesList';
|
||||
|
@ -40,18 +46,38 @@ ve.dm.MWReferencesListNode.static.ignoreChildren = true;
|
|||
|
||||
ve.dm.MWReferencesListNode.static.matchTagNames = null;
|
||||
|
||||
ve.dm.MWReferencesListNode.static.matchRdfaTypes = [ 'mw:Extension/references' ];
|
||||
ve.dm.MWReferencesListNode.static.matchRdfaTypes = [ 'mw:Extension/references', 'mw:Transclusion' ];
|
||||
|
||||
ve.dm.MWReferencesListNode.static.matchFunction = function ( domElement ) {
|
||||
function isRefList( el ) {
|
||||
return el && el.nodeType === Node.ELEMENT_NODE && ( el.getAttribute( 'typeof' ) || '' ).indexOf( 'mw:Extension/references' ) !== -1;
|
||||
}
|
||||
// If the template generated only a reference list, treat it as a ref list (T52769)
|
||||
return isRefList( domElement ) ||
|
||||
// A div-wrapped reference list
|
||||
( domElement.children.length === 1 && isRefList( domElement.children[ 0 ] ) );
|
||||
};
|
||||
|
||||
ve.dm.MWReferencesListNode.static.preserveHtmlAttributes = false;
|
||||
|
||||
ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, converter ) {
|
||||
var referencesListData, contentsDiv, contentsData,
|
||||
isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' ),
|
||||
mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
||||
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
||||
refGroup = ve.getProp( mwData, 'attrs', 'group' ) || '',
|
||||
responsiveAttr = ve.getProp( mwData, 'attrs', 'responsive' ),
|
||||
listGroup = 'mwReference/' + refGroup;
|
||||
var referencesListData, contentsDiv, contentsData, refListNode,
|
||||
mwDataJSON, mwData, refGroup, responsiveAttr, listGroup,
|
||||
templateGenerated = false,
|
||||
isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );
|
||||
|
||||
if ( ( domElements[ 0 ].getAttribute( 'typeof' ) || '' ).indexOf( 'mw:Extension/references' ) !== -1 ) {
|
||||
refListNode = domElements[ 0 ];
|
||||
} else {
|
||||
refListNode = domElements[ 0 ].querySelectorAll( '[typeof*="mw:Extension/references"]' )[ 0 ];
|
||||
templateGenerated = true;
|
||||
}
|
||||
|
||||
mwDataJSON = refListNode.getAttribute( 'data-mw' );
|
||||
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
||||
refGroup = ve.getProp( mwData, 'attrs', 'group' ) || '';
|
||||
responsiveAttr = ve.getProp( mwData, 'attrs', 'responsive' );
|
||||
listGroup = 'mwReference/' + refGroup;
|
||||
|
||||
referencesListData = {
|
||||
type: this.name,
|
||||
|
@ -60,7 +86,8 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
|
|||
originalMw: mwDataJSON,
|
||||
refGroup: refGroup,
|
||||
listGroup: listGroup,
|
||||
isResponsive: responsiveAttr !== undefined ? responsiveAttr !== '0' : isResponsiveDefault
|
||||
isResponsive: responsiveAttr !== undefined ? responsiveAttr !== '0' : isResponsiveDefault,
|
||||
templateGenerated: templateGenerated
|
||||
}
|
||||
};
|
||||
if ( mwData.body && mwData.body.html ) {
|
||||
|
@ -78,13 +105,20 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
|
|||
ve.dm.MWReferencesListNode.static.toDomElements = function ( data, doc, converter ) {
|
||||
var el, els, mwData, originalMw, contentsHtml, originalHtml, nextIndex, nextElement, modelNode, viewNode,
|
||||
isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' ),
|
||||
isForClipboard = converter.isForClipboard(),
|
||||
wrapper = doc.createElement( 'div' ),
|
||||
originalHtmlWrapper = doc.createElement( 'div' ),
|
||||
dataElement = data[ 0 ],
|
||||
attrs = dataElement.attributes,
|
||||
contentsData = data.slice( 1, -1 );
|
||||
|
||||
if ( converter.isForClipboard() ) {
|
||||
// If we are sending a template generated ref back to Parsoid, output it as a template.
|
||||
// This works because the dataElement already as mw, originalMw and originalDomIndex properties.
|
||||
if ( attrs.templateGenerated && !isForClipboard ) {
|
||||
return ve.dm.MWTransclusionNode.static.toDomElements.call( this, dataElement, doc, converter );
|
||||
}
|
||||
|
||||
if ( isForClipboard ) {
|
||||
// Output needs to be read so re-render
|
||||
modelNode = new ve.dm.MWReferencesListNode( dataElement );
|
||||
// Build from original doc's internal list to get all refs (T186407)
|
||||
|
|
|
@ -43,6 +43,22 @@ ve.ui.MWReferencesListContextItem.static.commandName = 'referencesList';
|
|||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWReferencesListContextItem.prototype.renderBody = function () {
|
||||
this.$body.append(
|
||||
$( '<div>' ).text( this.getDescription() )
|
||||
);
|
||||
if ( this.model.getAttribute( 'templateGenerated' ) ) {
|
||||
this.$body.append(
|
||||
$( '<div>' )
|
||||
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
||||
.text( ve.msg( 'cite-ve-referenceslist-missingreflist' ) )
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue