mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-13 17:56:59 +00:00
5f16307582
Bug: T126349 Change-Id: I15fbeec282868b4267a3e3d15740f2c3ff37ea48
36 lines
1 KiB
PHP
36 lines
1 KiB
PHP
<?php
|
|
|
|
use Wikibase\DataModel\Snak\PropertyValueSnak;
|
|
use Wikibase\Rdf\ValueSnakRdfBuilder;
|
|
use Wikimedia\Purtle\RdfWriter;
|
|
|
|
class MathMLRdfBuilder implements ValueSnakRdfBuilder {
|
|
|
|
/**
|
|
* Adds a value
|
|
*
|
|
* @param RdfWriter $writer
|
|
* @param string $propertyValueNamespace Property value relation namespace
|
|
* @param string $propertyValueLName Property value relation name
|
|
* @param string $dataType Property data type
|
|
* @param PropertyValueSnak $snak
|
|
*/
|
|
public function addValue(
|
|
RdfWriter $writer,
|
|
$propertyValueNamespace,
|
|
$propertyValueLName,
|
|
$dataType,
|
|
PropertyValueSnak $snak
|
|
) {
|
|
$renderer = new MathMathML( $snak->getDataValue()->getValue() );
|
|
if ( $renderer->checkTeX() && $renderer->render() ) {
|
|
$mml = $renderer->getMathml();
|
|
} else {
|
|
$err = $renderer->getLastError();
|
|
$mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><merror>$err</merror></math>";
|
|
}
|
|
$writer->say( $propertyValueNamespace, $propertyValueLName )
|
|
->value( $mml, 'http://www.w3.org/1998/Math/MathML' );
|
|
}
|
|
}
|