2019-11-19 10:29:33 +00:00
|
|
|
<?php
|
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
namespace Cite;
|
|
|
|
|
|
|
|
use Html;
|
|
|
|
use Language;
|
|
|
|
use Parser;
|
|
|
|
use Sanitizer;
|
|
|
|
|
2019-11-19 10:29:33 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*
|
2019-11-22 10:43:09 +00:00
|
|
|
* @return string Half-parsed wikitext with extension's tags already being expanded
|
2019-11-19 10:29:33 +00:00
|
|
|
*/
|
2019-11-22 10:43:09 +00:00
|
|
|
public function halfParsed( $key, ...$params ) {
|
|
|
|
// FIXME: We suspect this is not necessary and can just be removed
|
|
|
|
return $this->parser->recursiveTagParse( $this->plain( $key, ...$params ) );
|
2019-11-19 10:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key Message name of the error or warning
|
|
|
|
* @param mixed ...$params
|
|
|
|
*
|
2019-11-22 10:43:09 +00:00
|
|
|
* @return string Plain, unparsed wikitext
|
2019-11-19 10:29:33 +00:00
|
|
|
* @return-taint tainted
|
|
|
|
*/
|
2019-11-22 10:43:09 +00:00
|
|
|
public function plain( $key, ...$params ) {
|
2019-11-19 10:29:33 +00:00
|
|
|
$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()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|