Basic Toml error handling and save checking
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace MediaWiki\Extension\AnatImageViewer;
|
|||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use Devium\Toml\Toml;
|
use Devium\Toml\Toml;
|
||||||
|
use Devium\Toml\TomlError;
|
||||||
use MediaWiki\MediaWikiServices;
|
use MediaWiki\MediaWikiServices;
|
||||||
use Content;
|
use Content;
|
||||||
use Title;
|
use Title;
|
||||||
@@ -43,7 +44,6 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
return parent::canBeUsedOn( $title );
|
return parent::canBeUsedOn( $title );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritDoc */
|
|
||||||
public function supportsPreloadContent(): bool {
|
public function supportsPreloadContent(): bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -61,16 +61,21 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function fillParserOutput( Content $content, ContentParseParams $cpoParams, ParserOutput &$output ) {
|
protected function fillParserOutput( Content $content, ContentParseParams $cpoParams, ParserOutput &$output ) {
|
||||||
parent::fillParserOutput( $content, $cpoParams, $output );
|
self::console_log('Fill Parser Output', true);
|
||||||
self::console_log('Parsing the fucking thing', true);
|
|
||||||
|
|
||||||
|
parent::fillParserOutput( $content, $cpoParams, $output );
|
||||||
|
|
||||||
|
try {
|
||||||
$metadata = toml_decode($content->getText(), true);
|
$metadata = toml_decode($content->getText(), true);
|
||||||
self::console_log(print_r($metadata, true), true);
|
} catch (TomlError $e) {
|
||||||
|
$output->addWarningMsg( $e->getMessage() );
|
||||||
|
$output->setText( 'No image available' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($metadata['baseImage'])) {
|
if (isset($metadata['baseImage'])) {
|
||||||
$imageTitle = Title::makeTitleSafe( NS_FILE, $metadata['baseImage'] );
|
$imageTitle = Title::makeTitleSafe( NS_FILE, $metadata['baseImage'] );
|
||||||
$baseImage = MediaWikiServices::getInstance()->getRepoGroup()->findFile($imageTitle);
|
$baseImage = MediaWikiServices::getInstance()->getRepoGroup()->findFile($imageTitle);
|
||||||
self::console_log($baseImage->getFullUrl(), true);
|
|
||||||
} else {
|
} else {
|
||||||
$baseImage = false;
|
$baseImage = false;
|
||||||
}
|
}
|
||||||
@@ -161,6 +166,19 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
return Html::rawElement('svg', $attrSvg, $elBaseImg . implode($markers) );
|
return Html::rawElement('svg', $attrSvg, $elBaseImg . implode($markers) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validateSave( Content $content, ValidationParams $validationParams ) {
|
||||||
|
self::console_log('Validate Save', true);
|
||||||
|
$status = Status::newGood();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$tomlCheck = toml_decode($content->getText(), true);
|
||||||
|
} catch (TomlError $e) {
|
||||||
|
$status->fatal( 'content-failed-to-parse', 'SVG', "", $e->getMessage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Small helper function to display information on the browser console
|
* Small helper function to display information on the browser console
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user