Show only model on file preview page

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-23 12:42:51 -07:00
parent 134d9203de
commit aae33e8210
2 changed files with 20 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
<?php
use MediaWiki\MediaWikiServices;
class GlModelViewer extends ImageHandler {
public static function onMimeMagicInit(MimeAnalyzer $mime) {
@@ -38,11 +39,18 @@ class GlModelViewer extends ImageHandler {
$out->addModules('ext.glmv');
$viewer = self::buildViewer($file,['class' => 'view-default']);
$out->addHtml(Html::rawElement('div',['id' => 'file', 'class' => 'fullModelView'],$viewer));
#echo '<script>';
#self::console_log($imagepage->getFile()->getFullUrl());
#self::console_log($imagepage->getFile()->getDescriptionText());
#self::console_log($out);
#echo '</script>';
}
public static function onAlternateEditPreview( EditPage $editor, Content $content, string &$previewHTML, ?ParserOutput &$parserOutput ) {
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile($editor->getTitle());
if ($file->getMimeType() !== 'model/gltf-binary') {
return true;
}
$out = $editor->getContext()->getOutput();
$out->addModules('ext.glmv');
$previewHTML = self::buildViewer($file,['class' => 'view-default']);
return false;
}
private static function buildViewer($file, $frameParams) {
@@ -83,6 +91,11 @@ class GlModelViewer extends ImageHandler {
}
public static function console_log($data, $add_script_tags = false) {
#Usage:
#echo '<script>';
#self::console_log('logged string');
#echo '</script>';
$command = 'console.log('. json_encode($data, JSON_HEX_TAG).');';
if ($add_script_tags) {
$command = '<script>'. $command . '</script>';