mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-18 01:30:32 +00:00
Fix inconsistencies and deep nesting for follow="…"
* This fixes the refArg() function. If there is nothing wrong with the follow="…" attribute, it should not return null. * However, *everything* is false if an unknown error (e.g. an unknown attribute) occurs. * A trivial check for `if ( $follow )` is fine because all keys are guaranteed to not be the string "0". Change-Id: Ia4e37781e01db1ee6615ffc30bb68e47023c6634
This commit is contained in:
parent
a823fa23d9
commit
177c9cc1eb
18
src/Cite.php
18
src/Cite.php
|
@ -417,7 +417,7 @@ class Cite {
|
|||
|
||||
if ( $argv === [] ) {
|
||||
// No key
|
||||
return [ null, null, false, $dir, null ];
|
||||
return [ null, null, null, $dir, null ];
|
||||
}
|
||||
|
||||
if ( isset( $argv['follow'] ) &&
|
||||
|
@ -460,7 +460,7 @@ class Cite {
|
|||
* @param string|null $text Content from the <ref> tag
|
||||
* @param string|null $key Argument to the <ref> tag as returned by $this->refArg()
|
||||
* @param string $group
|
||||
* @param string|null $follow
|
||||
* @param string|null $follow Guaranteed to not be a numeric string
|
||||
* @param string[] $call
|
||||
* @param string $dir ref direction
|
||||
* @param StripState $stripState
|
||||
|
@ -475,11 +475,14 @@ class Cite {
|
|||
if ( !isset( $this->mGroupCnt[$group] ) ) {
|
||||
$this->mGroupCnt[$group] = 0;
|
||||
}
|
||||
if ( $follow != null ) {
|
||||
|
||||
if ( $follow ) {
|
||||
// We know the parent note already, so just perform the "follow" and bail out
|
||||
if ( isset( $this->mRefs[$group][$follow] ) ) {
|
||||
// add text to the note that is being followed
|
||||
$this->mRefs[$group][$follow]['text'] .= ' ' . $text;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
// insert part of note at the beginning of the group
|
||||
$k = 0;
|
||||
foreach ( $this->mRefs[$group] as $k => $value ) {
|
||||
|
@ -492,12 +495,11 @@ class Cite {
|
|||
'text' => $text,
|
||||
'key' => ++$this->mOutCnt,
|
||||
'follow' => $follow,
|
||||
'dir' => $dir
|
||||
'dir' => $dir,
|
||||
] ] );
|
||||
array_splice( $this->mRefCallStack, $k, 0,
|
||||
[ [ 'new', $call, $text, $key, $group, $this->mOutCnt ] ] );
|
||||
}
|
||||
// return an empty string : this is not a reference
|
||||
// A "follow" never gets it's own footnote marker
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ class CiteTest extends \MediaWikiUnitTestCase {
|
|||
|
||||
public function provideRefAttributes() {
|
||||
return [
|
||||
[ [], [ null, null, false, null, null ] ],
|
||||
[ [], [ null, null, null, null, null ] ],
|
||||
|
||||
// One attribute only
|
||||
[ [ 'dir' => 'invalid' ], [ null, null, false, 'invalid', null ] ],
|
||||
[ [ 'dir' => ' rtl ' ], [ null, null, false, 'rtl', null ] ],
|
||||
[ [ 'dir' => 'invalid' ], [ null, null, null, 'invalid', null ] ],
|
||||
[ [ 'dir' => ' rtl ' ], [ null, null, null, 'rtl', null ] ],
|
||||
[ [ 'follow' => ' f ' ], [ null, null, 'f', null, null ] ],
|
||||
// FIXME: Unlike all other attributes, group isn't trimmed. Why?
|
||||
[ [ 'group' => ' g ' ], [ null, ' g ', null, null, null ] ],
|
||||
|
|
Loading…
Reference in a new issue