mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 08:50:07 +00:00
Properly bump reference anchors
* Adds an index of all the references on a page in order to avoid repeating attrs when multiple <references /> tags are present. * Update tests to reflect the new behaviour. Bug: 59782 Change-Id: Ia44bf59a9304788aca170041d3b85f53557151fc
This commit is contained in:
parent
a372d97939
commit
d2ba2d73e7
|
@ -134,30 +134,32 @@ function RefGroup(group) {
|
|||
this.indexByName = new Map();
|
||||
}
|
||||
|
||||
RefGroup.prototype.add = function(refName, about, skipLinkback) {
|
||||
RefGroup.prototype.add = function( references, refName, about, skipLinkback ) {
|
||||
var ref;
|
||||
if ( refName && this.indexByName.has( refName ) ) {
|
||||
ref = this.indexByName.get( refName );
|
||||
} else {
|
||||
var n = this.refs.length,
|
||||
var n = references.index,
|
||||
refKey = (1+n) + '';
|
||||
|
||||
// bump index
|
||||
references.index += 1;
|
||||
|
||||
if (refName) {
|
||||
refKey = refName + '-' + refKey;
|
||||
}
|
||||
|
||||
ref = {
|
||||
about: about,
|
||||
content: null,
|
||||
group: this.name,
|
||||
groupIndex: (1+n), // FIXME -- this seems to be wiki-specific
|
||||
groupIndex: this.refs.length + 1,
|
||||
index: n,
|
||||
key: refKey,
|
||||
linkbacks: [],
|
||||
name: refName,
|
||||
target: 'cite_note-' + refKey
|
||||
};
|
||||
this.refs[n] = ref;
|
||||
this.refs.push( ref );
|
||||
if (refName) {
|
||||
this.indexByName.set( refName, ref );
|
||||
}
|
||||
|
@ -230,10 +232,10 @@ function getRefGroup(refGroups, groupName, allocIfMissing) {
|
|||
|
||||
function References(cite) {
|
||||
this.cite = cite;
|
||||
this.reset();
|
||||
this.reset( null, true );
|
||||
}
|
||||
|
||||
References.prototype.reset = function(group) {
|
||||
References.prototype.reset = function( group, resetIndex ) {
|
||||
if (group) {
|
||||
this.refGroups.set( group, undefined );
|
||||
} else {
|
||||
|
@ -254,6 +256,11 @@ References.prototype.reset = function(group) {
|
|||
* ----------------------------------------------------------------- */
|
||||
this.nestedRefsHTMLMap = new Map();
|
||||
}
|
||||
|
||||
// restart reference counter
|
||||
if ( resetIndex ) {
|
||||
this.index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -355,7 +362,7 @@ References.prototype.extractRefFromNode = function(node) {
|
|||
about = node.getAttribute("about"),
|
||||
skipLinkback = dp.tmp.skiplinkback,
|
||||
refGroup = getRefGroup(this.refGroups, group, true),
|
||||
ref = refGroup.add(refName, about, skipLinkback),
|
||||
ref = refGroup.add(this, refName, about, skipLinkback),
|
||||
nodeType = (node.getAttribute("typeof") || '').replace(/mw:Extension\/ref\/Marker/, '');
|
||||
|
||||
// Add ref-index linkback
|
||||
|
@ -484,7 +491,7 @@ var Cite = function() {
|
|||
|
||||
Cite.prototype.resetState = function() {
|
||||
this.ref.reset();
|
||||
this.references.reset();
|
||||
this.references.reset( null, true );
|
||||
};
|
||||
|
||||
if (typeof module === "object") {
|
||||
|
|
Loading…
Reference in a new issue