Add basic gltf format checking
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -124,6 +124,41 @@ class GlModelHooks {
|
||||
$out->addModules('ext.glmv.upl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform upload verification, based on both file properties like MIME type
|
||||
* (same as UploadVerifyFile) and the information entered by the user (upload
|
||||
* comment, file page contents etc.).
|
||||
*
|
||||
* @param UploadBase $upload Instance of UploadBase, with all info about the upload
|
||||
* @param User $user User uploading this file
|
||||
* @param array | null $props File properties, as returned by MWFileProps::getPropsFromPath()
|
||||
* @param string $comment Upload log comment (also used as edit summary)
|
||||
* @param string | false $pageText File description page text (only used for new uploads)
|
||||
* @param array | MessageSpecifier | null &$error Output: If the file upload should be prevented, set this to the reason
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public static function onUploadVerifyUpload ($upload, $user, ?array $props, $comment, $pageText, &$error) {
|
||||
if ($props['mime'] != 'model/gltf-binary') {
|
||||
return true;
|
||||
} else {
|
||||
$path = $upload->getTempPath();
|
||||
$gltf = fopen($path, 'r');
|
||||
$glHeader = fread($gltf, 4);
|
||||
fclose($gltf);
|
||||
|
||||
if ($glHeader == 'glTF') {
|
||||
return true;
|
||||
} else {
|
||||
$error = array(
|
||||
"glmv-load-error-format",
|
||||
$upload->getTitle()->getRootText()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MWHook: Called just before the upload data, like wpUploadDescription, are processed, so extensions get a chance to manipulate them.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user