Enable metadata versioning
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -2,10 +2,11 @@
|
|||||||
namespace MediaWiki\Extension\GlModelViewer;
|
namespace MediaWiki\Extension\GlModelViewer;
|
||||||
|
|
||||||
use ImageHandler;
|
use ImageHandler;
|
||||||
|
use BitmapMetadataHandler;
|
||||||
use Html;
|
use Html;
|
||||||
|
|
||||||
class GlModelHandler extends ImageHandler {
|
class GlModelHandler extends ImageHandler {
|
||||||
private const glmvVersion = '0.1';
|
private const GLMV_VERSION = '0.2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model cannot be displayed directly in a browser but can be rendered.
|
* Model cannot be displayed directly in a browser but can be rendered.
|
||||||
@@ -169,7 +170,6 @@ class GlModelHandler extends ImageHandler {
|
|||||||
* bits, and metadata keys. All keys are optional.
|
* bits, and metadata keys. All keys are optional.
|
||||||
*/
|
*/
|
||||||
public function getSizeAndMetadata ($state, $path) {
|
public function getSizeAndMetadata ($state, $path) {
|
||||||
|
|
||||||
$gltf = fopen($path, 'r');
|
$gltf = fopen($path, 'r');
|
||||||
fseek($gltf,12);
|
fseek($gltf,12);
|
||||||
$glMetaLength = unpack("Iint", fread($gltf, 4));
|
$glMetaLength = unpack("Iint", fread($gltf, 4));
|
||||||
@@ -177,7 +177,8 @@ class GlModelHandler extends ImageHandler {
|
|||||||
$glMeta = json_decode(fread($gltf,$glMetaLength['int']),true);
|
$glMeta = json_decode(fread($gltf,$glMetaLength['int']),true);
|
||||||
fclose($gltf);
|
fclose($gltf);
|
||||||
$newMeta = array(
|
$newMeta = array(
|
||||||
'Type' => $glType
|
'glmv-meshes' => count($glMeta['meshes']),
|
||||||
|
'glmv-textures' => count($glMeta['textures'])
|
||||||
);
|
);
|
||||||
foreach($glMeta['asset'] as $key => $value) {
|
foreach($glMeta['asset'] as $key => $value) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
@@ -195,9 +196,9 @@ class GlModelHandler extends ImageHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$newMeta['glmv-meshes'] = count($glMeta['meshes']);
|
$newMeta['glmv-metadata'] = self::GLMV_VERSION;
|
||||||
$newMeta['glmv-textures'] = count($glMeta['textures']);
|
$metaHandler = new BitmapMetadataHandler;
|
||||||
$newMeta['glmv-metadata'] = self::glmvVersion;
|
$metaHandler->addMetadata($newMeta,'exif');
|
||||||
return array(
|
return array(
|
||||||
'width' => 600,
|
'width' => 600,
|
||||||
'height' => 800,
|
'height' => 800,
|
||||||
@@ -212,13 +213,13 @@ class GlModelHandler extends ImageHandler {
|
|||||||
* MediaHandler::METADATA_GOOD for if the metadata is a-ok,
|
* MediaHandler::METADATA_GOOD for if the metadata is a-ok,
|
||||||
* MediaHandler::METADATA_COMPATIBLE if metadata is old but backwards compatible (which may or may not trigger a metadata reload).
|
* MediaHandler::METADATA_COMPATIBLE if metadata is old but backwards compatible (which may or may not trigger a metadata reload).
|
||||||
*
|
*
|
||||||
* TODO: This version is for testing/dev only. Better checking will be requried in the future
|
* TODO: This version is for testing/dev only. Better checking will be required in the future
|
||||||
* @param File $image
|
* @param File $image
|
||||||
* @return bool|int
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function isFileMetadataValid ($image) {
|
public function isFileMetadataValid ($image) {
|
||||||
$meta = $image->getMetadataItems('glmv-metadata');
|
$meta = $image->getMetadataItems(['glmv-metadata']);
|
||||||
if (!isset($meta['glmv-metadata']) || $meta['glmv-metadata'] != self::glmvVersion) {
|
if (!isset($meta['glmv-metadata']) || $meta['glmv-metadata'] != self::GLMV_VERSION) {
|
||||||
return self::METADATA_BAD;
|
return self::METADATA_BAD;
|
||||||
}
|
}
|
||||||
return self::METADATA_GOOD;
|
return self::METADATA_GOOD;
|
||||||
|
|||||||
Reference in New Issue
Block a user