mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
Merge "Split ref.number field"
This commit is contained in:
commit
fa4410836d
|
@ -175,7 +175,8 @@ class FootnoteBodyFormatter {
|
||||||
'cite_references_link_many_format',
|
'cite_references_link_many_format',
|
||||||
$this->citeKeyFormatter->refKey( $key, $val['key'] . '-' . $i ),
|
$this->citeKeyFormatter->refKey( $key, $val['key'] . '-' . $i ),
|
||||||
$this->referencesFormatEntryNumericBacklinkLabel(
|
$this->referencesFormatEntryNumericBacklinkLabel(
|
||||||
$val['number'],
|
$val['number'] .
|
||||||
|
( isset( $val['extendsIndex'] ) ? '.' . $val['extendsIndex'] : '' ),
|
||||||
$i,
|
$i,
|
||||||
$val['count']
|
$val['count']
|
||||||
),
|
),
|
||||||
|
|
|
@ -165,27 +165,13 @@ class ReferenceStack {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $extends !== null ) {
|
|
||||||
if ( isset( $this->refs[$group][$extends] ) ) {
|
|
||||||
$this->extendsCount[$group][$extends] =
|
|
||||||
( $this->extendsCount[$group][$extends] ?? 0 ) + 1;
|
|
||||||
|
|
||||||
$ref['extends'] = $this->groupRefSequence[$group] . '.' . $this->extendsCount[$group][$extends];
|
|
||||||
} else {
|
|
||||||
// TODO: check parent existence in a second, pre-render stage of validation.
|
|
||||||
// This should be an error, not silent degradation.
|
|
||||||
$extends = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$name ) {
|
if ( !$name ) {
|
||||||
// This is an anonymous reference, which will be given a numeric index.
|
// This is an anonymous reference, which will be given a numeric index.
|
||||||
$this->refs[$group][] = $ref;
|
$this->refs[$group][] =& $ref;
|
||||||
$action = 'new';
|
$action = 'new';
|
||||||
} elseif ( !isset( $this->refs[$group][$name] ) ) {
|
} elseif ( !isset( $this->refs[$group][$name] ) ) {
|
||||||
// Valid key with first occurrence
|
// Valid key with first occurrence
|
||||||
$ref['number'] = $ref['extends'] ?? ++$this->groupRefSequence[$group];
|
$this->refs[$group][$name] =& $ref;
|
||||||
$this->refs[$group][$name] = $ref;
|
|
||||||
$action = 'new';
|
$action = 'new';
|
||||||
} else {
|
} else {
|
||||||
// Change an existing entry.
|
// Change an existing entry.
|
||||||
|
@ -215,11 +201,29 @@ class ReferenceStack {
|
||||||
$action = 'increment';
|
$action = 'increment';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ref['number'] = $ref['number'] ?? ++$this->groupRefSequence[$group];
|
||||||
|
|
||||||
|
if ( $extends ) {
|
||||||
|
if ( isset( $this->refs[$group][$extends] ) ) {
|
||||||
|
$ref['extends'] = $extends;
|
||||||
|
$ref['extendsIndex'] = $this->extendsCount[$group][$extends] =
|
||||||
|
( $this->extendsCount[$group][$extends] ?? 0 ) + 1;
|
||||||
|
|
||||||
|
$ref['number'] = $this->refs[$group][$extends]['number'];
|
||||||
|
} else {
|
||||||
|
// TODO: check parent existence in a second, pre-render stage of validation.
|
||||||
|
// This should be an error, not silent degradation.
|
||||||
|
$extends = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->refCallStack[] = [ $action, $argv, $text, $name, $extends, $group, $ref['key'] ];
|
$this->refCallStack[] = [ $action, $argv, $text, $name, $extends, $group, $ref['key'] ];
|
||||||
return [
|
return [
|
||||||
$name ?? $ref['key'],
|
$name ?? $ref['key'],
|
||||||
$name ? $ref['key'] . '-' . $ref['count'] : null,
|
$name ? $ref['key'] . '-' . $ref['count'] : null,
|
||||||
$ref['extends'] ?? $ref['number'] ?? ++$this->groupRefSequence[$group],
|
$ref['number'] .
|
||||||
|
( isset( $ref['extendsIndex'] ) ? '.' . $ref['extendsIndex'] : '' ),
|
||||||
$name ? '-' . $ref['key'] : null
|
$name ? '-' . $ref['key'] : null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,11 +152,11 @@ wgCiteBookReferencing=true
|
||||||
!! html/php
|
!! html/php
|
||||||
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
<sup id="cite_ref-b_2-0" class="reference"><a href="#cite_note-b-2">[1.1]</a></sup>
|
<sup id="cite_ref-b_2-0" class="reference"><a href="#cite_note-b-2">[1.1]</a></sup>
|
||||||
<sup id="cite_ref-b_2-1" class="reference"><a href="#cite_note-b-2">[1.1]</a></sup>
|
<sup id="cite_ref-b_2-1" class="reference"><a href="#cite_note-b-2">[1.2]</a></sup>
|
||||||
</p>
|
</p>
|
||||||
<div class="mw-references-wrap"><ol class="references">
|
<div class="mw-references-wrap"><ol class="references">
|
||||||
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
||||||
<ol class="mw-extended-references"><li id="cite_note-b-2"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-b_2-0">1.1.0</a></sup> <sup><a href="#cite_ref-b_2-1">1.1.1</a></sup></span> <span class="reference-text">page 2 <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag; name "b" defined multiple times with different content</span></span>
|
<ol class="mw-extended-references"><li id="cite_note-b-2"><span class="mw-cite-backlink">↑ <sup><a href="#cite_ref-b_2-0">1.2.0</a></sup> <sup><a href="#cite_ref-b_2-1">1.2.1</a></sup></span> <span class="reference-text">page 2 <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code><ref></code> tag; name "b" defined multiple times with different content</span></span>
|
||||||
</li>
|
</li>
|
||||||
</ol></li>
|
</ol></li>
|
||||||
</ol></div>
|
</ol></div>
|
||||||
|
@ -454,9 +454,9 @@ Extends <ref> defined in <references> called with #tag
|
||||||
</p>
|
</p>
|
||||||
<div class="mw-references-wrap"><ol class="references">
|
<div class="mw-references-wrap"><ol class="references">
|
||||||
<li id="cite_note-foo-1"><span class="mw-cite-backlink"><a href="#cite_ref-foo_1-0">↑</a></span> <span class="reference-text">BAR</span>
|
<li id="cite_note-foo-1"><span class="mw-cite-backlink"><a href="#cite_ref-foo_1-0">↑</a></span> <span class="reference-text">BAR</span>
|
||||||
|
<ol class="mw-extended-references"><li id="cite_note-footwo-2"><span class="mw-cite-backlink"><a href="#cite_ref-footwo_2-0">↑</a></span> <span class="reference-text">p. 10</span>
|
||||||
</li>
|
</li>
|
||||||
<li id="cite_note-footwo-2"><span class="mw-cite-backlink"><a href="#cite_ref-footwo_2-0">↑</a></span> <span class="reference-text">p. 10</span>
|
</ol></li>
|
||||||
</li>
|
|
||||||
</ol></div>
|
</ol></div>
|
||||||
!! end
|
!! end
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ wgCiteBookReferencing=true
|
||||||
!! html/php
|
!! html/php
|
||||||
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
<p><sup id="cite_ref-a_1-0" class="reference"><a href="#cite_note-a-1">[1]</a></sup>
|
||||||
<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">[2]</a></sup>
|
<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">[2]</a></sup>
|
||||||
<sup id="cite_ref-3" class="reference"><a href="#cite_note-3">[2.1]</a></sup>
|
<sup id="cite_ref-3" class="reference"><a href="#cite_note-3">[1.1]</a></sup>
|
||||||
</p>
|
</p>
|
||||||
<div class="mw-references-wrap"><ol class="references">
|
<div class="mw-references-wrap"><ol class="references">
|
||||||
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
<li id="cite_note-a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_1-0">↑</a></span> <span class="reference-text">book</span>
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text', null, '', null, null, [], 'rtl' ]
|
[ 'text', null, '', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 1, null, 1, null ]
|
[ 1, null, '1', null ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'' => [
|
'' => [
|
||||||
|
@ -72,6 +72,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 1,
|
'key' => 1,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text',
|
'text' => 'text',
|
||||||
|
'number' => 1,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -84,7 +85,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 1, null, 1, null ]
|
[ 1, null, '1', null ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -94,6 +95,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 1,
|
'key' => 1,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text',
|
'text' => 'text',
|
||||||
|
'number' => 1,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -106,7 +108,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
[ 'text', null, 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 1, null, 1, null ]
|
[ 1, null, '1', null ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -116,6 +118,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 1,
|
'key' => 1,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text',
|
'text' => 'text',
|
||||||
|
'number' => 1,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -128,7 +131,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text', 'name', 'foo', null, null, [], 'rtl' ]
|
[ 'text', 'name', 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'name', '1-0', 1, '-1' ]
|
[ 'name', '1-0', '1', '-1' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -152,7 +155,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-b', 'b', 'foo', null, 'a', [], 'rtl' ]
|
[ 'text-b', 'b', 'foo', null, 'a', [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
null
|
null
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -201,9 +204,9 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
|
[ 'text-c', 'c', 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
null,
|
null,
|
||||||
[ 'c', '3-0', 2, '-3' ],
|
[ 'c', '3-0', '2', '-3' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -245,8 +248,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ null, 'a', 'foo', null, null, [], 'rtl' ]
|
[ null, 'a', 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 'a', '1-1', 1, '-1' ],
|
[ 'a', '1-1', '1', '-1' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -271,8 +274,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
|
[ 'text', 'a', 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 'a', '1-1', 1, '-1' ],
|
[ 'a', '1-1', '1', '-1' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -297,8 +300,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-2', 'a', 'foo', null, null, [], 'rtl' ]
|
[ 'text-2', 'a', 'foo', null, null, [], 'rtl' ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 'a', '1-1', 1, '-1' ],
|
[ 'a', '1-1', '1', '-1' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -322,7 +325,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
[ 'text-a', 'a', 'foo', 'b', null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -346,8 +349,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 'b', '2-0', 2, '-2' ],
|
[ 'b', '2-0', '2', '-2' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -380,7 +383,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-b', 'b', 'foo', 'a', null, [], 'rtl' ],
|
[ 'text-b', 'b', 'foo', 'a', null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 'b', '2-0', '1.1', '-2' ],
|
[ 'b', '2-0', '1.1', '-2' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -399,8 +402,9 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 2,
|
'key' => 2,
|
||||||
'name' => 'b',
|
'name' => 'b',
|
||||||
'text' => 'text-b',
|
'text' => 'text-b',
|
||||||
'extends' => '1.1',
|
'number' => 1,
|
||||||
'number' => '1.1',
|
'extends' => 'a',
|
||||||
|
'extendsIndex' => 1,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -414,7 +418,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
[ 'text-a', null, 'foo', 'b', null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 1, null, 1, null ],
|
[ 1, null, '1', null ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -424,6 +428,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 1,
|
'key' => 1,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text-a',
|
'text' => 'text-a',
|
||||||
|
'number' => 1,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -437,8 +442,8 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
[ 'text-b', 'b', 'foo', null, null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 1, null, 1, null ],
|
[ 1, null, '1', null ],
|
||||||
[ 'b', '2-0', 2, '-2' ],
|
[ 'b', '2-0', '2', '-2' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'foo' => [
|
'foo' => [
|
||||||
|
@ -448,6 +453,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 1,
|
'key' => 1,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text-a',
|
'text' => 'text-a',
|
||||||
|
'number' => 1,
|
||||||
],
|
],
|
||||||
'b' => [
|
'b' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
|
@ -470,7 +476,7 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
[ 'text-b', null, 'foo', 'a', null, [], 'rtl' ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[ 'a', '1-0', 1, '-1' ],
|
[ 'a', '1-0', '1', '-1' ],
|
||||||
[ 2, null, '1.1', null ],
|
[ 2, null, '1.1', null ],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -489,7 +495,9 @@ class ReferenceStackTest extends MediaWikiUnitTestCase {
|
||||||
'key' => 2,
|
'key' => 2,
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'text' => 'text-b',
|
'text' => 'text-b',
|
||||||
'extends' => '1.1',
|
'number' => 1,
|
||||||
|
'extends' => 'a',
|
||||||
|
'extendsIndex' => 1,
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue