jenkins-bot has submitted this change and it was merged.
Change subject: Expiremental option MathML input
......................................................................
Expiremental option MathML input
* this change allows for MahML iput like
it's used on PubMed.
See also:
Bug: 58201
Change-Id: I0b1085d2afa569fda000e96cc50c7bde303326b1
---
M MathMathML.php
M MathRenderer.php
M tests/MathMathMLTest.php
3 files changed, 55 insertions(+), 5 deletions(-)
Approvals:
Physikerwelt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MathMathML.php b/MathMathML.php
index 4dc630c..f2301eb 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -14,11 +14,34 @@
protected $defaultAllowedRootElements = array( 'math' );
protected $allowedRootElements = '';
protected $hosts;
+ protected $inputType = 'tex';
+
+ /**
+ * @param string $inputType
+ */
+ public function setInputType($inputType)
+ {
+ $this->inputType = $inputType;
+ }
+
+ /**
+ * @return string
+ */
+ public function getInputType()
+ {
+ return $this->inputType;
+ }
public function __construct( $tex = '', $params = array() ) {
global $wgMathMathMLUrl;
parent::__construct( $tex, $params );
$this->hosts = $wgMathMathMLUrl;
+ if ( isset( $params['type'] ) ) {
+ if( $params['type'] == 'pmml' ){
+ $this->inputType = 'pmml';
+ $this->setMathml( '<math>' . $tex . '</math>' );
+ }
+ }
}
/**
@@ -164,12 +187,11 @@
*/
public function getPostData() {
$tex = $this->getTex();
- if ( is_null( $this->getDisplaystyle() ) ) {
+ if ( $this->inputType == 'tex' && is_null(
$this->getDisplaystyle() ) ) {
// default preserve the (broken) layout as it was
$tex = '{\\displaystyle ' . $tex . '}';
}
-
- if ( $this->getMode() == MW_MATH_LATEXML && $this->getMathml()
) {
+ if ( $this->inputType == 'pmml' || $this->getMode() ==
MW_MATH_LATEXML && $this->getMathml() ) {
$out = 'type=mml&q=' . rawurlencode( $this->getMathml()
);
} else {
$out = 'type=tex&q=' . rawurlencode( $tex );
@@ -198,7 +220,9 @@
$result = json_decode( $res );
if ( $result && json_last_error() === JSON_ERROR_NONE )
{
if ( $result->success ) {
- if ( $this->getMode() ==
MW_MATH_LATEXML || $this->isValidMathML( $result->mml ) ) {
+ if ( $this->getMode() ==
MW_MATH_LATEXML ||
+ $this->inputType ==
'pmml' ||
+ $this->isValidMathML(
$result->mml ) ) {
$xmlObject = new XmlTypeCheck(
$result->svg, null, false );
if ( ! $xmlObject->wellFormed )
{
$this->lastError =
$this->getError( 'math_latexml_invalidxml', $host );
@@ -209,7 +233,7 @@
if ( $wgMathDebug ) {
$this->setLog(
$result->log );
}
- if ( $this->getMode() !=
MW_MATH_LATEXML ) {
+ if ( $this->getMode() !=
MW_MATH_LATEXML && $this->inputType != 'pmml') {
//add the inputhash
used for the generation to the MathML element
$mml = '<math id="' .
$this->getMd5() . '" ' . substr( $result->mml , 5 );
$this->setMathml( $mml
);
@@ -217,6 +241,7 @@
return true;
} else {
$this->lastError =
$this->getError( 'math_unknown_error', $host );
+ return false;
}
} else {
// Do not print bad mathml. It's
probably too verbose and might
diff --git a/MathRenderer.php b/MathRenderer.php
index 50c2a87..9508662 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -135,6 +135,13 @@
if ( !in_array( $mode, $wgMathValidModes ) ) {
$mode = $wgDefaultUserOptions['math'];
}
+ // Support of MathML input (experimental)
+ // Currently support for mode MW_MATH_MATHML only
+ if ( isset( $params['type'] ) ) {
+ if( $params['type'] == 'pmml' ){
+ $mode = MW_MATH_MATHML;
+ }
+ }
switch ( $mode ) {
case MW_MATH_SOURCE:
case MW_MATH_MATHJAX:
diff --git a/tests/MathMathMLTest.php b/tests/MathMathMLTest.php
index e073a60..aabd69f 100644
--- a/tests/MathMathMLTest.php
+++ b/tests/MathMathMLTest.php
@@ -149,6 +149,24 @@
$this->assertEquals( $svgRef, $renderer->getSvg() );
}
+ /**
+ * Checks the experimental option to 'render' MathML input
+ */
+ public function testPmmlInput(){
+ if ( in_array( gethostname(), self::$jenkinsServer ) ) {
+ $this->markTestSkipped( 'currently no live svgtex
server availible' );
+ }
+ // sample from 'Navajo Coal Combustion and Respiratory Health
Near Shiprock, New Mexico' in ''Journal of Environmental and Public Health'' ,
vol. 2010p.
+ // authors Joseph E. Bunnell; Linda V. Garcia; Jill M.
Furst; Harry Lerch; Ricardo A. Olea; Stephen E. Suitt; Allan Kolker
+ $inputSample = '<msub> <mrow> <mi> P</mi> </mrow> <mrow>
<mi> i</mi> <mi> j</mi> </mrow> </msub> <mo> =</mo> <mfrac> <mrow> <mn>
100</mn> <msub> <mrow> <mi> d</mi> </mrow> <mrow> <mi> i</mi> <mi> j</mi>
</mrow> </msub> </mrow> <mrow> <mn> 6.75</mn> <msub> <mrow> <mi> r</mi>
</mrow> <mrow> <mi> j</mi> </mrow> </msub> </mrow> </mfrac> <mo> ,</mo>
</math>';
+ $attribs = array( 'type' => 'pmml' );
+ $renderer = new MathMathML( $inputSample , $attribs );
+ $this->assertEquals( 'pmml' , $renderer->getInputType(), 'Input
type was not set correctly' );
+ $this->assertTrue($renderer->render(), 'Failed to render' );
+ $real = MathRenderer::renderMath( $inputSample, $attribs );
+ $expected = 'hash=5628b8248b79267ecac656102334d5e3&mode=5';
+ $this->assertContains( $expected, $real, 'Link to SVG image
missing');
+ }
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/120486
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0b1085d2afa569fda000e96cc50c7bde303326b1
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: dev
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Klortho <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
Gerrit-Reviewer: Worden.lee <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits