Split FootnoteMarkFormatter code into logical pieces

This is motivated by T367749 where we probably need this code to be
separated. This minor refactoring just moves existing code around
without changing anything. The idea is just to make the concepts more
visible in the code.

Bug: T367749
Change-Id: I765d19fa9cb43a6f8492b707a7ae46ddffe43897
This commit is contained in:
thiemowmde 2024-06-21 21:09:31 +02:00 committed by Thiemo Kreuz (WMDE)
parent d9351bc0f4
commit 36f4ab138d

View file

@ -38,19 +38,10 @@ class FootnoteMarkFormatter {
* @param Parser $parser
* @param ReferenceStackItem $ref
*
* @return string
* @return string HTML
*/
public function linkRef( Parser $parser, ReferenceStackItem $ref ): string {
$label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number );
if ( $label === null ) {
$label = $this->messageLocalizer->localizeDigits( (string)$ref->number );
if ( $ref->group !== Cite::DEFAULT_GROUP ) {
$label = $ref->group . ' ' . $label;
}
}
if ( isset( $ref->extendsIndex ) ) {
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
}
$label = $this->makeLabel( $ref, $parser );
$key = $ref->name ?? $ref->key;
// TODO: Use count without decrementing.
@ -67,6 +58,20 @@ class FootnoteMarkFormatter {
);
}
private function makeLabel( ReferenceStackItem $ref, Parser $parser ): string {
$label = $this->fetchCustomizedLinkLabel( $parser, $ref->group, $ref->number ) ??
$this->makeDefaultLabel( $ref );
if ( isset( $ref->extendsIndex ) ) {
$label .= '.' . $this->messageLocalizer->localizeDigits( (string)$ref->extendsIndex );
}
return $label;
}
private function makeDefaultLabel( ReferenceStackItem $ref ): string {
$label = $this->messageLocalizer->localizeDigits( (string)$ref->number );
return $ref->group === Cite::DEFAULT_GROUP ? $label : "$ref->group $label";
}
/**
* Generate a custom format link for a group given an offset, e.g.
* the second <ref group="foo"> is b if $this->mLinkLabels["foo"] =