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:
physikerwelt 2024-06-26 06:06:02 +02:00
parent 17ac038ae4
commit 8aee6acf24
No known key found for this signature in database
GPG key ID: FCC793EFFA5FB13C
2 changed files with 38 additions and 30 deletions

View file

@ -121,7 +121,7 @@ class RendererFactory {
return $renderer; return $renderer;
} }
public function getFromHash( $inputHash ) { public function getFromHash( $inputHash ): MathRenderer {
$key = $this->cache->makeGlobalKey( $key = $this->cache->makeGlobalKey(
MathRenderer::class, MathRenderer::class,
$inputHash $inputHash

View file

@ -2,6 +2,7 @@
namespace MediaWiki\Extension\Math; namespace MediaWiki\Extension\Math;
use InvalidArgumentException;
use MediaWiki\Extension\Math\Render\RendererFactory; use MediaWiki\Extension\Math\Render\RendererFactory;
use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\SpecialPage\SpecialPage;
@ -79,9 +80,17 @@ class SpecialMathShowImage extends SpecialPage {
if ( $hash === '' && $tex === '' && $asciimath === '' ) { if ( $hash === '' && $tex === '' && $asciimath === '' ) {
$this->setHeaders( false ); $this->setHeaders( false );
echo $this->printSvgError( 'No Inputhash specified' ); echo $this->printSvgError( 'No Inputhash specified' );
} else { return;
}
if ( $tex === '' && $asciimath === '' ) { if ( $tex === '' && $asciimath === '' ) {
try {
$this->renderer = $this->rendererFactory->getFromHash( $hash ); $this->renderer = $this->rendererFactory->getFromHash( $hash );
} catch ( InvalidArgumentException $exception ) {
$this->setHeaders( false );
echo $this->printSvgError( $exception->getMessage() );
return;
}
$this->noRender = $request->getBool( 'noRender', false ); $this->noRender = $request->getBool( 'noRender', false );
$isInDatabase = $this->renderer->readFromCache(); $isInDatabase = $this->renderer->readFromCache();
if ( $isInDatabase || $this->noRender ) { if ( $isInDatabase || $this->noRender ) {
@ -113,7 +122,6 @@ class SpecialMathShowImage extends SpecialPage {
$this->renderer->writeCache(); $this->renderer->writeCache();
} }
} }
}
/** /**
* Prints the specified error message as svg. * Prints the specified error message as svg.