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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user