Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/72362


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

Check if media wiki core is capable of xml type checking

Bug: 50884
Change-Id: I86af95cbecc4b5c9c33fcd3a66a7fb2ccdde0194
---
M Math.i18n.php
M MathLaTeXML.php
M tests/MathLaTeXMLTest.php
3 files changed, 27 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/62/72362/1

diff --git a/Math.i18n.php b/Math.i18n.php
index 5bd9a9b..3f67663 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 1.22 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 if XML check must be skipped, due 
to Mediawiki core version, prior to 1.22.'
 );
 
 /** 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/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: newchange
Gerrit-Change-Id: I86af95cbecc4b5c9c33fcd3a66a7fb2ccdde0194
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to