Refactor to MediaHandler transform
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
92
includes/GlModelTransformOutput.php
Normal file
92
includes/GlModelTransformOutput.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace MediaWiki\Extension\GlModelViewer;
|
||||
|
||||
use MediaTransformOutput;
|
||||
use Html;
|
||||
|
||||
class GlModelTransformOutput extends MediaTransformOutput {
|
||||
/**
|
||||
* Main Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param File $file
|
||||
* @param array $parameters Parameters for constructing HTML.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file, $parameters) {
|
||||
$this->file = $file;
|
||||
$this->parameters = $parameters;
|
||||
$this->url = $file->getFullUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch HTML for this transform output
|
||||
*
|
||||
* @access public
|
||||
* @param array $options Associative array of options. Boolean options
|
||||
* should be indicated with a value of true for true, and false or
|
||||
* absent for false.
|
||||
* alt Alternate text or caption
|
||||
* desc-link Boolean, show a description link
|
||||
* file-link Boolean, show a file download link
|
||||
* custom-url-link Custom URL to link to
|
||||
* custom-title-link Custom Title object to link to
|
||||
* valign vertical-align property, if the output is an inline element
|
||||
* img-class Class applied to the "<img>" tag, if there is such a tag
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function toHtml($options = []) {
|
||||
return Html::rawElement( 'div',[ 'class' => 'my-model-class'], $this->url . ' is a ' . $this->parameters['type'] . ' 3D model!' );
|
||||
/*
|
||||
$parameters = $this->parameters;
|
||||
|
||||
$style = [];
|
||||
$style[] = "max-width: 100%;";
|
||||
$style[] = "max-height: 100%;";
|
||||
if (empty($options['no-dimensions'])) {
|
||||
$parameters['width'] = $this->getWidth();
|
||||
$parameters['height'] = $this->getHeight();
|
||||
$style[] = "width: {$this->getWidth()}px;";
|
||||
$style[] = "height: {$this->getHeight()}px;";
|
||||
}
|
||||
|
||||
if (!empty($options['valign'])) {
|
||||
$style[] = "vertical-align: {$options['valign']};";
|
||||
}
|
||||
|
||||
if (!empty($options['img-class'])) {
|
||||
$class = $options['img-class'];
|
||||
}
|
||||
|
||||
if (!isset($parameters['start'])) {
|
||||
$parameters['start'] = null;
|
||||
}
|
||||
if (!isset($parameters['end'])) {
|
||||
$parameters['end'] = null;
|
||||
}
|
||||
|
||||
$inOut = false;
|
||||
if ($parameters['start'] !== $parameters['end']) {
|
||||
if ($parameters['start'] !== false) {
|
||||
$inOut[] = $parameters['start'];
|
||||
}
|
||||
|
||||
if ($parameters['end'] !== false) {
|
||||
$inOut[] = $parameters['end'];
|
||||
}
|
||||
}
|
||||
|
||||
$descLink = Html::element( 'a', [ 'href' => $parameters['descriptionUrl'] ], $parameters['descriptionUrl'] );
|
||||
|
||||
return Html::rawElement( 'video', [
|
||||
'src' => $this->url . ($inOut !== false ? '#t=' . implode(',', $inOut) : ''),
|
||||
'width' => $this->getWidth(),
|
||||
'height' => $this->getHeight(),
|
||||
'class' => $class ?? false,
|
||||
'style' => $style ? implode( ' ', $style ) : false,
|
||||
'controls' => true,
|
||||
], $descLink );
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user