From a823fa23d90f66e8d9f405b4e5484ad781cd5506 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 21 Nov 2019 17:23:22 +0100 Subject: [PATCH] Merge two more code paths in Cite::referencesFormatEntry() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was another, duplicated special case for previews. It was using the same message as a with multiple uses. Now it's only one code path. The goal here is to reduce the number of code paths to make it much easier to implement proper rendering for the extends="…" use cases. Bug: T237241 Change-Id: I863ac3b5234d3a6f7f2371a2a85385c3aea276e5 --- src/Cite.php | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Cite.php b/src/Cite.php index ffad2e96b..09b0374b3 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -809,21 +809,8 @@ class Cite { )->inContentLanguage()->plain(); } - if ( !isset( $val['count'] ) ) { - // this handles the case of section preview for list-defined references - return wfMessage( - 'cite_references_link_many', - $this->normalizeKey( - self::getReferencesKey( $key . "-" . ( $val['key'] ?? '' ) ) - ), - '', - $text . $error, - $extraAttributes - )->inContentLanguage()->plain(); - } - // This counts the number of reuses. 0 means the reference appears only 1 time. - if ( $val['count'] < 1 ) { + if ( isset( $val['count'] ) && $val['count'] < 1 ) { // Anonymous, auto-numbered references can't be reused and get marked with a -1. if ( $val['count'] < 0 ) { $id = $val['key']; @@ -843,21 +830,25 @@ class Cite { // Named references with >1 occurrences $backlinks = []; - // for group handling, we have an extra key here. - for ( $i = 0; $i <= $val['count']; $i++ ) { + // There is no count in case of a section preview + for ( $i = 0; $i <= ( $val['count'] ?? -1 ); $i++ ) { $backlinks[] = wfMessage( 'cite_references_link_many_format', $this->normalizeKey( - $this->refKey( $key, $val['key'] . "-$i" ) + $this->refKey( $key, $val['key'] . '-' . $i ) + ), + $this->referencesFormatEntryNumericBacklinkLabel( + $val['number'], + $i, + $val['count'] ), - $this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i, $val['count'] ), $this->referencesFormatEntryAlternateBacklinkLabel( $i ) )->inContentLanguage()->plain(); } - - return wfMessage( 'cite_references_link_many', + return wfMessage( + 'cite_references_link_many', $this->normalizeKey( - self::getReferencesKey( $key . "-" . $val['key'] ) + self::getReferencesKey( $key . '-' . ( $val['key'] ?? '' ) ) ), $this->listToText( $backlinks ), $text . $error,