From a5ddbd031dbe42b60fdc231bdb9fcd721b3485d7 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Tue, 10 May 2016 09:45:26 -0400 Subject: [PATCH] Catch exceptions thrown by restbase Display the error message on the screen, but do not throw an exception. The extension will be available from the error log. Bug: T134652 Change-Id: I5e88e74df6cd534d138d65251615066bab663368 --- MathMathML.php | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/MathMathML.php b/MathMathML.php index 2dd091f..09722bd 100644 --- a/MathMathML.php +++ b/MathMathML.php @@ -79,28 +79,39 @@ class MathMathML extends MathRenderer { * @see MathRenderer::render() */ public function render( $forceReRendering = false ) { - if ( in_array( $this->inputType, $this->restbaseInputTypes ) && $this->mode == 'mathml' ) { - if ( !$this->rbi ){ - $this->rbi = new MathRestbaseInterface( $this->getTex(), $this->getInputType() ); + global $wgMathFullRestbaseURL; + try { + if ( in_array( $this->inputType, $this->restbaseInputTypes ) && + $this->mode == 'mathml' + ) { + if ( !$this->rbi ) { + $this->rbi = + new MathRestbaseInterface( $this->getTex(), $this->getInputType() ); + } + $rbi = $this->rbi; + if ( $rbi->getSuccess() ) { + $this->mathml = $rbi->getMathML(); + $this->mathoidStyle = $rbi->getMathoidStyle(); + $this->svgPath = $rbi->getFullSvgUrl(); + } elseif ( $this->lastError === '' ) { + $this->doCheck(); + } + $this->changed = false; + return $rbi->getSuccess(); } - $rbi = $this->rbi; - if ( $rbi->getSuccess() ) { - $this->mathml = $rbi->getMathML(); - $this->mathoidStyle = $rbi->getMathoidStyle(); - $this->svgPath = $rbi->getFullSvgUrl(); - } elseif ( $this->lastError === '' ) { - $this->doCheck(); + if ( $forceReRendering ) { + $this->setPurge( true ); } - $this->changed = false; - return $rbi->getSuccess(); + if ( $this->renderingRequired() ) { + return $this->doRender(); + } + return true; + } catch ( Exception $e ) { + $this->lastError = $this->getError( 'math_mathoid_error', + $wgMathFullRestbaseURL, $e->getMessage() ); + LoggerFactory::getInstance( 'Math' )->error( $e->getMessage(), [ $e, $this ] ); + return false; } - if ( $forceReRendering ) { - $this->setPurge( true ); - } - if ( $this->renderingRequired() ) { - return $this->doRender(); - } - return true; } /**