Check if media wiki core is capable of xml type checking

* new test for XML type checking function
* check if StrigUtils::isUtf8 exists in core (Thanks to Deyan Ginev for the hint.)

Bug: 50884
Change-Id: I86af95cbecc4b5c9c33fcd3a66a7fb2ccdde0194
This commit is contained in:
physikerwelt 2013-07-07 12:42:31 +00:00 committed by Physikerwelt (Moritz Schubotz)
parent 73b374a265
commit 48461d0fca
5 changed files with 38 additions and 8 deletions

View file

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

View file

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

View file

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

3
README
View file

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

View file

@ -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 = '<math>content</math>';
$invalidSample = '<notmath />';
$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.