Add view and hsset link parameters
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
7
GlModelHandler.i18n.magic.php
Normal file
7
GlModelHandler.i18n.magic.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
$magicWords = [];
|
||||||
|
|
||||||
|
$magicWords['en'] = [
|
||||||
|
'glmv_view' => [ 1, "view=$1" ],
|
||||||
|
'glmv_hsset' => [1, "set=$1"]
|
||||||
|
];
|
||||||
@@ -19,6 +19,9 @@
|
|||||||
"BeforePageDisplay": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onBeforePageDisplay",
|
"BeforePageDisplay": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onBeforePageDisplay",
|
||||||
"AlternateEditPreview": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onAlternateEditPreview"
|
"AlternateEditPreview": "MediaWiki\\Extension\\GlModelViewer\\GlModelHooks::onAlternateEditPreview"
|
||||||
},
|
},
|
||||||
|
"ExtensionMessagesFiles": {
|
||||||
|
"GlModelHandlerMagic": "GlModelHandler.i18n.magic.php"
|
||||||
|
},
|
||||||
"ResourceFileModulePaths": {
|
"ResourceFileModulePaths": {
|
||||||
"localBasePath": "modules",
|
"localBasePath": "modules",
|
||||||
"remoteExtPath": "GlModelViewer/modules"
|
"remoteExtPath": "GlModelViewer/modules"
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ class GlModelHandler extends ImageHandler {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateParam( $name, $value ) {
|
public function validateParam( $name, $value ) {
|
||||||
echo '<script>';
|
|
||||||
self::console_log('Param: ' . $name . " = " . $value);
|
|
||||||
echo '</script>';
|
|
||||||
if (in_array($name, ['width', 'height'])) {
|
if (in_array($name, ['width', 'height'])) {
|
||||||
return $value > 0;
|
return $value > 0;
|
||||||
} else if (in_array($name, ['view', 'hsset'])) {
|
} else if (in_array($name, ['view', 'hsset'])) {
|
||||||
@@ -71,6 +68,68 @@ class GlModelHandler extends ImageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge a parameter array into a string appropriate for inclusion in filenames.
|
||||||
|
*
|
||||||
|
* @param array $params array of parameters that have been through normaliseParams.
|
||||||
|
* @return string concatenated, formatted string of parameter values
|
||||||
|
*/
|
||||||
|
public function makeParamString( $params ) {
|
||||||
|
$res = parent::makeParamString( $params );
|
||||||
|
if ( $res && isset( $params['hsset'] ) ) {
|
||||||
|
$res = "hs{$params['hsset']}-$res";
|
||||||
|
}
|
||||||
|
if ( $res && isset( $params['view'] ) ) {
|
||||||
|
$res = "v{$params['view']}-$res";
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a param string made with makeParamString back into an array.
|
||||||
|
*
|
||||||
|
* @param string $str the parameter string without file name
|
||||||
|
* @return array|false Array of parameters or false on failure
|
||||||
|
*/
|
||||||
|
public function parseParamString( $str ) {
|
||||||
|
preg_match( '/v([^-]*?)-/', $str, $view );
|
||||||
|
preg_match( '/hs([^-]*?)-/', $str, $hsset );
|
||||||
|
$otherParams = preg_replace('/(?:(?:hs[^-]*?-)|(?:v[^-]*?-))*(.*)$/', '/$1/', $str);
|
||||||
|
$parsedParams = parent::parseParamString( $otherParams );
|
||||||
|
$parsedParams['view'] = $view;
|
||||||
|
$parsedParams['hsset'] = $hsset;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?
|
||||||
|
*
|
||||||
|
* @param array $params input parameters
|
||||||
|
* @return array same array as input?
|
||||||
|
*/
|
||||||
|
protected function getScriptParams( $params ) {
|
||||||
|
$res = parent::getScriptParams( $params );
|
||||||
|
if ( isset( $params['view'] ) ) {
|
||||||
|
$res['view'] = $params['view'];
|
||||||
|
}
|
||||||
|
if ( isset( $params['hsset'] ) ) {
|
||||||
|
$res['hsset'] = $params['hsset'];
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an associative array mapping magic word IDs to parameter names.
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getParamMap() {
|
||||||
|
return [
|
||||||
|
'img_width' => 'width',
|
||||||
|
'glmv_view' => 'view',
|
||||||
|
'glmv_hsset' => 'hsset'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Small helper function to display information on the browser console
|
* Small helper function to display information on the browser console
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
|||||||
$this->parameters = $parameters;
|
$this->parameters = $parameters;
|
||||||
$this->width = $parameters['width'];
|
$this->width = $parameters['width'];
|
||||||
$this->height = $parameters['height'];
|
$this->height = $parameters['height'];
|
||||||
|
$this->view = (isset($parameters['view'])) ? $parameters['view'] : 'default';
|
||||||
|
$this->hsset = (isset($parameters['hsset'])) ? $parameters['hsset'] : 'all';
|
||||||
$this->url = $file->getFullUrl();
|
$this->url = $file->getFullUrl();
|
||||||
$this->thumb = isset($parameters['isFilePageThumb']) && $parameters['isFilePageThumb'];
|
$this->thumb = isset($parameters['isFilePageThumb']) && $parameters['isFilePageThumb'];
|
||||||
}
|
}
|
||||||
@@ -79,15 +81,15 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
|||||||
//Gather basic data
|
//Gather basic data
|
||||||
preg_match('/<pre>([\S\s]*?)<\/pre>/',$inText,$modelDescript);
|
preg_match('/<pre>([\S\s]*?)<\/pre>/',$inText,$modelDescript);
|
||||||
$metadata = json_decode($modelDescript[1], true);
|
$metadata = json_decode($modelDescript[1], true);
|
||||||
$viewClass = self::extractClassParams('view',$viewParams['class']);
|
$hsSet = (isset($metadata['annotationSets']) && isset($metadata['annotationSets'][$this->hsset])) ? $this->hsset : 'default';
|
||||||
$hsSetClass = self::extractClassParams('hsset',$viewParams['class']);
|
$view = (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$this->view])) ? $this->view : 'default';
|
||||||
|
|
||||||
//Handle annotations and annotation sets
|
//Handle annotations and annotation sets
|
||||||
if (isset($metadata['annotations'])) {
|
if (isset($metadata['annotations'])) {
|
||||||
$hotspots = [];
|
$hotspots = [];
|
||||||
$annotations = [];
|
$annotations = [];
|
||||||
if ($hsSetClass != 'default' && isset($metadata['annotationSets'])) {
|
if ($hsSet != 'default') {
|
||||||
foreach($metadata['annotationSets'][$hsSetClass] as $includeAn) {
|
foreach($metadata['annotationSets'][$hsSet] as $includeAn) {
|
||||||
if (isset($metadata['annotations'][$includeAn])) {
|
if (isset($metadata['annotations'][$includeAn])) {
|
||||||
$annotations[$includeAn] = $metadata['annotations'][$includeAn];
|
$annotations[$includeAn] = $metadata['annotations'][$includeAn];
|
||||||
}
|
}
|
||||||
@@ -114,8 +116,8 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set viewer configurations or use basic default if none defined
|
//Set viewer configurations or use basic default if none defined
|
||||||
if (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$viewClass])) {
|
if (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$view])) {
|
||||||
$attrModelView = $metadata['viewerConfig'][$viewClass];
|
$attrModelView = $metadata['viewerConfig'][$view];
|
||||||
} else {
|
} else {
|
||||||
$attrModelView = array('camera-controls' => true);
|
$attrModelView = array('camera-controls' => true);
|
||||||
}
|
}
|
||||||
@@ -139,32 +141,6 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
|||||||
return Html::rawElement('div', $attrContainer, $elModel . $elMenu);
|
return Html::rawElement('div', $attrContainer, $elModel . $elMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect and return model user params from link classes
|
|
||||||
*
|
|
||||||
* The best way to send information in a file link is by adding classes to the
|
|
||||||
* link. This function parses the array of those classes and returns the information
|
|
||||||
* or 'default'
|
|
||||||
*
|
|
||||||
* @param string $paramType the type of parameter to be extracted 'view'|'hsset'
|
|
||||||
* @param string $classList a string of class names
|
|
||||||
* @return string parameter value or 'default'
|
|
||||||
*/
|
|
||||||
private static function extractClassParams(string $paramType, ? string $classList) {
|
|
||||||
if (!in_array($paramType, ['view', 'hsset'])) {
|
|
||||||
return 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($classList)) {
|
|
||||||
return 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
$searchString = '/' . $paramType . '-(\S*)/';
|
|
||||||
preg_match($searchString,$classList,$extractInfo);
|
|
||||||
|
|
||||||
return ($extractInfo[1]) ? $extractInfo[1] : 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the button menu used for viewer actions
|
* Build the button menu used for viewer actions
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user