mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 00:40:12 +00:00
342e231a22
Change-Id: Icf61c9a27fd03266c98caf443bb9f00a421e31f6
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteErrorReporter {
|
|
|
|
/**
|
|
* @var Parser
|
|
*/
|
|
private $parser;
|
|
|
|
/**
|
|
* @var Language
|
|
*/
|
|
private $language;
|
|
|
|
/**
|
|
* @param Language $language
|
|
* @param Parser $parser
|
|
*/
|
|
public function __construct( Language $language, Parser $parser ) {
|
|
$this->language = $language;
|
|
$this->parser = $parser;
|
|
}
|
|
|
|
/**
|
|
* @param string $key Message name of the error or warning
|
|
* @param mixed ...$params
|
|
*
|
|
* @return string HTML ready for output
|
|
*/
|
|
public function html( $key, ...$params ) {
|
|
// FIXME: We suspect this is not necessary and can be replaced with Message::parse(),
|
|
// except wikis have custom error messages with example <ref> tags.
|
|
return $this->parser->recursiveTagParse( $this->wikitext( $key, ...$params ) );
|
|
}
|
|
|
|
/**
|
|
* @param string $key Message name of the error or warning
|
|
* @param mixed ...$params
|
|
*
|
|
* @return string Wikitext ready for output
|
|
* @return-taint tainted
|
|
*/
|
|
public function wikitext( $key, ...$params ) {
|
|
$msg = wfMessage( $key, $params )->inLanguage( $this->language );
|
|
|
|
if ( strncmp( $key, 'cite_warning_', 13 ) === 0 ) {
|
|
$type = 'warning';
|
|
$id = substr( $key, 13 );
|
|
$extraClass = ' mw-ext-cite-warning-' . Sanitizer::escapeClass( $id );
|
|
} else {
|
|
$type = 'error';
|
|
$extraClass = '';
|
|
|
|
// Take care; this is a sideeffect that might not belong to this class.
|
|
$this->parser->addTrackingCategory( 'cite-tracking-category-cite-error' );
|
|
}
|
|
|
|
return Html::rawElement(
|
|
'span',
|
|
[
|
|
'class' => "$type mw-ext-cite-$type" . $extraClass,
|
|
'lang' => $this->language->getHtmlCode(),
|
|
'dir' => $this->language->getDir(),
|
|
],
|
|
wfMessage( "cite_$type", $msg->plain() )->inLanguage( $this->language )->plain()
|
|
);
|
|
}
|
|
|
|
}
|