TheDJ has submitted this change and it was merged.

Change subject: Check if media wiki core is capable of xml type checking
......................................................................


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
---
M Math.i18n.php
M MathLaTeXML.php
M MathRenderer.php
M README
M tests/MathLaTeXMLTest.php
5 files changed, 38 insertions(+), 8 deletions(-)

Approvals:
  TheDJ: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Math.i18n.php b/Math.i18n.php
index f28b913..6b838fe 100644
--- a/Math.i18n.php
+++ b/Math.i18n.php
@@ -39,6 +39,7 @@
        '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 @@
        '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 8fd2c05..703a3de 100644
--- a/MathLaTeXML.php
+++ b/MathLaTeXML.php
@@ -156,7 +156,7 @@
         * 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 @@
         */
        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 b2fc50c..16a6cc0 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -161,7 +161,14 @@
                        $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 f003860..b64242e 100644
--- a/README
+++ b/README
@@ -16,6 +16,9 @@
 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 ce2d47c..f33465b 100644
--- a/tests/MathLaTeXMLTest.php
+++ b/tests/MathLaTeXMLTest.php
@@ -44,7 +44,7 @@
                        , "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 @@
                        , '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 );
@@ -91,6 +91,17 @@
        }
 
        /**
+        * 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.
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/72362
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I86af95cbecc4b5c9c33fcd3a66a7fb2ccdde0194
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Cjucovschi <[email protected]>
Gerrit-Reviewer: Deyan <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
Gerrit-Reviewer: TheDJ <[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

Reply via email to