diff --git a/Math.i18n.php b/Math.i18n.php
index f28b913d8..6b838fed2 100644
--- a/Math.i18n.php
+++ b/Math.i18n.php
@@ -39,6 +39,7 @@ $messages['en'] = array(
'math_latexml_invalidresponse' => 'LaTeXML Invalid response (\'$2\') from server \'$1\':',
'math_latexml_invalidxml' => 'LaTeXML MathML is invalid XML.',
'math_latexml_invalidjson' => 'LaTeXML Server response is invalid JSON.',
+ 'math_latexml_xmlversion' => 'Warning: XML Type check skipped! Check if your MediaWiki installation is version wmf/1.22wmf7 or newer.'
);
/** Message documentation (Message documentation)
@@ -145,6 +146,8 @@ This message follows the message {{msg-mw|Math failure}}.',
'math_latexml_invalidjson' => 'Used as error message.
This message follows the message {{msg-mw|Math failure}}.',
+
+ 'math_latexml_xmlversion' => 'Warning that XML checking of MathML requires wmf/1.22wmf7 or newer.'
);
/** Achinese (Acèh)
diff --git a/MathLaTeXML.php b/MathLaTeXML.php
index 8fd2c058e..703a3de4f 100644
--- a/MathLaTeXML.php
+++ b/MathLaTeXML.php
@@ -156,7 +156,7 @@ class MathLaTeXML extends MathRenderer {
* and the input string only.
* @return string HTTP POST data
*/
- public function getPostData(){
+ public function getPostData() {
$texcmd = urlencode( $this->tex );
return $this->getLaTeXMLSettings() . '&tex=' . $texcmd;
}
@@ -204,13 +204,19 @@ class MathLaTeXML extends MathRenderer {
*/
static public function isValidMathML( $XML ) {
$out = false;
- //depends on https://gerrit.wikimedia.org/r/#/c/66365/
- $xmlObject = new XmlTypeCheck($XML, null, false);
+ // depends on https://gerrit.wikimedia.org/r/#/c/66365/
+ if ( ! is_callable( 'XmlTypeCheck::newFromString' ) ) {
+ $msg = wfMessage( 'math_latexml_xmlversion' )->inContentLanguage()->escaped();
+ trigger_error( $msg, E_USER_NOTICE );
+ wfDebugLog( 'Math', $msg );
+ return true;
+ }
+ $xmlObject = new XmlTypeCheck( $XML, null, false );
if ( ! $xmlObject->wellFormed ) {
wfDebugLog( "Math", "XML validation error:\n " . var_export( $XML, true ) . "\n" );
} else {
$name = $xmlObject->getRootElement();
- $name = str_replace('http://www.w3.org/1998/Math/MathML:', '', $name);
+ $name = str_replace( 'http://www.w3.org/1998/Math/MathML:', '', $name );
if ( $name == "math" or $name == "table" or $name == "div" ) {
$out = true;
} else {
diff --git a/MathRenderer.php b/MathRenderer.php
index b2fc50cb6..16a6cc01a 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -161,7 +161,14 @@ abstract class MathRenderer {
$this->conservativeness = $rpage->math_html_conservativeness;
$this->html = $rpage->math_html;
$this->mathml = utf8_decode( $rpage->math_mathml);
- if ( StringUtils::isUtf8( $this->mathml ) ) {
+ if ( ! is_callable( 'StringUtils::isUtf8' ) ) {
+ $msg = wfMessage( 'math_latexml_xmlversion' )->inContentLanguage()->escaped();
+ trigger_error( $msg, E_USER_NOTICE );
+ wfDebugLog( 'Math', $msg );
+ //If we can not check if mathml output is valid, we skip the test and assume that it is valid.
+ $this->recall = true;
+ return true;
+ } elseif( StringUtils::isUtf8( $this->mathml ) ) {
$this->recall = true;
return true;
}
diff --git a/README b/README
index f0038602b..b64242ed0 100644
--- a/README
+++ b/README
@@ -16,6 +16,9 @@ $wgDefaultUserOptions['math'] = MW_MATH_LATEXML;
in the LocalSettings.php file.
The LaTeXML option requires php5-curl to be installed. Without php5-curl no proper
error handling can be guaranteed.
+Furthermore, a core version of wmf/1.22wmf7 or newer is recommended.
+Otherwise, errors in LaTeXML can lead to mal-formatted XML output and disturb the
+page layout.
MathJax configuration:
Client-side configuration of MathJax can be done by specifying a mathJax.config
diff --git a/tests/MathLaTeXMLTest.php b/tests/MathLaTeXMLTest.php
index ce2d47c84..f33465b49 100644
--- a/tests/MathLaTeXMLTest.php
+++ b/tests/MathLaTeXMLTest.php
@@ -44,7 +44,7 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
, "requestReturn is false if HTTP::post returns false." );
$this->assertEquals( false, $res
, "res is false if HTTP:post returns false." );
- $errmsg = wfMessage( 'math_latexml_invalidresponse' , $url,'' )
+ $errmsg = wfMessage( 'math_latexml_invalidresponse' , $url, '' )
->inContentLanguage()->escaped();
$this->assertContains( $errmsg, $error
, "return an error if HTTP::post returns false" );
@@ -66,13 +66,13 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
, 'LaTeXMLHttpRequestTester' );
$this->assertEquals( true, $requestReturn, "successful call return" );
$this->isTrue( $res, "successfull call" );
- $this->assertEquals( $error,'', "successfull call errormessage" );
+ $this->assertEquals( $error, '', "successfull call errormessage" );
}
/**
* Tests behavior of makeRequest() that communicates with the host.
* Testcase: Timeout.
- * @covers MathTexvc::makeRequest
+ * @covers MathLaTeXML::makeRequest
*/
public function testMakeRequestTimeout() {
self::setMockValues( false, true, true );
@@ -90,6 +90,17 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
$this->assertContains( $errmsg, $error, "timeout call errormessage" );
}
+ /**
+ * Checks if a String is a valid MathML element
+ * @covers MathLaTeXML::isValidXML
+ */
+ public function testisValidXML() {
+ $validSample = '';
+ $invalidSample = '';
+ $this->assertTrue( MathLaTeXML::isValidMathML( $validSample ), 'test if math expression is valid mathml sample' );
+ $this->assertFalse( MathLaTeXML::isValidMathML( $invalidSample ), 'test if math expression is invalid mathml sample' );
+
+ }
/**
* Checks the basic functionallity
* i.e. if the span element is generated right.