Link wikidata items to math tags

Adds a parameter that links individual formulae to their respective wikidata items.

Bug: T71424
Change-Id: I32cfe2039e62f163fe3aebaf77bafbdd84b343c6
This commit is contained in:
AndreG-P 2018-11-06 02:29:56 +09:00
parent b6cf2e7c02
commit 2699479827
2 changed files with 16 additions and 0 deletions

View file

@ -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

View file

@ -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 );
}
}
/**