MathMathML::batchEvaluate - only pass MathRenderer

We do not need a ParserObject in the batchEvaluate,
so only pass in the MathRenderer

Change-Id: Id2e8cad709c08a0225597cb1fbf85289830f828b
This commit is contained in:
Petr Pchelko 2021-08-04 12:49:10 -07:00 committed by Physikerwelt
parent 32185cd9d0
commit 44ad3fbdf9
4 changed files with 19 additions and 20 deletions

View file

@ -153,10 +153,13 @@ class ParserHooksHandler implements
*/
public function onParserAfterTidy( $parser, &$text ) {
global $wgMathoidCli;
$renderers = array_map( static function ( $tag ) {
return $tag[0];
}, $this->mathLazyRenderBatch );
if ( $wgMathoidCli ) {
MathMathMLCli::batchEvaluate( $this->mathLazyRenderBatch );
MathMathMLCli::batchEvaluate( $renderers );
} else {
MathMathML::batchEvaluate( $this->mathLazyRenderBatch );
MathMathML::batchEvaluate( $renderers );
}
foreach ( $this->mathLazyRenderBatch as $key => [ $renderer, $renderParser ] ) {
$value = $this->mathPostTagHook( $renderer, $renderParser );

View file

@ -95,13 +95,11 @@ class MathMathML extends MathRenderer {
}
/**
* @param array[] $tags
* @param MathRenderer[] $renderers
*/
public static function batchEvaluate( array $tags ) {
public static function batchEvaluate( array $renderers ) {
$rbis = [];
foreach ( $tags as $key => $tag ) {
/** @var MathRenderer $renderer */
$renderer = $tag[0];
foreach ( $renderers as $key => $renderer ) {
$rbi = new MathRestbaseInterface( $renderer->getTex(), $renderer->getInputType() );
$renderer->setRestbaseInterface( $rbi );
$rbis[] = $rbi;

View file

@ -14,15 +14,14 @@ use stdClass;
class MathMathMLCli extends MathMathML {
/**
* @param array[] $tags math tags
* @param MathRenderer[] $renderers
* @return bool
* @throws MWException
*/
public static function batchEvaluate( array $tags ) {
public static function batchEvaluate( array $renderers ) {
$req = [];
foreach ( $tags as $key => $tag ) {
/** @var MathMathMLCli $renderer */
$renderer = $tag[0];
foreach ( $renderers as $key => $renderer ) {
'@phan-var MathMathMLCli $renderer';
// checking if the rendering is in the database is no security issue since only the md5
// hash of the user input string will be sent to the database
if ( !$renderer->isInDatabase() ) {
@ -34,9 +33,8 @@ class MathMathMLCli extends MathMathML {
}
$exitCode = 1;
$res = self::evaluateWithCli( $req, $exitCode );
foreach ( $tags as $key => $tag ) {
/** @var MathMathMLCli $renderer */
$renderer = $tag[0];
foreach ( $renderers as $key => $renderer ) {
'@phan-var MathMathMLCli $renderer';
if ( !$renderer->isInDatabase() ) {
$renderer->initializeFromCliResponse( $res );
}

View file

@ -34,7 +34,7 @@ class MathoidCliTest extends MediaWikiTestCase {
public function testGood() {
$mml = new MathMathMLCli( $this->goodInput );
$input = [ 'good' => [ $mml ] ];
$input = [ 'good' => $mml ];
MathMathMLCli::batchEvaluate( $input );
$this->assertTrue( $mml->render(), 'assert that renders' );
$this->assertStringContainsString( '</mo>', $mml->getMathml() );
@ -42,7 +42,7 @@ class MathoidCliTest extends MediaWikiTestCase {
public function testUndefinedFunctionError() {
$mml = new MathMathMLCli( $this->badInput );
$input = [ 'bad' => [ $mml ] ];
$input = [ 'bad' => $mml ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'newcommand', $mml->getLastError() );
@ -50,7 +50,7 @@ class MathoidCliTest extends MediaWikiTestCase {
public function testSyntaxError() {
$mml = new MathMathMLCli( '^' );
$input = [ 'bad' => [ $mml ] ];
$input = [ 'bad' => $mml ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
@ -58,7 +58,7 @@ class MathoidCliTest extends MediaWikiTestCase {
public function testCeError() {
$mml = new MathMathMLCli( '\ce{H2O}' );
$input = [ 'bad' => [ $mml ] ];
$input = [ 'bad' => $mml ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
@ -66,7 +66,7 @@ class MathoidCliTest extends MediaWikiTestCase {
public function testEmpty() {
$mml = new MathMathMLCli( '' );
$input = [ 'bad' => [ $mml ] ];
$input = [ 'bad' => $mml ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that renders' );
$this->assertFalse( $mml->isTexSecure() );