Add basic thumbnail handling with static image

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-10-30 09:28:29 -07:00
parent 11bac465d9
commit 64140b7cd9
5 changed files with 28 additions and 23 deletions

View File

@@ -17,7 +17,6 @@
"MimeMagicInit": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onMimeMagicInit",
"MimeMagicImproveFromExtension": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onMimeMagicImproveFromExtension",
"BeforePageDisplay": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onBeforePageDisplay",
"ImageOpenShowImageInlineBefore": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onImageOpenShowImageInlineBefore",
"AlternateEditPreview": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onAlternateEditPreview"
},
"ResourceFileModulePaths": {

View File

@@ -36,6 +36,18 @@ class GlModelHandler extends ImageHandler {
* @return MediaTransformOutput
*/
public function doTransform($image, $dstPath, $dstUrl, $params, $flags = 0) {
$params['isFilePageThumb'] = false;
if (!isset($params['width']) || $params['width'] == 0) {
$params['width'] = 800;
}
if (!isset($params['height']) || $params['height'] == 0) {
$params['height'] = 600;
}
if ($params['width'] <= 300 || $params['height'] <= 300) {
$params['isFilePageThumb'] = true;
}
return new GlModelTransformOutput($image, $params);
}
@@ -47,7 +59,10 @@ class GlModelHandler extends ImageHandler {
* @return bool
*/
public function validateParam( $name, $value ) {
if (in_array($name, ['width', 'height'])) {
echo '<script>';
self::console_log('Param: ' . $name . " = " . $value);
echo '</script>';
if (in_array($name, ['width', 'height'])) {
return $value > 0;
} else if (in_array($name, ['view', 'hsset'])) {
return true;

View File

@@ -52,22 +52,6 @@ class GlModelHooks {
}
}
/**
* MWHook: Display model on file page
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ImageOpenShowImageInlineBefore
*
* @param ImagePage $imagepage information regarding the page for the image file
* @param OutputPage $out compiled page html and manipulation methods
*/
public static function onImageOpenShowImageInlineBefore( $imagepage, $out ){
$file = $imagepage->getFile();
if ($file->getMimeType() == 'model/gltf-binary') {
$out->clearHTML();
$out->addWikiTextAsContent('[[' . $file->getTitle()->getFullText() . '|800x600px]]');
}
}
/**
* MWHook: Display model when model file page edits are previewed
*
@@ -88,7 +72,7 @@ class GlModelHooks {
$out = $editor->getContext()->getOutput();
$out->addModules('ext.glmv');
$mvTransform = $file->transform([ 'width' => '800', 'hight' => '600']);
$mvTransform = $file->transform([ 'width' => '800', 'hight' => '600', 'view' => 'test']);
$previewViewer = $mvTransform->toHtml([ 'preview' => true]);
$addButtonAttr = array(

View File

@@ -18,10 +18,10 @@ class GlModelTransformOutput extends MediaTransformOutput {
public function __construct($file, $parameters) {
$this->file = $file;
$this->parameters = $parameters;
$this->width = (isset($parameters['width'])) ? $parameters['width'] : '800';
$this->height = (isset($parameters['height'])) ? $parameters['height'] : (int)($this->width * .75);
$this->width = $parameters['width'];
$this->height = $parameters['height'];
$this->url = $file->getFullUrl();
$this->thumb = isset($parameters['isFilePageThumb']);
$this->thumb = isset($parameters['isFilePageThumb']) && $parameters['isFilePageThumb'];
}
/**
@@ -43,7 +43,13 @@ class GlModelTransformOutput extends MediaTransformOutput {
*/
public function toHtml($options = []) {
if ($this->thumb) {
return Html::rawElement('span',['class' => 'fake-thumbnail'],'Gltf model thumbnail');
$mainConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
$thumbUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/model_thumb.svg';
$attrMenuImg = array (
'src' => $thumbUrl,
'style' => 'width: ' . $this->width . 'px; height: ' . $this->height . 'px;'
);
return Html::rawElement('img', $attrMenuImg, '');
}
if (isset($options['img-class'])) {

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="40px" viewBox="0 -960 960 960" width="40px" fill="#5f6368"><path d="M446.67-163.67V-461l-260-150.33V-314l260 150.33Zm66.66 0 260-150.33v-298l-260 150.89v297.44ZM480-518l256.33-149L480-815.33 223-667l257 149ZM153.33-256q-15.83-9.28-24.58-24.48-8.75-15.19-8.75-33.19v-332.66q0-18 8.75-33.19 8.75-15.2 24.58-24.48l293.34-169q15.88-9 33.44-9 17.56 0 33.22 9l293.34 169q15.83 9.28 24.58 24.48 8.75 15.19 8.75 33.19v332.66q0 18-8.75 33.19-8.75 15.2-24.58 24.48L513.33-87q-15.88 9-33.44 9-17.56 0-33.22-9L153.33-256ZM480-480Z"/></svg>

After

Width:  |  Height:  |  Size: 575 B