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,48 @@
|
||||
{
|
||||
"name": "KarateMedia",
|
||||
"version": "1.0.0",
|
||||
"author": [
|
||||
"Goju-Kai Dojo"
|
||||
],
|
||||
"url": "https://www.gojukai-dojo.de",
|
||||
"description": "Schlanke, wartungsfreie HTML5-Video- und Audio-Erweiterung fuer das Karate-Wiki (unterstuetzt <html5media> und [[Datei:*.mp4]])",
|
||||
"license-name": "GPL-2.0-or-later",
|
||||
"type": "media",
|
||||
"requires": {
|
||||
"MediaWiki": ">= 1.35.0"
|
||||
},
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\KarateMedia\\": "src/"
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": "MediaWiki\\Extension\\KarateMedia\\KarateMediaHooks::onParserFirstCallInit",
|
||||
"BeforePageDisplay": "MediaWiki\\Extension\\KarateMedia\\KarateMediaHooks::onBeforePageDisplay"
|
||||
},
|
||||
"MediaHandlers": {
|
||||
"video/mp4": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler",
|
||||
"video/webm": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler",
|
||||
"video/ogg": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler",
|
||||
"application/ogg": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler",
|
||||
"audio/mpeg": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler",
|
||||
"audio/mp3": "MediaWiki\\Extension\\KarateMedia\\KarateVideoHandler"
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.karateMedia": {
|
||||
"styles": [
|
||||
"resources/karatemedia.css"
|
||||
],
|
||||
"scripts": [
|
||||
"resources/karatemedia.js"
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "",
|
||||
"remoteExtPath": "KarateMedia"
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
.karate-media-wrapper {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
margin: 4px 0;
|
||||
background: #1a1a1a;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.karate-video-player {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.karate-video-controls {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 4px 8px;
|
||||
background: #262626;
|
||||
border-top: 1px solid #3a3a3a;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.karate-video-controls button {
|
||||
background: #3a3a3a;
|
||||
color: #e0e0e0;
|
||||
border: 1px solid #505050;
|
||||
border-radius: 3px;
|
||||
padding: 2px 7px;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.karate-video-controls button:hover {
|
||||
background: #505050;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.karate-video-controls button.active {
|
||||
background: #b71c1c;
|
||||
border-color: #d32f2f;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.karate-media-missing {
|
||||
display: inline-block;
|
||||
padding: 4px 8px;
|
||||
background: #ffebee;
|
||||
border: 1px solid #ef9a9a;
|
||||
border-radius: 4px;
|
||||
color: #b71c1c;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
document.addEventListener( 'click', function ( ev ) {
|
||||
var speedBtn = ev.target.closest( '.km-speed-btn' );
|
||||
if ( speedBtn ) {
|
||||
var wrapper = speedBtn.closest( '.karate-media-wrapper' );
|
||||
var video = wrapper && wrapper.querySelector( 'video' );
|
||||
if ( video ) {
|
||||
var speed = parseFloat( speedBtn.getAttribute( 'data-speed' ) || '1' );
|
||||
video.playbackRate = speed;
|
||||
wrapper.querySelectorAll( '.km-speed-btn' ).forEach( function ( btn ) {
|
||||
btn.classList.toggle( 'active', btn === speedBtn );
|
||||
} );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var loopBtn = ev.target.closest( '.km-loop-btn' );
|
||||
if ( loopBtn ) {
|
||||
var loopWrapper = loopBtn.closest( '.karate-media-wrapper' );
|
||||
var loopVideo = loopWrapper && loopWrapper.querySelector( 'video' );
|
||||
if ( loopVideo ) {
|
||||
loopVideo.loop = !loopVideo.loop;
|
||||
loopBtn.classList.toggle( 'active', loopVideo.loop );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}() );
|
||||
@@ -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