Physikerwelt has uploaded a new change for review. https://gerrit.wikimedia.org/r/284818
Change subject: WIP: Add more pngs to export script ...................................................................... WIP: Add more pngs to export script Change-Id: Ia327b4fac7d826ba24027b9f5cea8ba45c7d9017 --- M MathObject.php M maintenance/ExportPngs.php 2 files changed, 65 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch refs/changes/18/284818/1 diff --git a/MathObject.php b/MathObject.php index 8df32a8..5b2d818 100644 --- a/MathObject.php +++ b/MathObject.php @@ -421,7 +421,7 @@ } public function getPng() { - if ( $this->mode == 'mathml' ){ + if ( $this->mode == 'mathml' && $this->getRbi() ){ $pngUrl = preg_replace( '#/svg/#', '/png/', $this->getRbi()->getFullSvgUrl() ); return file_get_contents( $pngUrl ); } diff --git a/maintenance/ExportPngs.php b/maintenance/ExportPngs.php index 37c2b8d..00a3ffd 100755 --- a/maintenance/ExportPngs.php +++ b/maintenance/ExportPngs.php @@ -20,6 +20,8 @@ * @ingroup Maintenance */ +use MediaWiki\Logger\LoggerFactory; + require_once __DIR__ . '/../../../maintenance/Maintenance.php'; class ExportPngs extends Maintenance { @@ -32,6 +34,7 @@ 'mathoid' => 'math_input', 'mathlatexml' => 'math_inputtex' ]; + public function __construct() { parent::__construct(); @@ -44,29 +47,79 @@ true, "l" ); $this->addOption( 'sort', 'If set the result is sorted according to the input', false, false, 's' ); + $wgHooks['MathRenderingResultRetrieved'][] = 'ExportPngs::onMathRenderingResultRetrieved'; } + public static function onMathRenderingResultRetrieved(MathMathML $renderer, $jsonResult){ + $log = LoggerFactory::getInstance( 'MathSearch-maint' ); + $log->debug( 'hook called', [ + 'renderer' => $renderer, + 'jsonResult' => $jsonResult + ] ); + } /** * @param $folder * @param $input */ private static function processImage( $folder, $input ) { + $log = LoggerFactory::getInstance( 'MathSearch-maint' ); $texvc = new MathTexvc( $input ); $texvc->render(); $mathML = new MathMathML( $input ); $md5 = $mathML->getMd5(); $path = self::makePath( $folder, $md5 ); + $log->debug( 'process image', [ + 'tex' => $input, + 'path' => $path + ] ); file_put_contents( "$path/old.png", $texvc->getPng() ); - if ( $mathML->render() ) { - $o = MathObject::cloneFromRenderer( $mathML ); - file_put_contents( "$path/new.png", $o->getPng() ); - file_put_contents( "$path/new.mml", $o->getMathml() ); - file_put_contents( "$path/new.svg", $o->getSvg() ); - file_put_contents( "$path/tex.tex", $o->getUserInputTex() ); - } else { - echo 'ERROR' . $mathML->getLastError(); - var_export( $mathML ); + + // Mathoid + if ( ! $mathML->render() ) { + $log->error( 'MathML rendering returned false', [ + 'mathml' => $mathML, + 'tex' => $input, + 'path' => $path + ] ); + return; } + $o = MathObject::cloneFromRenderer( $mathML ); + file_put_contents( "$path/new.png", $o->getPng() ); + file_put_contents( "$path/new.mml", $o->getMathml() ); + file_put_contents( "$path/new.svg", $o->getSvg() ); + file_put_contents( "$path/tex.tex", $o->getUserInputTex() ); + + // Mathoid eating it's MathML + $mathML = new MathMathML( $o->getMathml(), [ 'type' => 'pmml' ] ); + if ( ! $mathML->render() ) { + $log->error( 'MathML rendering returned false', [ + 'mathml' => $mathML, + 'tex' => $input, + 'path' => $path + ] ); + return; + } + + $o = MathObject::cloneFromRenderer( $mathML ); + file_put_contents( "$path/new-mathml.png", $o->getPng() ); + file_put_contents( "$path/new-mathml.svg", $o->getSvg() ); + + // LaTeXML + $mathML = new MathLaTeXML( $input); + if ( ! $mathML->render() ) { + $log->error( 'LaTeXML rendering returned false', [ + 'mathml' => $mathML, + 'tex' => $input, + 'path' => $path + ] ); + return; + } + + $o = MathObject::cloneFromRenderer( $mathML ); + file_put_contents( "$path/new-latexml.png", $o->getPng() ); + file_put_contents( "$path/new-latexml.svg", $o->getSvg() ); + file_put_contents( "$path/new-latexml.mml", $o->getMathml() ); + } /** @@ -90,7 +143,6 @@ * @return bool|ResultWrapper */ private static function getMathTagsFromDatabase( $folder, $table, $offset, $length, $sort ) { - $out = [ ]; $dbr = wfGetDB( DB_SLAVE ); $inputColumn = self::$inputColumns[$table]; $options = [ @@ -101,8 +153,8 @@ $options['ORDER BY'] = $inputColumn; } $res = - $dbr->select( [ 'm' => 'math', 'l' => $table ], [ 'm.math_inputhash', $inputColumn ], - [ 'm.math_inputhash = l.math_inputhash' ], __METHOD__, $options ); + $dbr->select( [ $table ], [ 'math_inputhash', $inputColumn ], + '', __METHOD__, $options ); if ( $res === false ) { return false; } -- To view, visit https://gerrit.wikimedia.org/r/284818 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia327b4fac7d826ba24027b9f5cea8ba45c7d9017 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