Physikerwelt has uploaded a new change for review.

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

Change subject: Move debug integration test to special-page
......................................................................

Move debug integration test to special-page

Since all other LaTexML integration tests will be performed
from the math status special page, it seems reasonable to
run the debug tests from this specialpage as well.

Localisation updates from https://translatewiki.net.

LaTeXML: prevent automatic rerendering of SVG

MathMathML::renderingRequired called the getSvg
function in MathLaTeXML that caused an automatic
rerendering of the SVG image if it was not cached.
That this rendering is triggered from the function
renderingRequired is contra intutive and should be
avoided.

Change-Id: Ieb4776469841fd428f885917d1b98c2b4e823b4b
---
M MathLaTeXML.php
M MathMathML.php
M MathRenderer.php
M SpecialMathStatus.php
4 files changed, 53 insertions(+), 10 deletions(-)


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

diff --git a/MathLaTeXML.php b/MathLaTeXML.php
index e8eaa62..318d652 100644
--- a/MathLaTeXML.php
+++ b/MathLaTeXML.php
@@ -182,7 +182,7 @@
         * No cache is used.
         * @return boolean
         */
-       public function calulateSvg() {
+       public function calculateSvg() {
                $renderer = new MathMathML( $this->getTex() );
                $renderer->setMathml( $this->getMathml() );
                $renderer->setMode( MW_MATH_LATEXML );
@@ -196,16 +196,22 @@
                return $res;
        }
 
+
        /**
         * Gets the SVG image
-        * Lazy evaluation: If no SVG image exists it's generated on the fly
+        *
+        * @param string $render if set to 'render' (default) and no SVG image 
exists, the function
+        *                       tries to generate it on the fly.
+        *                       Otherwise, if set to 'cached', and there is no 
SVG in the database
+        *                       cache, an empty string is returned.
+        *
         * @return string XML-Document of the rendered SVG
         */
-       public function getSvg( $render = true ) {
-               if ( $render && ( $this->isPurge() || $this->svg == '' ) ) {
-                       $this->calulateSvg();
+       public function getSvg( $render = 'render' ) {
+               if ( $render == 'render' && ( $this->isPurge() || $this->svg == 
'' ) ) {
+                       $this->calculateSvg();
                }
-               return $this->svg;
+               return parent::getSvg( $render );
        }
 
        protected function getMathTableName() {
diff --git a/MathMathML.php b/MathMathML.php
index 03bdd05..c32e796 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -214,8 +214,8 @@
                                // default preserve the (broken) layout as it 
was
                                $out = 'type=inline-TeX&q=' .rawurlencode( 
'{\\displaystyle ' . $input . '}' );
                        } else {
-                $out = 'type=tex&q=' . rawurlencode( $input );
-            }
+                               $out = 'type=tex&q=' . rawurlencode( $input );
+                       }
                }
                wfDebugLog( 'Math', 'Get post data: ' . $out );
                return $out;
diff --git a/MathRenderer.php b/MathRenderer.php
index fbab530..2654298 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -675,10 +675,16 @@
        }
 
        /**
+        * Gets the SVG image
         *
-        * @return type
+        * @param string $render if set to 'render' (default) and no SVG image 
exists, the function
+        *                       tries to generate it on the fly.
+        *                       Otherwise, if set to 'cached', and there is no 
SVG in the database
+        *                       cache, an empty string is returned.
+        *
+        * @return string XML-Document of the rendered SVG
         */
-       public function getSvg() {
+       public function getSvg( $render = 'render' ) {
                // Spaces will prevent the image from being displayed correctly 
in the browser
                return trim( $this->svg );
        }
diff --git a/SpecialMathStatus.php b/SpecialMathStatus.php
index c4c97b3..ec9a7be 100644
--- a/SpecialMathStatus.php
+++ b/SpecialMathStatus.php
@@ -51,8 +51,18 @@
        }
 
        private function runMathLaTeXMLTest( $modeName ) {
+               global $wgMathDebug;
                $this->getOutput()->addWikiMsgArray( 'math-test-start', 
$modeName );
                $this->testMathMLIntegration();
+               if ( $wgMathDebug ){
+                       try {
+                               $this->testDebug();
+                       }catch ( Exception $e){
+                               $this->getOutput()->addWikiText(
+                                       'Math debug test failed. Please run 
<code>mwscript update.php</code>');
+                               $this->getOutput()->addWikiText( 
$e->getMessage() );
+                       }
+               }
                $this->getOutput()->addWikiMsgArray( 'math-test-end', $modeName 
);
        }
 
@@ -120,6 +130,27 @@
                          $renderer->getLastError() );
        }
 
+       /**
+        * Checks the creation of the math table with debugging enabled.
+        * @covers MathHooks::onLoadExtensionSchemaUpdates
+        */
+       public function testDebug() {
+               $dbr = wfGetDB( DB_SLAVE );
+               if ( $dbr->getType() !== 'mysql' ) {
+                       $this->getOutput()->addWikiText( 'Debug columns not 
supported in ' . $dbr->getType() );
+                       return;
+               }
+               $renderer = MathRenderer::getRenderer( "a+b", array(), 
MW_MATH_MATHML );
+               $this->assertTrue( $renderer->render( true ) , "MathDebug: 
Rendering a+b");
+               $hash = $renderer->getInputHash();
+               $row = $dbr->selectRow("mathlog", "*", array( "math_inputhash" 
=> $hash ) , __METHOD__,
+                       array("order by" => "math_timestamp desc"));
+               $this->assertContains( "success", $row->math_log ,"MathDebug: 
Search for 'success' in the log file" );
+               $this->assertEquals( 
"type=inline-TeX&q=%7B%5Cdisplaystyle%20a%2Bb%7D", $row->math_post,
+                       "MathDebug: Check post variables in the log file" );
+               $this->assertEquals( 5, $row->math_mode, "MathDebug: Check 
rendering mode");
+       }
+
        private function assertTrue( $expression, $message = '' ) {
                if ( $expression ){
                        $this->getOutput()->addWikiMsgArray( 
'math-test-success' , $message );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb4776469841fd428f885917d1b98c2b4e823b4b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: debug
Gerrit-Owner: Physikerwelt <[email protected]>

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

Reply via email to