Basic svg rendering

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2026-05-18 18:13:20 -07:00
parent c4e783dd9d
commit aad84ac0fc
3 changed files with 75 additions and 39 deletions

View File

@@ -1,6 +1,8 @@
<?php
namespace MediaWiki\Extension\AnatImageViewer;
require_once __DIR__ . '/../vendor/autoload.php';
use Devium\Toml\Toml;
use MediaWiki\MediaWikiServices;
use Content;
@@ -9,12 +11,19 @@ use CodeContentHandler;
use MediaWiki\Content\Renderer\ContentParseParams;
use ParserOutput;
use Html;
use IContextSource;
use MediaWiki\Content\ValidationParams;
use Status;
class AnnotationHandler extends CodeContentHandler {
private const ANNOT_VERSION = '0.1';
public function __construct( $modelId = 'annotation' ) {
parent::__construct( $modelId, [ CONTENT_FORMAT_TEXT ] );
public function __construct(
$modelId = AnnotationContent::MODEL,
$formats = [ CONTENT_FORMAT_TEXT ]
) {
parent::__construct( $modelId, $formats );
}
protected function getContentClass() {
@@ -39,27 +48,23 @@ class AnnotationHandler extends CodeContentHandler {
return true;
}
/*
public function serializeContent( Content $content, $format = null ) {
return parent::serializeContent( $content, $format );
}
public function unserializeContent( $blob, $format = null ) {
public function unserializeContent( $text, $format = null ) {
return new AnnotationContent( $text );
}
*/
public function makeEmptyContent() {
return new AnnotationContent();
}
public function supportsDirectEditing() {
return true;
return new AnnotationContent( '' );
}
protected function fillParserOutput( Content $content, ContentParseParams $cpoParams, ParserOutput &$output ) {
self::console_log('Parsing the fucking thing', true);
self::console_log($content, true);
$metadata = toml_decode($content->getNativeData(), true);
self::console_log(var_dump($metadata), true);
if (isset($metadata['baseImage'])) {
$baseImage = MediaWikiServices::getInstance()->getRepoGroup()->findFile('File:' . $metadata['baseImage']);
@@ -77,11 +82,11 @@ class AnnotationHandler extends CodeContentHandler {
* and produces the html string for the svg with base image and annotations.
*
* @param string $metadata The metadata object parsed from the text
* @param string $baseImageUrl The full url pointing to the base image to annotate
* @param array $frameParams The additional user defined parameters for the viewer such as hotspot and view classes
* @return string Html string of the complete model-viewer element inside a div container
* @param string $baseImage The full url pointing to the base image to annotate
* @return string Html string of the complete svg
*/
private function buildSvg($metadata, $baseImage) {
self::console_log(var_dump($baseImage), true);
//Gather basic data
$elBaseImg = '';
$vbHeight = 100;