| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math; |
| 4 |
|
| 5 |
use Wikibase\DataModel\Snak\PropertyValueSnak; |
| 6 |
use Wikibase\Repo\Rdf\ValueSnakRdfBuilder; |
| 7 |
use Wikimedia\Purtle\RdfWriter; |
| 8 |
|
| 9 |
class MathMLRdfBuilder implements ValueSnakRdfBuilder { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function addValue( |
| 22 |
RdfWriter $writer, |
| 23 |
$propertyValueNamespace, |
| 24 |
$propertyValueLName, |
| 25 |
$dataType, |
| 26 |
$snakNamespace, |
| 27 |
PropertyValueSnak $snak |
| 28 |
) { |
| 29 |
$renderer = new MathMathML( $snak->getDataValue()->getValue() ); |
| 30 |
if ( $renderer->checkTeX() && $renderer->render() ) { |
| 31 |
$mml = $renderer->getMathml(); |
| 32 |
} else { |
| 33 |
$err = $renderer->getLastError(); |
| 34 |
$mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><merror>$err</merror></math>"; |
| 35 |
} |
| 36 |
$writer->say( $propertyValueNamespace, $propertyValueLName ) |
| 37 |
->value( $mml, 'http://www.w3.org/1998/Math/MathML' ); |
| 38 |
} |
| 39 |
} |