From c4e783dd9d94ffb774729de3fce48d97338bac54 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Mon, 18 May 2026 08:56:56 -0700 Subject: [PATCH] Stuck point Signed-off-by: Justin Georgi --- extension.json | 11 ++++------ includes/AnnotationContent.php | 2 +- includes/AnnotationHandler.php | 37 +++++++++++++++++++++++++--------- includes/AnnotationHooks.php | 20 ++++++++++++------ 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/extension.json b/extension.json index 5dda34f..8559803 100644 --- a/extension.json +++ b/extension.json @@ -13,17 +13,13 @@ "constant": "NS_AV_ANNOT", "name": "Annotation", "protection": "annotations-edit", - "subpages": false, - "content": true, - "defaultcontentmodel": "annotation" + "subpages": false }, { "id": 2219, "constant": "NS_AV_ANNOT_TALK", "name": "Annotation_talk", - "subpages": true, - "content": false, - "defaultcontentmodel": "wikitext" + "subpages": true } ], "callback": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::registrationCallback", @@ -31,8 +27,9 @@ "MediaWiki\\Extension\\AnatImageViewer\\": "includes/" }, "ContentHandlers": { - "annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler" + "annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler::class" }, "Hooks": { + "ContentHandlerDefaultModelFor": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onContentHandlerDefaultModelFor" } } \ No newline at end of file diff --git a/includes/AnnotationContent.php b/includes/AnnotationContent.php index ae8f492..b61c2c2 100644 --- a/includes/AnnotationContent.php +++ b/includes/AnnotationContent.php @@ -8,7 +8,7 @@ class AnnotationContent extends TextContent { public function __construct( $modelId = 'annotation' ) { parent::__construct( $modelId ); } - + /* public function getTextForSearchIndex() { } diff --git a/includes/AnnotationHandler.php b/includes/AnnotationHandler.php index cb630ec..3d55a8e 100644 --- a/includes/AnnotationHandler.php +++ b/includes/AnnotationHandler.php @@ -4,20 +4,41 @@ namespace MediaWiki\Extension\AnatImageViewer; use Devium\Toml\Toml; use MediaWiki\MediaWikiServices; use Content; -use TextContentHandler; +use Title; +use CodeContentHandler; use MediaWiki\Content\Renderer\ContentParseParams; use ParserOutput; -use ConfigFactory; -use RequestContext; use Html; -class AnnotationHandler extends TextContentHandler { +class AnnotationHandler extends CodeContentHandler { private const ANNOT_VERSION = '0.1'; public function __construct( $modelId = 'annotation' ) { parent::__construct( $modelId, [ CONTENT_FORMAT_TEXT ] ); } + protected function getContentClass() { + return AnnotationContent::class; + } + + /** + * Only allow this content handler to be used in the Module namespace + * @param Title $title + * @return bool + */ + public function canBeUsedOn( Title $title ) { + if ( $title->getNamespace() !== NS_AV_ANNOT ) { + return false; + } + + return parent::canBeUsedOn( $title ); + } + + /** @inheritDoc */ + public function supportsPreloadContent(): bool { + return true; + } + /* public function serializeContent( Content $content, $format = null ) { } @@ -25,7 +46,7 @@ class AnnotationHandler extends TextContentHandler { public function unserializeContent( $blob, $format = null ) { } */ - + public function makeEmptyContent() { return new AnnotationContent(); } @@ -35,9 +56,7 @@ class AnnotationHandler extends TextContentHandler { } protected function fillParserOutput( Content $content, ContentParseParams $cpoParams, ParserOutput &$output ) { - // define $html somewhere - // e.g. $output->setText( $html ); - + self::console_log('Parsing the fucking thing', true); self::console_log($content, true); $metadata = toml_decode($content->getNativeData(), true); @@ -83,8 +102,6 @@ class AnnotationHandler extends TextContentHandler { ); $elBaseImg = Html::rawElement('image', $attrBase); } - $mainConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); - $context = RequestContext::getMain(); //Render and return svg $attrSvg = array( diff --git a/includes/AnnotationHooks.php b/includes/AnnotationHooks.php index bbb1e8a..22d081d 100644 --- a/includes/AnnotationHooks.php +++ b/includes/AnnotationHooks.php @@ -1,17 +1,25 @@ getNamespace() === NS_AV_ANNOT ) { + self::console_log('Found fucking thing!',true); + $model = CONTENT_MODEL_ANNOTATION; + } + } + /** * Small helper function to display information on the browser console *