Convert to image handler hook based viewer insertion

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-22 19:58:02 -07:00
parent b31d9f3925
commit 5d90da0fda
3 changed files with 20 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
"author": "Justin Georgi", "author": "Justin Georgi",
"url": "https://gitea.azgeorgis.net/jgeorgi/mwModelViewer", "url": "https://gitea.azgeorgis.net/jgeorgi/mwModelViewer",
"description": "This extension allows .glb and .gltf files to be added, displayed, and annotated in MediaWiki", "description": "This extension allows .glb and .gltf files to be added, displayed, and annotated in MediaWiki",
"version": "0.0.3", "version": "0.0.4",
"license-name": "MIT", "license-name": "MIT",
"type": "media", "type": "media",
"manifest_version": 2, "manifest_version": 2,
@@ -13,7 +13,8 @@
"Hooks": { "Hooks": {
"MimeMagicInit": "GlModelViewer::onMimeMagicInit", "MimeMagicInit": "GlModelViewer::onMimeMagicInit",
"MimeMagicImproveFromExtension": "GlModelViewer::onMimeMagicImproveFromExtension", "MimeMagicImproveFromExtension": "GlModelViewer::onMimeMagicImproveFromExtension",
"BeforePageDisplay": "GlModelViewer::onBeforePageDisplay" "BeforePageDisplay": "GlModelViewer::onBeforePageDisplay",
"ImageBeforeProduceHTML": "GlModelViewer::onImageBeforeProduceHTML"
}, },
"ResourceFileModulePaths": { "ResourceFileModulePaths": {
"localBasePath": "modules", "localBasePath": "modules",

View File

@@ -16,12 +16,25 @@ class GlModelViewer extends ImageHandler {
} }
public static function onBeforePageDisplay(OutputPage $out) { public static function onBeforePageDisplay(OutputPage $out) {
preg_match('/(<a href="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf); preg_match('/(<model-viewer src="\S*?\.(glb|gltf"))/',$out->getHTML(),$findGltf);
if ($findGltf[0]) { if ($findGltf[0]) {
$out->addModules('ext.glmv'); $out->addModules('ext.glmv');
} }
} }
public static function onImageBeforeProduceHTML( DummyLinker &$linker, Title &$title, &$file, array &$frameParams, array &$handlerParams, &$time, &$result, Parser $parser, string &$query, &$widthOption ) {
if ($file->getMimeType() !== 'model/gltf-binary') {
return true;
}
$result = '<model-viewer src=' . $file->getFullUrl() . '></model-viewer>';
#echo '<script>';
#GlModelViewer::console_log($handlerParams);
#GlModelViewer::console_log($frameParams);
#GlModelViewer::console_log($file->getDescriptionText());
#echo '</script>';
return false;
}
public static function console_log($data, $add_script_tags = false) { public static function console_log($data, $add_script_tags = false) {
$command = 'console.log('. json_encode($data, JSON_HEX_TAG).');'; $command = 'console.log('. json_encode($data, JSON_HEX_TAG).');';
if ($add_script_tags) { if ($add_script_tags) {

View File

@@ -6,6 +6,7 @@ headElem.appendChild(modelLoad)
let urlProm, dataProm let urlProm, dataProm
let isFilePageImage = false let isFilePageImage = false
/*
let glbElems = document.querySelectorAll('.mw-body-content [href$=".glb"][title$=".glb"') let glbElems = document.querySelectorAll('.mw-body-content [href$=".glb"][title$=".glb"')
if (glbElems.length > 0) { if (glbElems.length > 0) {
[...glbElems].forEach((ge, idx) => { [...glbElems].forEach((ge, idx) => {
@@ -66,3 +67,4 @@ async function getModelMeta(getTitle) {
}); });
return JSON.parse($(metaApiResp.parse.text['*']).find('pre').text() || '{}') return JSON.parse($(metaApiResp.parse.text['*']).find('pre').text() || '{}')
} }
*/