From 269947982784e4674007b6552a51dd760515af6c Mon Sep 17 00:00:00 2001 From: AndreG-P Date: Tue, 6 Nov 2018 02:29:56 +0900 Subject: [PATCH] Link wikidata items to math tags Adds a parameter that links individual formulae to their respective wikidata items. Bug: T71424 Change-Id: I32cfe2039e62f163fe3aebaf77bafbdd84b343c6 --- src/MathMathML.php | 3 +++ tests/phpunit/MathMathMLTest.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/MathMathML.php b/src/MathMathML.php index 6efa5b1..5b343a0 100644 --- a/src/MathMathML.php +++ b/src/MathMathML.php @@ -480,6 +480,9 @@ class MathMathML extends MathRenderer { if ( $this->getID() !== '' ) { $attribs['id'] = $this->getID(); } + if ( isset( $this->params['qid'] ) && preg_match( '/Q\d+/', $this->params['qid'] ) ) { + $attribs['data-qid'] = $this->params['qid']; + } $output = Html::openElement( $element, $attribs ); // MathML has to be wrapped into a div or span in order to be able to hide it. // Remove displayStyle attributes set by the MathML converter diff --git a/tests/phpunit/MathMathMLTest.php b/tests/phpunit/MathMathMLTest.php index 45d8b40..5b7bb32 100644 --- a/tests/phpunit/MathMathMLTest.php +++ b/tests/phpunit/MathMathMLTest.php @@ -260,6 +260,19 @@ class MathMathMLTest extends MediaWikiTestCase { ->with( 'math-tracking-category-mhchem-deprecation' ); $renderer->addTrackingCategories( $parser ); } + + public function testGetHtmlOutputQID() { + $math = new MathMathML( "a+b", [ "qid" => "Q123" ] ); + $out = $math->getHtmlOutput(); + $this->assertContains( "data-qid=\"Q123\"", $out ); + } + + public function testGetHtmlOutputInvalidQID() { + // test with not valid ID. An ID must match /Q\d+/ + $math = new MathMathML( "a+b", [ "qid" => "123" ] ); + $out = $math->getHtmlOutput(); + $this->assertNotContains( "data-qid", $out ); + } } /**