Physikerwelt has uploaded a new change for review. https://gerrit.wikimedia.org/r/65873
Change subject: Update to new Version of Math extension. ...................................................................... Update to new Version of Math extension. Step 1 of 2 because there I can not debug at the moment: The debug toolbar stopped working on special pages I can not update core repo (see bug 44129) Change-Id: If5cf784f37aea49ca6c96c9fb1f50104d073b5b2 --- M FormulaInfo.php M MathObject.php M SpecialMathDebug.php 3 files changed, 173 insertions(+), 168 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch refs/changes/73/65873/1 diff --git a/FormulaInfo.php b/FormulaInfo.php index 68e4f02..c766201 100644 --- a/FormulaInfo.php +++ b/FormulaInfo.php @@ -66,12 +66,13 @@ $mo = MathObject::constructformpage( $pid, $eid ); $wgOut->addWikiText( "Occurences on the following pages:" ); wfDebugLog( "MathSearch", var_export( $mo->getAllOccurences(), true ) ); - // $wgOut->addWikiText('<b>:'.var_export($res,true).'</b>'); + $wgOut->addWikiText('<b>:'.var_export($mo,true).'</b>'); $wgOut->addWikiText( 'TeX : <code>' . $mo->getTex() . '</code>' ); $wgOut->addWikiText( 'MathML : ', false ); - $wgOut->addHTML( $mo->mathml ); - $wgOut->addHtml( '<a href="/wiki/Special:MathSearch?pattern=' . urlencode( $mo->getTex() ) . '&searchx=Search"><img src="http://wikidemo.formulasearchengine.com/images/FSE-PIC.png" width="15" height="15"></a>' ); + $wgOut->addHTML( $mo->getMathml() ); + $wgOut->addHtml( '<a href="/wiki/Special:MathSearch?pattern=' . urlencode( $mo->getTex() ) + . '&searchx=Search"><img src="http://wikidemo.formulasearchengine.com/images/FSE-PIC.png" width="15" height="15"></a>' ); # $log=htmlspecialchars( $res->math_log ); $wgOut->addWikiText( '==Similar pages==' ); $wgOut->addWikiText( 'Calculataed based on the variables occuring on the entire ' . $pagename . ' page' ); @@ -82,7 +83,7 @@ $wgOut->addWikiText( '==MathML==' ); $wgOut->addHtml( "<br />" ); - $wgOut->addHtml( htmlspecialchars( $mo->mathml ) ); + $wgOut->addHtml( htmlspecialchars( $mo->getMathml() ) ); $wgOut->addHtml( "<br />" ); $wgOut->addHtml( "<br />" ); $wgOut->addHtml( "<br />" ); @@ -90,7 +91,8 @@ $wgOut->addWikiText( '==LOG and Debug==' ); $wgOut->addWikiText( 'Rendered at : <code>' . $mo->getTimestamp() . '</code> an idexed at <code>' . $mo->getIndexTimestamp() . '</code>' ); - $wgOut->addWikiText( 'validxml : <code>' . $mo->getValidXml() . '</code> recheck:', false ); + $wgOut->addWikiText( 'validxml : <code>' . MathLaTeXML::isValidMathML( $mo->getMathml()) + . '</code> recheck:', false ); $wgOut->addHtml( MathLaTeXML::isValidMathML( $mo->getMathml() ) ? "valid":"invalid" ); $wgOut->addWikiText( 'status : <code>' . $mo->getStatusCode() . '</code>' ); $wgOut->addHtml( htmlspecialchars( $mo->getLog() ) ); diff --git a/MathObject.php b/MathObject.php index dbc158d..fbe0785 100644 --- a/MathObject.php +++ b/MathObject.php @@ -28,7 +28,7 @@ $instance->index_timestamp = $res->mathindex_timestamp; } $instance->inputHash = $res->mathindex_inputhash; - $instance->readDatabaseEntry(); + $instance->readFromDatabase(); wfDebugLog( "MathSearch", 'got' . var_export( $instance, true ) ); return $instance; } else { diff --git a/SpecialMathDebug.php b/SpecialMathDebug.php index 96aee93..dc26821 100644 --- a/SpecialMathDebug.php +++ b/SpecialMathDebug.php @@ -1,175 +1,178 @@ -<?php -class SpecialMathDebug extends SpecialPage { + <?php + class SpecialMathDebug extends SpecialPage { - function __construct() { - parent::__construct( 'MathDebug', 'edit', true ); - } - /** - * Sets headers - this should be called from the execute() method of all derived classes! - */ - function setHeaders() { - $out = $this->getOutput(); - $out->setArticleRelated( false ); - $out->setRobotPolicy( "noindex,nofollow" ); - $out->setPageTitle( $this->getDescription() ); - } + function __construct() { + parent::__construct( 'MathDebug', 'edit', true ); + } + /** + * Sets headers - this should be called from the execute() method of all derived classes! + */ + function setHeaders() { + $out = $this->getOutput(); + $out->setArticleRelated( false ); + $out->setRobotPolicy( "noindex,nofollow" ); + $out->setPageTitle( $this->getDescription() ); + } - function execute( $par ) { - global $wgDebugMath, $wgRequest; - $output = $this->getOutput(); - $this->setHeaders(); - $offset = $wgRequest->getVal( 'offset', 0 ); - $length = $wgRequest->getVal( 'length', 10 ); - $page = $wgRequest->getVal( 'page', 'Testpage' ); - $action = $wgRequest->getVal( 'action', 'show' ); - if ( !$this->userCanExecute( $this->getUser() ) ) { - $this->displayRestrictionError(); - return; - } else { - $this->displayButtons( $offset, $length, $page, $action ); - if ( $action == 'parserTest' ) { - $this->generateLaTeXMLOutput( $offset, $length, $page ); - return; - } elseif ( $action == 'parserDiff' ) { - $this->compareParser( $offset, $length, $page ); - return; + function execute( $par ) { + global $wgDebugMath, $wgRequest; + $output = $this->getOutput(); + $this->setHeaders(); + $offset = $wgRequest->getVal( 'offset', 0 ); + $length = $wgRequest->getVal( 'length', 10 ); + $page = $wgRequest->getVal( 'page', 'Testpage' ); + $action = $wgRequest->getVal( 'action', 'show' ); + if ( !$this->userCanExecute( $this->getUser() ) ) { + $this->displayRestrictionError(); } else { - $this->testParser( $offset, $length, $page ); - } - } - } - function displayButtons( $offset = 0, $length = 10, $page = 'Testpage', $action = 'show' ) { - $out = $this->getOutput(); - // TODO check if addHTML has to be sanitized - $out->addHTML( '<form method=\'get\'>' - . '<input value="Show :" type="submit">' - . ' <input name="length" size="3" value="' - . $length - . '" class="textfield" onfocus="this.select()" type="text">' - . ' test(s) starting from test # <input name="offset" size="6" value="' - . ( $offset + $length ) - . '" class="textfield" onfocus="this.select()" type="text"> for page' - . ' <input name="page" size="12" value="' - . $page - . '" class="textfield" onfocus="this.select()" type="text">' - . ' <input name="action" size="12" value="' - . $action - . '" class="textfield" onfocus="this.select()" type="text"> </form>' - ); - } - public function compareParser( $offset = 0, $length = 10, $page = 'Testpage' ) { - global $wgUseLaTeXML, $wgRequest, $wgLaTeXMLUrl; - $out = $this->getOutput(); - if ( !$wgUseLaTeXML ) { - $out->addWikiText( "MahtML support must be enabled." ); - return false; - } - $parserA = $wgRequest->getVal( 'parserA', 'http://latexml.mathweb.org/convert' ); - $parserB = $wgRequest->getVal( 'parserB', 'http://latexml-test.instance-proxy.wmflabs.org/' ); - $formulae = self::getMathTagsFromPage( $page ); - $i = 0; - $str_out = ''; - $renderer = new MathLaTeXML(); - $renderer->setPurge( ); - $diffFormatter = new DiffFormatter(); - if ( is_array( $formulae ) ) { - foreach ( array_slice( $formulae, $offset, $length, true ) as $key => $formula ) { - $out->addWikiText( "=== Test #" . ( $offset + $i++ ) . ": $key === " ); - $renderer->setTex( $formula ); - $wgLaTeXMLUrl = $parserA; - $stringA = $renderer->render( true ) ; - $wgLaTeXMLUrl = $parserB; - $stringB = $renderer->render( true ) ; - $diff = new Diff( array( $stringA ), array( $stringB ) ); - if ( $diff->isEmpty() ) { - $out->addWikiText( 'Output is identical' ); + $this->displayButtons( $offset, $length, $page, $action ); + if ( $action == 'parserTest' ) { + $this->generateLaTeXMLOutput( $offset, $length, $page ); + } elseif ( $action == 'parserDiff' ) { + $this->compareParser( $offset, $length, $page ); + } elseif ( $action == 'parserDiff' ) { + $this->testParser( $offset, $length, $page ); } else { - $out->addWikiText( '<source lang="diff">' . $diffFormatter->format( $diff ) . '</source>' ); - $out->addWikiText( 'XML Element based:' ); - $XMLA = explode( '>', $stringA ); - $XMLB = explode( '>', $stringB ); - $diff = new Diff( $XMLA, $XMLB ); - $out->addWikiText( '<source lang="diff">' . $diffFormatter->format( $diff ) . '</source>' ); + $output->addWikiText('unknon action'); } - $i++; - } - } else { - $str_out = "No math elements found"; - } - $out->addWikiText( $str_out ); - return true; - $out = $this->getOutput(); - } - - public function testParser( $offset = 0, $length = 10, $page = 'Testpage' ) { - global $wgUseMathJax, $wgUseLaTeXML; - $out = $this->getOutput(); - $out->addModules( array( 'ext.math.mathjax.enabler' ) ); - $i = 0; - foreach ( array_slice( self::getMathTagsFromPage( $page ), $offset, $length, true ) as $key => $t ) { - $out->addWikiText( "=== Test #" . ( $offset + $i++ ) . ": $key === " ); - $out->addHTML( self::render( $t, MW_MATH_SOURCE ) ); - $out->addHTML( self::render( $t, MW_MATH_PNG ) ); - if ( $wgUseLaTeXML ) { - $out->addHTML( self::render( $t, MW_MATH_LATEXML ) ); - } - if ( $wgUseMathJax ) { - $out->addHTML( self::render( $t, MW_MATH_MATHJAX, false ) ); } } - } - - function generateLaTeXMLOutput( $offset = 0, $length = 10, $page = 'Testpage' ) { - global $wgUseLaTeXML; - $out = $this->getOutput(); - if ( !$wgUseLaTeXML ) { - $out->addWikiText( "MahtML support must be enabled." ); - return false; + function displayButtons( $offset = 0, $length = 10, $page = 'Testpage', $action = 'show' ) { + $out = $this->getOutput(); + // TODO check if addHTML has to be sanitized + $out->addHTML( '<form method=\'get\'>' + . '<input value="Show :" type="submit">' + . ' <input name="length" size="3" value="' + . $length + . '" class="textfield" onfocus="this.select()" type="text">' + . ' test(s) starting from test # <input name="offset" size="6" value="' + . ( $offset + $length ) + . '" class="textfield" onfocus="this.select()" type="text"> for page' + . ' <input name="page" size="12" value="' + . $page + . '" class="textfield" onfocus="this.select()" type="text">' + . ' <input name="action" size="12" value="' + . $action + . '" class="textfield" onfocus="this.select()" type="text"> </form>' + ); } - - $formulae = self::getMathTagsFromPage( $page ); - $i = 0; - $renderer = new MathLaTeXML(); - $renderer->setPurge( ); - $tstring = ''; - if ( is_array( $formulae ) ) { - foreach ( array_slice( $formulae, $offset, $length, true ) as $key => $formula ) { - $tstring .= "\n!! test\n Test #" . ( $offset + $i++ ) . ": $key \n!! input" - . "\n<math>$formula</math>\n!! result\n"; - $renderer->setTex( $formula ); - $tstring .= $renderer->render( true ) ; - $tstring .= "\n!! end\n"; + public function compareParser( $offset = 0, $length = 10, $page = 'Testpage' ) { + global $wgUseLaTeXML, $wgRequest, $wgLaTeXMLUrl; + $out = $this->getOutput(); + if ( !$wgUseLaTeXML ) { + $out->addWikiText( "MahtML support must be enabled." ); + return false; } - } else { - $tstring = "No math elements found"; + $parserA = $wgRequest->getVal( 'parserA', 'http://latexml.mathweb.org/convert' ); + $parserB = $wgRequest->getVal( 'parserB', 'http://latexml-test.instance-proxy.wmflabs.org/' ); + $out->addWikiText("Comparing:\n * ParserA (first entry) $parserA". + "\n * ParserB (second entry) $parserB"); + $formulae = self::getMathTagsFromPage( $page ); + $i = 0; + $str_out = ''; + $renderer = new MathLaTeXML('test'); + $renderer->setPurge( ); + $diffFormatter = new DiffFormatter(); + if ( is_array( $formulae ) ) { + foreach ( array_slice( $formulae, $offset, $length, true ) as $key => $formula ) { + $out->addWikiText( "=== Test #" . ( $offset + $i++ ) . ": $key === " ); + $renderer->setTex( $formula ); + $wgLaTeXMLUrl = $parserA; + $stringA = $renderer->render( true ) ; + $wgLaTeXMLUrl = $parserB; + $stringB = $renderer->render( true ) ; + $diff = new Diff( array( $stringA ), array( $stringB ) ); + if ( $diff->isEmpty() ) { + $out->addWikiText( 'Output is identical' ); + } else { + $out->addWikiText( '<source lang="diff">' + . $diffFormatter->format( $diff ) + . '</source>' ); + $out->addWikiText( 'XML Element based:' ); + $XMLA = explode( '>', $stringA ); + $XMLB = explode( '>', $stringB ); + $diff = new Diff( $XMLA, $XMLB ); + $out->addWikiText( '<source lang="diff">' . $diffFormatter->format( $diff ) . '</source>' ); + } + $i++; + } + } else { + $str_out = "No math elements found"; + } + $out->addWikiText( $str_out ); + return true; + $out = $this->getOutput(); } - $out->addWikiText( '<source>' . $tstring . '<\source>' ); - return true; - } - private static function render( $t, $mode, $aimJax = true ) { - $res = $mode . ':' . MathRenderer::renderMath( $t, array(), $mode ); - if ( $aimJax ) { - self::aimHTMLFromJax( $res ); - } - return $res . '<br/>'; - } - private static function aimHTMLFromJax( &$s ) { - $s = str_replace( 'class="tex"', 'class="-NO-JAX-"', $s ); - return $s; - } - private static function getMathTagsFromPage( $titleString = 'Testpage' ) { - $title = Title::newFromText( $titleString ); - $article = new Article( $title ); - // TODO: find a better way to extract math elements from a page - $wikiText = $article->getPage()->getContent()->getNativeData(); - $wikiText = Sanitizer::removeHTMLcomments( $wikiText ); - $wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '', $wikiText ); - $matches = preg_match_all( "#<math>(.*?)</math>#s", $wikiText, $math ); - // TODO: Find a way to specify a key e.g '\nRenderTest:(.?)#<math>(.*?)</math>#s\n' - // leads to array('\1'->'\2') with \1 eg Bug 2345 and \2 the math content - return $math[1]; - } -} \ No newline at end of file + public function testParser( $offset = 0, $length = 10, $page = 'Testpage' ) { + global $wgUseMathJax, $wgUseLaTeXML; + $out = $this->getOutput(); + $out->addModules( array( 'ext.math.mathjax.enabler' ) ); + $i = 0; + foreach ( array_slice( self::getMathTagsFromPage( $page ), $offset, $length, true ) as $key => $t ) { + $out->addWikiText( "=== Test #" . ( $offset + $i++ ) . ": $key === " ); + $out->addHTML( self::render( $t, MW_MATH_SOURCE ) ); + $out->addHTML( self::render( $t, MW_MATH_PNG ) ); + if ( $wgUseLaTeXML ) { + $out->addHTML( self::render( $t, MW_MATH_LATEXML ) ); + } + if ( $wgUseMathJax ) { + $out->addHTML( self::render( $t, MW_MATH_MATHJAX, false ) ); + } + } + } + + function generateLaTeXMLOutput( $offset = 0, $length = 10, $page = 'Testpage' ) { + global $wgUseLaTeXML; + $out = $this->getOutput(); + if ( !$wgUseLaTeXML ) { + $out->addWikiText( "MahtML support must be enabled." ); + return false; + } + + $formulae = self::getMathTagsFromPage( $page ); + $i = 0; + $renderer = new MathLaTeXML(); + $renderer->setPurge( ); + $tstring = ''; + if ( is_array( $formulae ) ) { + foreach ( array_slice( $formulae, $offset, $length, true ) as $key => $formula ) { + $tstring .= "\n!! test\n Test #" . ( $offset + $i++ ) . ": $key \n!! input" + . "\n<math>$formula</math>\n!! result\n"; + $renderer->setTex( $formula ); + $tstring .= $renderer->render( true ) ; + $tstring .= "\n!! end\n"; + } + } else { + $tstring = "No math elements found"; + } + $out->addWikiText( '<source>' . $tstring . '<\source>' ); + return true; + } + private static function render( $t, $mode, $aimJax = true ) { + $res = $mode . ':' . MathRenderer::renderMath( $t, array(), $mode ); + if ( $aimJax ) { + self::aimHTMLFromJax( $res ); + } + return $res . '<br/>'; + } + private static function aimHTMLFromJax( &$s ) { + $s = str_replace( 'class="tex"', 'class="-NO-JAX-"', $s ); + return $s; + } + + private static function getMathTagsFromPage( $titleString = 'Testpage' ) { + $title = Title::newFromText( $titleString ); + $article = new Article( $title ); + // TODO: find a better way to extract math elements from a page + $wikiText = $article->getPage()->getContent()->getNativeData(); + $wikiText = Sanitizer::removeHTMLcomments( $wikiText ); + $wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '', $wikiText ); + $matches = preg_match_all( "#<math>(.*?)</math>#s", $wikiText, $math ); + // TODO: Find a way to specify a key e.g '\nRenderTest:(.?)#<math>(.*?)</math>#s\n' + // leads to array('\1'->'\2') with \1 eg Bug 2345 and \2 the math content + return $math[1]; + } + } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/65873 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If5cf784f37aea49ca6c96c9fb1f50104d073b5b2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MathSearch 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