64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\KarateMedia;
|
|
|
|
use File;
|
|
use MediaHandler;
|
|
use MediaTransformOutput;
|
|
|
|
/**
|
|
* MediaHandler fuer [[Datei:Beispiel.mp4|mini|Beschreibung]] und [[File:Beispiel.mp4|300x169px]]
|
|
*/
|
|
class KarateVideoHandler extends MediaHandler {
|
|
|
|
public function getParamMap(): array {
|
|
return [
|
|
'img_width' => 'width',
|
|
];
|
|
}
|
|
|
|
public function validateParam( $name, $value ): bool {
|
|
if ( in_array( $name, [ 'width', 'height' ], true ) ) {
|
|
return $value > 0;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function makeParamString( $params ): string {
|
|
$width = $params['width'] ?? 320;
|
|
return "{$width}px";
|
|
}
|
|
|
|
public function parseParamString( $str ) {
|
|
if ( preg_match( '/^(\d+)px$/', $str, $m ) ) {
|
|
return [ 'width' => (int)$m[1] ];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function normaliseParams( $image, &$params ): bool {
|
|
if ( !isset( $params['width'] ) || $params['width'] <= 0 ) {
|
|
$params['width'] = 320;
|
|
}
|
|
if ( !isset( $params['height'] ) || $params['height'] <= 0 ) {
|
|
$params['height'] = (int)round( $params['width'] * 9 / 16 );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function getImageSize( $image, $path ) {
|
|
// Standard 16:9 Fallback-Dimensionen fuer den MediaWiki-Layout-Berechner
|
|
return [ 640, 360 ];
|
|
}
|
|
|
|
public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ): MediaTransformOutput {
|
|
$this->normaliseParams( $image, $params );
|
|
return new KarateVideoTransformOutput(
|
|
$image,
|
|
$image->getUrl(),
|
|
(int)$params['width'],
|
|
(int)$params['height']
|
|
);
|
|
}
|
|
}
|