mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 23:25:02 +00:00
Handle invalid cache keys on Special:MathShowImage
Special:MathShowImage takes a hash as an HTTP GET parameter. Show an error if the hash does not exist. Bug: T365112 Change-Id: I7d4a6602b8732b0b00cb9cba5800ba2b2fe5044f
This commit is contained in:
parent
17ac038ae4
commit
8aee6acf24
|
@ -121,7 +121,7 @@ class RendererFactory {
|
|||
return $renderer;
|
||||
}
|
||||
|
||||
public function getFromHash( $inputHash ) {
|
||||
public function getFromHash( $inputHash ): MathRenderer {
|
||||
$key = $this->cache->makeGlobalKey(
|
||||
MathRenderer::class,
|
||||
$inputHash
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\Math;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Math\Render\RendererFactory;
|
||||
use MediaWiki\SpecialPage\SpecialPage;
|
||||
|
||||
|
@ -79,39 +80,46 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
if ( $hash === '' && $tex === '' && $asciimath === '' ) {
|
||||
$this->setHeaders( false );
|
||||
echo $this->printSvgError( 'No Inputhash specified' );
|
||||
} else {
|
||||
if ( $tex === '' && $asciimath === '' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $tex === '' && $asciimath === '' ) {
|
||||
try {
|
||||
$this->renderer = $this->rendererFactory->getFromHash( $hash );
|
||||
$this->noRender = $request->getBool( 'noRender', false );
|
||||
$isInDatabase = $this->renderer->readFromCache();
|
||||
if ( $isInDatabase || $this->noRender ) {
|
||||
$success = $isInDatabase;
|
||||
} else {
|
||||
$success = $this->renderer->render();
|
||||
}
|
||||
} elseif ( $asciimath === '' ) {
|
||||
$this->renderer = $this->rendererFactory->getRenderer( $tex, [], $this->mode );
|
||||
$success = $this->renderer->render();
|
||||
} catch ( InvalidArgumentException $exception ) {
|
||||
$this->setHeaders( false );
|
||||
echo $this->printSvgError( $exception->getMessage() );
|
||||
return;
|
||||
}
|
||||
$this->noRender = $request->getBool( 'noRender', false );
|
||||
$isInDatabase = $this->renderer->readFromCache();
|
||||
if ( $isInDatabase || $this->noRender ) {
|
||||
$success = $isInDatabase;
|
||||
} else {
|
||||
$this->renderer = $this->rendererFactory->getRenderer(
|
||||
$asciimath, [ 'type' => 'ascii' ], $this->mode
|
||||
);
|
||||
$success = $this->renderer->render();
|
||||
}
|
||||
if ( $success ) {
|
||||
$output = $this->renderer->getSvg();
|
||||
} else {
|
||||
$output = $this->printSvgError( $this->renderer->getLastError() );
|
||||
}
|
||||
if ( $output == "" ) {
|
||||
$output = $this->printSvgError( 'No Output produced' );
|
||||
$success = false;
|
||||
}
|
||||
$this->setHeaders( $success );
|
||||
echo $output;
|
||||
if ( $success ) {
|
||||
$this->renderer->writeCache();
|
||||
}
|
||||
} elseif ( $asciimath === '' ) {
|
||||
$this->renderer = $this->rendererFactory->getRenderer( $tex, [], $this->mode );
|
||||
$success = $this->renderer->render();
|
||||
} else {
|
||||
$this->renderer = $this->rendererFactory->getRenderer(
|
||||
$asciimath, [ 'type' => 'ascii' ], $this->mode
|
||||
);
|
||||
$success = $this->renderer->render();
|
||||
}
|
||||
if ( $success ) {
|
||||
$output = $this->renderer->getSvg();
|
||||
} else {
|
||||
$output = $this->printSvgError( $this->renderer->getLastError() );
|
||||
}
|
||||
if ( $output == "" ) {
|
||||
$output = $this->printSvgError( 'No Output produced' );
|
||||
$success = false;
|
||||
}
|
||||
$this->setHeaders( $success );
|
||||
echo $output;
|
||||
if ( $success ) {
|
||||
$this->renderer->writeCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue