Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContentMathMLRdfBuilder
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 addValue
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Extension\MathSearch\Wikidata\Content;
4
5use MediaWiki\Extension\Math\MathLaTeXML;
6use Wikibase\DataModel\Snak\PropertyValueSnak;
7use Wikibase\Repo\Rdf\ValueSnakRdfBuilder;
8use Wikimedia\Purtle\RdfWriter;
9
10class ContentMathMLRdfBuilder implements ValueSnakRdfBuilder {
11
12    /**
13     * Adds a value
14     *
15     * @param RdfWriter $writer
16     * @param string $propertyValueNamespace Property value relation namespace
17     * @param string $propertyValueLName Property value relation name
18     * @param string $dataType Property data type
19     * @param string $snakNamespace
20     * @param PropertyValueSnak $snak
21     */
22    public function addValue(
23        RdfWriter $writer,
24        $propertyValueNamespace,
25        $propertyValueLName,
26        $dataType,
27        $snakNamespace,
28        PropertyValueSnak $snak
29    ) {
30        $renderer = new MathLaTeXML( $snak->getDataValue()->getValue() );
31        if ( $renderer->checkTeX() && $renderer->render() ) {
32            $mml = $renderer->getMathml();
33        } else {
34            $err = $renderer->getLastError();
35            $mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><merror>$err</merror></math>";
36        }
37        $writer->say( $propertyValueNamespace, $propertyValueLName )
38            ->value( $mml, 'http://www.w3.org/1998/Math/MathML' );
39    }
40}