Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
MwsDumpWriter | |
0.00% |
0 / 36 |
|
0.00% |
0 / 12 |
240 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
InitializeHeader | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
generateIndexString | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
getHead | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFooter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMwsExpression | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
addMwsExpression | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
addRevision | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMwsns | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setMwsns | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOutput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addFromMathIdGenerator | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\Extension\Math\MathLaTeXML; |
4 | |
5 | class MwsDumpWriter { |
6 | |
7 | /** @var string */ |
8 | private $mwsns = 'mws:'; |
9 | private $XMLHead; |
10 | private $XMLFooter; |
11 | /** @var string */ |
12 | private $outBuffer = ''; |
13 | |
14 | public function __construct( $ns = 'mws:' ) { |
15 | $this->setMwsns( $ns ); |
16 | $this->InitializeHeader(); |
17 | } |
18 | |
19 | public function InitializeHeader() { |
20 | $ns = $this->mwsns; |
21 | $this->XMLHead = "<?xml version=\"1.0\"?>\n<" . $ns . |
22 | 'harvest xmlns:mws="http://search.mathweb.org/ns" xmlns:m="http://www.w3.org/1998/Math/MathML">'; |
23 | $this->XMLFooter = '</' . $ns . 'harvest>'; |
24 | } |
25 | |
26 | /** |
27 | * @param stdClass $row |
28 | * |
29 | * @return string |
30 | */ |
31 | public function generateIndexString( $row ) { |
32 | $xml = simplexml_load_string( $row->math_mathml ); |
33 | if ( !$xml ) { |
34 | echo "ERROR while converting:\n " . var_export( $row->math_mathml, true ) . "\n"; |
35 | foreach ( libxml_get_errors() as $error ) { |
36 | echo "\t", $error->message; |
37 | } |
38 | libxml_clear_errors(); |
39 | return ''; |
40 | } |
41 | return $this->getMwsExpression( $row->math_mathml, |
42 | $row->mathindex_revision_id, $row->mathindex_anchor |
43 | ); |
44 | } |
45 | |
46 | public function getHead() { |
47 | return $this->XMLHead; |
48 | } |
49 | |
50 | public function getFooter() { |
51 | return $this->XMLFooter; |
52 | } |
53 | |
54 | public function getMwsExpression( $mathML, $revId, $eId ) { |
55 | $out = "\n<" . $this->mwsns . "expr url=\"{$revId}#{$eId}\">\n\t"; |
56 | $out .= $mathML; |
57 | $out .= "\n</" . $this->mwsns . "expr>\n"; |
58 | return $out; |
59 | } |
60 | |
61 | public function addMwsExpression( $mathML, $revId, $eId ) { |
62 | $this->outBuffer .= $this->getMwsExpression( $mathML, $revId, $eId ); |
63 | return true; |
64 | } |
65 | |
66 | public function addRevision( $revId ) { |
67 | $mathId = MathIdGenerator::newFromRevisionId( $revId ); |
68 | $this->addFromMathIdGenerator( $mathId ); |
69 | } |
70 | |
71 | /** |
72 | * @return string |
73 | */ |
74 | public function getMwsns() { |
75 | return $this->mwsns; |
76 | } |
77 | |
78 | /** |
79 | * @param string $mwsns |
80 | */ |
81 | public function setMwsns( $mwsns ) { |
82 | $this->mwsns = $mwsns; |
83 | } |
84 | |
85 | public function getOutput() { |
86 | return $this->getHead() . $this->outBuffer . $this->getFooter(); |
87 | } |
88 | |
89 | /** |
90 | * @param MathIdGenerator $generator |
91 | */ |
92 | public function addFromMathIdGenerator( MathIdGenerator $generator ) { |
93 | foreach ( $generator->getMathTags() as $key => $tag ) { |
94 | $mml = new MathLaTeXML( $tag[MathIdGenerator::CONTENT_POS], |
95 | $tag[MathIdGenerator::ATTRIB_POS] ); |
96 | $mml->render(); |
97 | $this->outBuffer .= $this->getMwsExpression( $mml->getMathml(), |
98 | $generator->getRevisionId(), |
99 | $generator->parserKey2fId( $key ) ); |
100 | } |
101 | } |
102 | } |