mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 03:34:10 +00:00
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:
parent
32185cd9d0
commit
44ad3fbdf9
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in a new issue