Konvertiere alle <html5media>-Tags im Wikitext auf MediaWiki-Standard [[Datei:...]]
Deploy Development / deploy (push) Successful in 39s
Deploy Development / deploy (push) Successful in 39s
This commit is contained in:
1 parent
86b9bbdb78
commit
5f7e304f28
5 files changed
+155
-2
No files matched your search
@@ -115,6 +115,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
docker compose -f docker-compose.dev-env.yml run --rm --no-deps mediawiki php maintenance/run.php update --quick
|
docker compose -f docker-compose.dev-env.yml run --rm --no-deps mediawiki php maintenance/run.php update --quick
|
||||||
|
docker compose -f docker-compose.dev-env.yml run --rm --no-deps mediawiki php maintenance/run.php /var/www/html/scripts/migrate-html5media-tags.php
|
||||||
if ! docker compose -f docker-compose.dev-env.yml up -d --wait; then
|
if ! docker compose -f docker-compose.dev-env.yml up -d --wait; then
|
||||||
echo "compose up --wait failed — mediawiki logs:"
|
echo "compose up --wait failed — mediawiki logs:"
|
||||||
docker compose -f docker-compose.dev-env.yml logs mediawiki --tail 150 || true
|
docker compose -f docker-compose.dev-env.yml logs mediawiki --tail 150 || true
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ jobs:
|
|||||||
done
|
done
|
||||||
docker compose run --rm --no-deps mediawiki php /usr/local/bin/ensure-db-schema.php
|
docker compose run --rm --no-deps mediawiki php /usr/local/bin/ensure-db-schema.php
|
||||||
docker compose run --rm --no-deps mediawiki php maintenance/run.php update --quick
|
docker compose run --rm --no-deps mediawiki php maintenance/run.php update --quick
|
||||||
|
docker compose run --rm --no-deps mediawiki php maintenance/run.php /var/www/html/scripts/migrate-html5media-tags.php
|
||||||
if ! docker compose up -d --wait; then
|
if ! docker compose up -d --wait; then
|
||||||
echo "compose up --wait failed — mediawiki logs:"
|
echo "compose up --wait failed — mediawiki logs:"
|
||||||
docker compose logs mediawiki --tail 150 || true
|
docker compose logs mediawiki --tail 150 || true
|
||||||
@@ -104,20 +105,26 @@ jobs:
|
|||||||
tar -czf - \
|
tar -czf - \
|
||||||
config/LocalSettings.php \
|
config/LocalSettings.php \
|
||||||
config/php-uploads.ini \
|
config/php-uploads.ini \
|
||||||
|
scripts/migrate-html5media-tags.php \
|
||||||
assets/ \
|
assets/ \
|
||||||
extensions-custom/KarateMedia/ \
|
extensions-custom/KarateMedia/ \
|
||||||
| ssh "${SSH_OPTS[@]}" "${STRATO_USER}@${STRATO_HOST}" '
|
| ssh "${SSH_OPTS[@]}" "${STRATO_USER}@${STRATO_HOST}" '
|
||||||
set -e
|
set -e
|
||||||
TMP_DEPLOY="$(mktemp -d)"
|
TMP_DEPLOY=~/karatewiki-shared/tmp_deploy
|
||||||
|
rm -rf "$TMP_DEPLOY"
|
||||||
|
mkdir -p "$TMP_DEPLOY"
|
||||||
tar -xzf - -C "$TMP_DEPLOY"
|
tar -xzf - -C "$TMP_DEPLOY"
|
||||||
cp "$TMP_DEPLOY/config/LocalSettings.php" ~/Karatewiki/LocalSettings.php
|
cp "$TMP_DEPLOY/config/LocalSettings.php" ~/Karatewiki/LocalSettings.php
|
||||||
cp "$TMP_DEPLOY/config/php-uploads.ini" ~/Karatewiki/php.ini
|
cp "$TMP_DEPLOY/config/php-uploads.ini" ~/Karatewiki/php.ini
|
||||||
cp "$TMP_DEPLOY/config/php-uploads.ini" ~/Karatewiki/.user.ini
|
cp "$TMP_DEPLOY/config/php-uploads.ini" ~/Karatewiki/.user.ini
|
||||||
|
mkdir -p ~/Karatewiki/scripts
|
||||||
|
cp "$TMP_DEPLOY/scripts/migrate-html5media-tags.php" ~/Karatewiki/scripts/migrate-html5media-tags.php
|
||||||
cp -r "$TMP_DEPLOY/assets/"* ~/Karatewiki/resources/assets/
|
cp -r "$TMP_DEPLOY/assets/"* ~/Karatewiki/resources/assets/
|
||||||
rm -rf ~/Karatewiki/extensions/KarateMedia
|
rm -rf ~/Karatewiki/extensions/KarateMedia
|
||||||
cp -r "$TMP_DEPLOY/extensions-custom/KarateMedia" ~/Karatewiki/extensions/KarateMedia
|
cp -r "$TMP_DEPLOY/extensions-custom/KarateMedia" ~/Karatewiki/extensions/KarateMedia
|
||||||
rm -rf "$TMP_DEPLOY"
|
rm -rf "$TMP_DEPLOY"
|
||||||
/opt/RZphp84/bin/php-cli ~/Karatewiki/maintenance/run.php update --quick
|
/opt/RZphp84/bin/php-cli ~/Karatewiki/maintenance/run.php update --quick
|
||||||
|
/opt/RZphp84/bin/php-cli ~/Karatewiki/maintenance/run.php ~/Karatewiki/scripts/migrate-html5media-tags.php
|
||||||
'
|
'
|
||||||
echo "=== Strato ~/Karatewiki erfolgreich aktualisiert! ==="
|
echo "=== Strato ~/Karatewiki erfolgreich aktualisiert! ==="
|
||||||
else
|
else
|
||||||
|
|||||||
+2
-1
@@ -23,8 +23,9 @@ COPY config/php-uploads.ini /usr/local/etc/php/conf.d/zz-karate-uploads.ini
|
|||||||
# Vereins-Logos & Favicon ins Image kopieren
|
# Vereins-Logos & Favicon ins Image kopieren
|
||||||
COPY assets/ /var/www/html/resources/assets/
|
COPY assets/ /var/www/html/resources/assets/
|
||||||
|
|
||||||
# DB-Initialisierungshilfe fuer Erst-Deployments auf dem Raspberry Pi
|
# DB-Initialisierungshilfe & Tag-Migration fuer Deployments
|
||||||
COPY scripts/ensure-db-schema.php /usr/local/bin/ensure-db-schema.php
|
COPY scripts/ensure-db-schema.php /usr/local/bin/ensure-db-schema.php
|
||||||
|
COPY scripts/migrate-html5media-tags.php /var/www/html/scripts/migrate-html5media-tags.php
|
||||||
|
|
||||||
# Unsere eigene, wartungsfreie Video- & Vereins-Extension
|
# Unsere eigene, wartungsfreie Video- & Vereins-Extension
|
||||||
COPY extensions-custom/KarateMedia /var/www/html/extensions/KarateMedia
|
COPY extensions-custom/KarateMedia /var/www/html/extensions/KarateMedia
|
||||||
@@ -37,6 +37,9 @@ class KarateVideoHandler extends MediaHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function normaliseParams( $image, &$params ): bool {
|
public function normaliseParams( $image, &$params ): bool {
|
||||||
|
if ( ( !isset( $params['width'] ) || $params['width'] <= 0 ) && isset( $params['height'] ) && $params['height'] > 0 ) {
|
||||||
|
$params['width'] = (int)round( $params['height'] * 16 / 9 );
|
||||||
|
}
|
||||||
if ( !isset( $params['width'] ) || $params['width'] <= 0 ) {
|
if ( !isset( $params['width'] ) || $params['width'] <= 0 ) {
|
||||||
$params['width'] = 320;
|
$params['width'] = 320;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Konvertiert alle veralteten <html5media ...>File:...</html5media> Tags
|
||||||
|
* im Wikitext in den offiziellen MediaWiki-Standard [[Datei:...|...px]].
|
||||||
|
*
|
||||||
|
* Aufruf:
|
||||||
|
* php maintenance/run.php scripts/migrate-html5media-tags.php [--dry-run]
|
||||||
|
*/
|
||||||
|
|
||||||
|
use MediaWiki\CommentStore\CommentStoreComment;
|
||||||
|
use MediaWiki\Content\ContentHandler;
|
||||||
|
use MediaWiki\Content\TextContent;
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use MediaWiki\Revision\SlotRecord;
|
||||||
|
use MediaWiki\Title\Title;
|
||||||
|
use MediaWiki\User\User;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../maintenance/Maintenance.php';
|
||||||
|
|
||||||
|
class MigrateHtml5MediaTags extends Maintenance {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
$this->addDescription( 'Ersetzt <html5media>-Tags durch MediaWiki-Standard [[Datei:...]] Syntax.' );
|
||||||
|
$this->addOption( 'dry-run', 'Nur anzeigen, was geaendert wuerde, ohne zu speichern', false, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute() {
|
||||||
|
$dryRun = $this->hasOption( 'dry-run' );
|
||||||
|
$services = MediaWikiServices::getInstance();
|
||||||
|
$dbr = $services->getConnectionProvider()->getReplicaDatabase();
|
||||||
|
$wikiPageFactory = $services->getWikiPageFactory();
|
||||||
|
$revisionLookup = $services->getRevisionLookup();
|
||||||
|
|
||||||
|
$res = $dbr->newSelectQueryBuilder()
|
||||||
|
->select( [ 'page_id', 'page_namespace', 'page_title' ] )
|
||||||
|
->from( 'page' )
|
||||||
|
->orderBy( 'page_id' )
|
||||||
|
->caller( __METHOD__ )
|
||||||
|
->fetchResultSet();
|
||||||
|
|
||||||
|
$systemUser = User::newSystemUser( 'MediaWiki maintenance', [ 'steal' => true ] );
|
||||||
|
$pagesChanged = 0;
|
||||||
|
$tagsReplacedTotal = 0;
|
||||||
|
|
||||||
|
foreach ( $res as $row ) {
|
||||||
|
$title = Title::newFromRow( $row );
|
||||||
|
$rev = $revisionLookup->getRevisionByTitle( $title );
|
||||||
|
if ( !$rev ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$content = $rev->getContent( SlotRecord::MAIN );
|
||||||
|
if ( !$content instanceof TextContent ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldText = $content->getText();
|
||||||
|
if ( stripos( $oldText, '<html5media' ) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagCount = 0;
|
||||||
|
$newText = preg_replace_callback(
|
||||||
|
'/<html5media([^>]*)>(.*?)<\/html5media>/is',
|
||||||
|
function ( array $m ) use ( &$tagCount ): string {
|
||||||
|
$attrString = $m[1];
|
||||||
|
$inner = trim( $m[2] );
|
||||||
|
|
||||||
|
// Entferne vorangestelltes File: / Datei: / Image: / Bild:
|
||||||
|
$cleanFile = preg_replace( '/^(file|datei|image|bild)\s*:\s*/i', '', $inner );
|
||||||
|
$cleanFile = trim( $cleanFile );
|
||||||
|
if ( $cleanFile === '' ) {
|
||||||
|
return $m[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$width = null;
|
||||||
|
$height = null;
|
||||||
|
if ( preg_match( '/\bwidth\s*=\s*["\']?(\d+)["\']?/i', $attrString, $wm ) ) {
|
||||||
|
$width = (int)$wm[1];
|
||||||
|
}
|
||||||
|
if ( preg_match( '/\bheight\s*=\s*["\']?(\d+)["\']?/i', $attrString, $hm ) ) {
|
||||||
|
$height = (int)$hm[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$sizeParam = '';
|
||||||
|
if ( $width && $height ) {
|
||||||
|
$sizeParam = "|{$width}x{$height}px";
|
||||||
|
} elseif ( $width ) {
|
||||||
|
$sizeParam = "|{$width}px";
|
||||||
|
} elseif ( $height ) {
|
||||||
|
$calcWidth = (int)round( $height * 16 / 9 );
|
||||||
|
$sizeParam = "|{$calcWidth}x{$height}px";
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagCount++;
|
||||||
|
return "[[Datei:{$cleanFile}{$sizeParam}]]";
|
||||||
|
},
|
||||||
|
$oldText
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $newText === null || $newText === $oldText || $tagCount === 0 ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pagesChanged++;
|
||||||
|
$tagsReplacedTotal += $tagCount;
|
||||||
|
|
||||||
|
$this->output( sprintf(
|
||||||
|
"[%s] %s (%d Tag%s)\n",
|
||||||
|
$dryRun ? 'DRY-RUN' : 'UPDATE',
|
||||||
|
$title->getPrefixedText(),
|
||||||
|
$tagCount,
|
||||||
|
$tagCount === 1 ? '' : 's'
|
||||||
|
) );
|
||||||
|
|
||||||
|
if ( !$dryRun ) {
|
||||||
|
$wikiPage = $wikiPageFactory->newFromTitle( $title );
|
||||||
|
$updater = $wikiPage->newPageUpdater( $systemUser );
|
||||||
|
$newContent = ContentHandler::makeContent( $newText, $title );
|
||||||
|
$updater->setContent( SlotRecord::MAIN, $newContent );
|
||||||
|
$comment = CommentStoreComment::newUnsavedComment(
|
||||||
|
'Migration: <html5media> durch MediaWiki-Standard [[Datei:...]] ersetzt'
|
||||||
|
);
|
||||||
|
$updater->saveRevision(
|
||||||
|
$comment,
|
||||||
|
EDIT_UPDATE | EDIT_MINOR | EDIT_FORCE_BOT | EDIT_SUPPRESS_RC
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output( sprintf(
|
||||||
|
"\nFertig: %d Seiten (%d <html5media>-Tags) %s.\n",
|
||||||
|
$pagesChanged,
|
||||||
|
$tagsReplacedTotal,
|
||||||
|
$dryRun ? 'gefunden (Dry-Run)' : 'erfolgreich auf [[Datei:...]] umgestellt'
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$maintClass = MigrateHtml5MediaTags::class;
|
||||||
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
||||||
Reference in new issue
Block a user