Physikerwelt has uploaded a new change for review.

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

Change subject: Display mathoids PNG file via SpecialPage
......................................................................

Display mathoids PNG file via SpecialPage

* mode=0 no loger uses the texvc rendering but the
  mathoid renderin

Change-Id: Iecc7d83651710a1bdc2bf603f7998a003aa5ae8d
---
M MathMathML.php
M MathRenderer.php
M SpecialMathShowImage.php
3 files changed, 53 insertions(+), 24 deletions(-)


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

diff --git a/MathMathML.php b/MathMathML.php
index e79d767..9507b3e 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -469,18 +469,10 @@
                if ( $this->getMode() == MW_MATH_LATEXML || $this->inputType == 
'pmml' ||
                         $this->isValidMathML( $jsonResult->mml )
                ) {
-                       if ( isset( $jsonResult->svg ) ) {
-                               $xmlObject = new XmlTypeCheck( 
$jsonResult->svg, null, false );
-                               if ( !$xmlObject->wellFormed ) {
-                                       $this->lastError = $this->getError( 
'math_invalidxml', $host );
-                                       return false;
-                               } else {
-                                       $this->setSvg( $jsonResult->svg );
-                               }
-                       } else {
-                               LoggerFactory::getInstance( 'Math' )->error(
-                                       'Missing SVG property in JSON result.' 
);
+                       if ( !$this->extractSvg( $jsonResult, $host ) ){
+                               return false;
                        }
+                       $this->extractPng( $jsonResult, $host );
                        if ( $wgMathDebug ) {
                                $this->setLog( $jsonResult->log );
                        }
@@ -493,4 +485,39 @@
                        return false;
                }
        }
+
+       /**
+        * @param $jsonResult
+        * @param $host
+        * @return bool
+        */
+       private function extractSvg( $jsonResult, $host ) {
+               if ( isset( $jsonResult->svg ) ) {
+                       $xmlObject = new XmlTypeCheck( $jsonResult->svg, null, 
false );
+                       if ( !$xmlObject->wellFormed ) {
+                               $this->lastError = $this->getError( 
'math_invalidxml', $host );
+                                return false;
+                       } else {
+                               $this->setSvg( $jsonResult->svg );
+                       }
+               } else {
+                       LoggerFactory::getInstance( 'Math' )->error( 'Missing 
SVG property in JSON result.' );
+               }
+               return true;
+       }
+
+       /**
+        * @param $jsonResult
+        * @param $host
+        * @return bool
+        */
+       private function extractPng( $jsonResult, $host ) {
+               if ( isset( $jsonResult->png ) ) {
+                       $this->setPng( $jsonResult->png );
+                       return true;
+               } else {
+                       LoggerFactory::getInstance( 'Math' )->error( 'Missing 
PNG property in JSON result from ' . $host );
+                       return false;
+               }
+       }
 }
diff --git a/MathRenderer.php b/MathRenderer.php
index 722d25e..c2df962 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -704,4 +704,8 @@
        public function getPng() {
                return $this->png;
        }
+
+       public function setPng( $png ) {
+               $this->png = $png;
+       }
 }
diff --git a/SpecialMathShowImage.php b/SpecialMathShowImage.php
index 154e40d..048f465 100644
--- a/SpecialMathShowImage.php
+++ b/SpecialMathShowImage.php
@@ -60,9 +60,6 @@
                } else {
                        if ( $tex === '' && $asciimath === ''){
                                switch ( $this->mode ) {
-                                       case MW_MATH_PNG:
-                                               $this->renderer = 
MathTexvc::newFromMd5( $hash );
-                                               break;
                                        case MW_MATH_LATEXML:
                                                $this->renderer = 
MathLaTeXML::newFromMd5( $hash );
                                                break;
@@ -74,14 +71,6 @@
                                if ( $isInDatabase || $this->noRender ) {
                                        $success = $isInDatabase;
                                } else {
-                                       if ( $this->mode == MW_MATH_PNG ) {
-                                               // get the texvc input from the 
mathoid database table
-                                               // and render the conventional 
way
-                                               $mmlRenderer = 
MathMathML::newFromMd5( $hash );
-                                               
$mmlRenderer->readFromDatabase();
-                                               $this->renderer = 
MathRenderer::getRenderer( $mmlRenderer->getUserInputTex(), array(), 
MW_MATH_PNG );
-                                               $this->renderer->setMathStyle( 
$mmlRenderer->getMathStyle() );
-                                       }
                                        $success = $this->renderer->render();
                                }
                        } elseif ( $asciimath === '' ) {
@@ -93,7 +82,16 @@
                        }
                        if ( $success ) {
                                if ( $this->mode == MW_MATH_PNG ) {
-                                       $output = $this->renderer->getPng();
+                                       $prefix = 'data:image/png;base64,';
+                                       $img = $this->renderer->getPng();
+                                       if( substr( $img, 0, strlen( $prefix ) 
) === $prefix ){
+                                               $img = str_replace( $prefix, 
'', $img );
+                                               $img = str_replace( ' ', '+', 
$img );
+                                               $output = base64_decode( $img );
+                                       } else {
+                                               $output = $this->printSvgError( 
'invalid png file' );
+                                               $success = false;
+                                       }
                                } else {
                                        $output = $this->renderer->getSvg();
                                }
@@ -101,7 +99,7 @@
                                // Error message in PNG not supported
                                $output = $this->printSvgError( 
$this->renderer->getLastError() );
                        }
-                       if ( $output == "" ) {
+                       if ( $output == "" || $output == false ) {
                                $output = $this->printSvgError( 'No Output 
produced' );
                                $success = false;
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecc7d83651710a1bdc2bf603f7998a003aa5ae8d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to