Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
FootnoteMarkFormatter | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
linkRef | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace Cite; |
4 | |
5 | use MediaWiki\Parser\Parser; |
6 | use MediaWiki\Parser\Sanitizer; |
7 | |
8 | /** |
9 | * Footnote markers in the context of the Cite extension are the numbers in the article text, e.g. |
10 | * [1], that can be hovered or clicked to be able to read the attached footnote. |
11 | * |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class FootnoteMarkFormatter { |
15 | |
16 | private AnchorFormatter $anchorFormatter; |
17 | private MarkSymbolRenderer $markSymbolRenderer; |
18 | private ReferenceMessageLocalizer $messageLocalizer; |
19 | |
20 | public function __construct( |
21 | AnchorFormatter $anchorFormatter, |
22 | MarkSymbolRenderer $markSymbolRenderer, |
23 | ReferenceMessageLocalizer $messageLocalizer |
24 | ) { |
25 | $this->anchorFormatter = $anchorFormatter; |
26 | $this->markSymbolRenderer = $markSymbolRenderer; |
27 | $this->messageLocalizer = $messageLocalizer; |
28 | } |
29 | |
30 | /** |
31 | * Generate a link (<sup ...) for the <ref> element from a key |
32 | * and return XHTML ready for output |
33 | * |
34 | * @suppress SecurityCheck-DoubleEscaped |
35 | * @param Parser $parser |
36 | * @param ReferenceStackItem $ref |
37 | * |
38 | * @return string HTML |
39 | */ |
40 | public function linkRef( Parser $parser, ReferenceStackItem $ref ): string { |
41 | $label = $this->markSymbolRenderer->makeLabel( $ref->group, $ref->number, $ref->extendsIndex ); |
42 | |
43 | $key = $ref->name ?? $ref->key; |
44 | // TODO: Use count without decrementing. |
45 | $count = $ref->name ? $ref->key . '-' . ( $ref->count - 1 ) : null; |
46 | $subkey = $ref->name ? '-' . $ref->key : null; |
47 | |
48 | return $parser->recursiveTagParse( |
49 | $this->messageLocalizer->msg( |
50 | 'cite_reference_link', |
51 | $this->anchorFormatter->backLinkTarget( $key, $count ), |
52 | $this->anchorFormatter->jumpLink( $key . $subkey ), |
53 | Sanitizer::safeEncodeAttribute( $label ) |
54 | )->plain() |
55 | ); |
56 | } |
57 | } |