Highlight when we have a valid follow

Rather than using no errors as proxy.

Change-Id: I78c445838de2d4f5f6a0f17e5bb38996674ca999
This commit is contained in:
Arlo Breault 2020-09-16 18:51:18 -04:00 committed by jenkins-bot
parent deb9451c15
commit e3484acfc6
2 changed files with 12 additions and 4 deletions

View file

@ -148,7 +148,12 @@ class Ref extends ExtensionTagHandler {
$hasRefName = strlen( $dataMw->attrs->name ?? '' ) > 0; $hasRefName = strlen( $dataMw->attrs->name ?? '' ) > 0;
$hasFollow = strlen( $dataMw->attrs->follow ?? '' ) > 0; $hasFollow = strlen( $dataMw->attrs->follow ?? '' ) > 0;
if ( $hasFollow && !DOMUtils::hasTypeOf( $node, 'mw:Error' ) ) { // FIXME: This isn't exactly right since a valid follow could
// potentially produce some other type of error, so this may
// need some more smarts
$validFollow = $hasFollow && !DOMUtils::hasTypeOf( $node, 'mw:Error' );
if ( $validFollow ) {
$about = $node->getAttribute( 'about' ); $about = $node->getAttribute( 'about' );
$followNode = DOMCompat::querySelector( $followNode = DOMCompat::querySelector(
$bodyElt, "span[typeof~='mw:Cite/Follow'][about='{$about}']" $bodyElt, "span[typeof~='mw:Cite/Follow'][about='{$about}']"

View file

@ -170,6 +170,8 @@ class References extends ExtensionTagHandler {
$hasRefName = strlen( $refName ) > 0; $hasRefName = strlen( $refName ) > 0;
$hasFollow = strlen( $followName ) > 0; $hasFollow = strlen( $followName ) > 0;
$validFollow = false;
if ( $hasFollow ) { if ( $hasFollow ) {
if ( $hasRefName ) { if ( $hasRefName ) {
$errs[] = [ 'key' => 'cite_error_ref_too_many_keys' ]; $errs[] = [ 'key' => 'cite_error_ref_too_many_keys' ];
@ -178,6 +180,7 @@ class References extends ExtensionTagHandler {
// been defined // been defined
$group = $refsData->getRefGroup( $groupName ); $group = $refsData->getRefGroup( $groupName );
if ( isset( $group->indexByName[$followName] ) ) { if ( isset( $group->indexByName[$followName] ) ) {
$validFollow = true;
$ref = $group->indexByName[$followName]; $ref = $group->indexByName[$followName];
$span = $c->ownerDocument->createElement( 'span' ); $span = $c->ownerDocument->createElement( 'span' );
@ -262,7 +265,7 @@ class References extends ExtensionTagHandler {
DOMUtils::addAttributes( $linkBack, [ DOMUtils::addAttributes( $linkBack, [
'about' => $about, 'about' => $about,
'class' => 'mw-ref', 'class' => 'mw-ref',
'id' => ( $nestedInReferences || ( $hasFollow && count( $errs ) === 0 ) ) ? 'id' => ( $nestedInReferences || $validFollow ) ?
null : ( $ref->name ? $lastLinkback : $ref->id ), null : ( $ref->name ? $lastLinkback : $ref->id ),
'rel' => 'dc:references', 'rel' => 'dc:references',
'typeof' => $nodeType 'typeof' => $nodeType
@ -294,8 +297,8 @@ class References extends ExtensionTagHandler {
} }
DOMDataUtils::setDataMw( $linkBack, $dmw ); DOMDataUtils::setDataMw( $linkBack, $dmw );
// FIXME (T263052) This should be moved to CSS // FIXME(T263052): This should be moved to CSS
if ( $hasFollow && count( $errs ) === 0 ) { if ( $validFollow ) {
$linkBack->setAttribute( 'style', 'display: none;' ); $linkBack->setAttribute( 'style', 'display: none;' );
} }