Initiales Karate-Wiki Setup (Docker, LocalSettings, KarateMedia Video-Extension)
This commit is contained in:
commit
53aec82f7d
17 files changed
+763
No files matched your search
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\KarateMedia;
|
||||
|
||||
use Html;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use OutputPage;
|
||||
use Parser;
|
||||
use PPFrame;
|
||||
use Skin;
|
||||
use Title;
|
||||
|
||||
class KarateMediaHooks {
|
||||
|
||||
/**
|
||||
* Registriert das <html5media>-Tag fuer Abwaertskompatibilitaet mit bestehenden Wiki-Seiten.
|
||||
*/
|
||||
public static function onParserFirstCallInit( Parser $parser ): bool {
|
||||
$parser->setHook( 'html5media', [ self::class, 'renderHtml5MediaTag' ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Laedt CSS und JS fuer die Video-Steuerung (z.B. Zeitlupe fuer Kata/Bunkai).
|
||||
*/
|
||||
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ): void {
|
||||
$out->addModules( [ 'ext.karateMedia' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert <html5media height="200" width="300">File:Beispiel.mp4</html5media>
|
||||
*/
|
||||
public static function renderHtml5MediaTag( ?string $input, array $args, Parser $parser, PPFrame $frame ): string {
|
||||
if ( $input === null || trim( $input ) === '' ) {
|
||||
return Html::element( 'span', [ 'class' => 'error' ], 'KarateMedia: Keine Mediendatei angegeben.' );
|
||||
}
|
||||
|
||||
$rawTarget = trim( $input );
|
||||
|
||||
// Entferne vorangestelltes "File:" oder "Datei:" falls vorhanden
|
||||
$cleanFileName = preg_replace( '/^(file|datei|image|bild)\s*:\s*/i', '', $rawTarget );
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$repoGroup = $services->getRepoGroup();
|
||||
|
||||
$title = Title::makeTitleSafe( NS_FILE, $cleanFileName );
|
||||
$file = $title ? $repoGroup->findFile( $title ) : false;
|
||||
|
||||
if ( !$file || !$file->exists() ) {
|
||||
return Html::element(
|
||||
'span',
|
||||
[ 'class' => 'error karate-media-missing' ],
|
||||
'Video nicht gefunden: ' . $cleanFileName
|
||||
);
|
||||
}
|
||||
|
||||
$url = $file->getUrl();
|
||||
$ext = strtolower( pathinfo( $file->getName(), PATHINFO_EXTENSION ) );
|
||||
|
||||
$attrs = [
|
||||
'src' => $url,
|
||||
'controls' => true,
|
||||
'preload' => 'metadata',
|
||||
'playsinline' => true,
|
||||
'class' => 'karate-video-player',
|
||||
];
|
||||
|
||||
if ( isset( $args['width'] ) && is_numeric( $args['width'] ) ) {
|
||||
$attrs['width'] = (int)$args['width'];
|
||||
}
|
||||
if ( isset( $args['height'] ) && is_numeric( $args['height'] ) ) {
|
||||
$attrs['height'] = (int)$args['height'];
|
||||
}
|
||||
|
||||
if ( in_array( $ext, [ 'mp3', 'ogg' ], true ) && strpos( $file->getMimeType(), 'audio/' ) === 0 ) {
|
||||
$attrs['class'] = 'karate-audio-player';
|
||||
return Html::rawElement( 'div', [ 'class' => 'karate-media-wrapper' ],
|
||||
Html::element( 'audio', $attrs )
|
||||
);
|
||||
}
|
||||
|
||||
return self::buildVideoHtml( $attrs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt das HTML fuer den Videoplayer inklusive Karate-Zeitlupen-Leiste.
|
||||
*/
|
||||
public static function buildVideoHtml( array $videoAttrs ): string {
|
||||
$videoTag = Html::element( 'video', $videoAttrs );
|
||||
|
||||
$controls = Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'karate-video-controls', 'title' => 'Abspielgeschwindigkeit fuer Kata/Bunkai-Studium' ],
|
||||
Html::element( 'button', [ 'type' => 'button', 'class' => 'km-speed-btn active', 'data-speed' => '1' ], '1x' ) .
|
||||
Html::element( 'button', [ 'type' => 'button', 'class' => 'km-speed-btn', 'data-speed' => '0.5' ], '0.5x' ) .
|
||||
Html::element( 'button', [ 'type' => 'button', 'class' => 'km-speed-btn', 'data-speed' => '0.25' ], '0.25x' ) .
|
||||
Html::element( 'button', [ 'type' => 'button', 'class' => 'km-loop-btn', 'data-loop' => '0' ], 'Loop' )
|
||||
);
|
||||
|
||||
return Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'karate-media-wrapper' ],
|
||||
$videoTag . $controls
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\KarateMedia;
|
||||
|
||||
use File;
|
||||
use MediaTransformOutput;
|
||||
|
||||
class KarateVideoTransformOutput extends MediaTransformOutput {
|
||||
|
||||
public function __construct( File $file, string $url, int $width, int $height ) {
|
||||
$this->file = $file;
|
||||
$this->url = $url;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
public function toHtml( $options = [] ): string {
|
||||
$attrs = [
|
||||
'src' => $this->url,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
'controls' => true,
|
||||
'preload' => 'metadata',
|
||||
'playsinline' => true,
|
||||
'class' => 'karate-video-player',
|
||||
];
|
||||
|
||||
return KarateMediaHooks::buildVideoHtml( $attrs );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user