2019-11-28 14:39:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite;
|
|
|
|
|
2024-06-08 21:31:42 +00:00
|
|
|
use MediaWiki\Parser\Parser;
|
2023-12-10 22:18:51 +00:00
|
|
|
use MediaWiki\Parser\Sanitizer;
|
2019-11-28 14:39:11 +00:00
|
|
|
|
2019-11-29 14:00:39 +00:00
|
|
|
/**
|
2023-12-15 13:27:58 +00:00
|
|
|
* Footnote markers in the context of the Cite extension are the numbers in the article text, e.g.
|
|
|
|
* [1], that can be hovered or clicked to be able to read the attached footnote.
|
|
|
|
*
|
2019-11-29 14:00:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
2019-11-28 14:39:11 +00:00
|
|
|
class FootnoteMarkFormatter {
|
|
|
|
|
2023-06-05 14:36:03 +00:00
|
|
|
private AnchorFormatter $anchorFormatter;
|
2024-10-23 16:39:59 +00:00
|
|
|
private MarkSymbolRenderer $markSymbolRenderer;
|
2023-06-05 14:36:03 +00:00
|
|
|
private ReferenceMessageLocalizer $messageLocalizer;
|
2019-12-05 08:37:17 +00:00
|
|
|
|
2019-11-28 14:39:11 +00:00
|
|
|
public function __construct(
|
2019-12-09 16:08:57 +00:00
|
|
|
AnchorFormatter $anchorFormatter,
|
2024-10-23 16:39:59 +00:00
|
|
|
MarkSymbolRenderer $markSymbolRenderer,
|
2019-12-05 08:37:17 +00:00
|
|
|
ReferenceMessageLocalizer $messageLocalizer
|
2019-11-28 14:39:11 +00:00
|
|
|
) {
|
2019-12-09 16:08:57 +00:00
|
|
|
$this->anchorFormatter = $anchorFormatter;
|
2024-10-23 16:39:59 +00:00
|
|
|
$this->markSymbolRenderer = $markSymbolRenderer;
|
2019-12-05 08:37:17 +00:00
|
|
|
$this->messageLocalizer = $messageLocalizer;
|
2019-11-28 14:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a link (<sup ...) for the <ref> element from a key
|
|
|
|
* and return XHTML ready for output
|
|
|
|
*
|
|
|
|
* @suppress SecurityCheck-DoubleEscaped
|
2019-12-11 14:03:09 +00:00
|
|
|
* @param Parser $parser
|
2023-12-22 22:46:54 +00:00
|
|
|
* @param ReferenceStackItem $ref
|
2019-11-28 14:39:11 +00:00
|
|
|
*
|
2024-06-21 19:09:31 +00:00
|
|
|
* @return string HTML
|
2019-11-28 14:39:11 +00:00
|
|
|
*/
|
2024-06-21 19:18:25 +00:00
|
|
|
public function linkRef( Parser $parser, ReferenceStackItem $ref ): string {
|
2024-10-23 16:39:59 +00:00
|
|
|
$label = $this->markSymbolRenderer->makeLabel( $ref->group, $ref->number, $ref->extendsIndex );
|
2019-12-03 09:00:58 +00:00
|
|
|
|
2023-12-22 22:46:54 +00:00
|
|
|
$key = $ref->name ?? $ref->key;
|
2024-01-06 01:18:51 +00:00
|
|
|
// TODO: Use count without decrementing.
|
2023-12-22 22:46:54 +00:00
|
|
|
$count = $ref->name ? $ref->key . '-' . ( $ref->count - 1 ) : null;
|
|
|
|
$subkey = $ref->name ? '-' . $ref->key : null;
|
2019-11-29 23:26:58 +00:00
|
|
|
|
2019-12-11 14:03:09 +00:00
|
|
|
return $parser->recursiveTagParse(
|
2019-12-05 08:37:17 +00:00
|
|
|
$this->messageLocalizer->msg(
|
2019-11-28 14:39:11 +00:00
|
|
|
'cite_reference_link',
|
2023-12-04 07:28:22 +00:00
|
|
|
$this->anchorFormatter->backLinkTarget( $key, $count ),
|
|
|
|
$this->anchorFormatter->jumpLink( $key . $subkey ),
|
2019-12-03 09:00:58 +00:00
|
|
|
Sanitizer::safeEncodeAttribute( $label )
|
2019-12-05 08:37:17 +00:00
|
|
|
)->plain()
|
2019-11-28 14:39:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|