Skip to content

Commit

Permalink
Merge branch 'release/v3.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Feb 13, 2023
2 parents 0b69492 + e1f1225 commit 0dbdd9a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starcitizenwiki/embedvideo",
"version": "3.2.4",
"version": "3.2.5",
"type": "mediawiki-extension",
"description": "Adds a parser function embedding video from popular sources.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EmbedVideo",
"version": "3.2.4",
"version": "3.2.5",
"author": [
"[https://www.mediawiki.org/wiki/User:Octfx Octfx]",
"[https://www.mediawiki.org/wiki/User:Alistair3149 Alistair3149]",
Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"embedvideo-error-id": "EmbedVideo received the bad id \"$2\" for the service \"$1\".",
"embedvideo-error-width": "EmbedVideo received the bad width parameter \"$1\".",
"embedvideo-error-height": "EmbedVideo received the bad height parameter \"$1\".",
"embedvideo-error-alignment": "EmbedVideo was given an illegal value for the alignment parameter \"$1\". Valid values are \"left\", \"center\", \"right\", or \"inline\".",
"embedvideo-error-alignment": "EmbedVideo was given an illegal value for the alignment parameter \"$1\". Valid values are \"left\", \"center\", or \"right\".",
"embedvideo-error-valignment": "EmbedVideo was given an illegal value for the valignment parameter \"$1\". Valid values are \"top\", \"middle\", \"bottom\", or \"baseline\".",
"embedvideo-error-urlargs": "EmbedVideo received a list of URL arguments that contained malformed data or blank arguments.",
"embedvideo-error-unknown": "EmbedVideo encountered an unknown error while trying to generate this video embed block. ($1)",
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"embedvideo-error-id": "« EmbedVideo » a reçu l’identifiant erroné « $2 » pour le service « $1 ».",
"embedvideo-error-width": "« EmbedVideo » a reçu une valeur erronée « $1 » pour le paramètre de largeur.",
"embedvideo-error-height": "« EmbedVideo » a reçu une valeur erronée « $1 » pour le paramètre de hauteur.",
"embedvideo-error-alignment": "« EmbedVideo » a reçu une valeur une valeur erronée « $1 » pour le paramètre d’alignement. Les valeurs valides sont « left » (gauche), « center » (centre), « right » (droite) ou « inline » (en ligne).",
"embedvideo-error-alignment": "« EmbedVideo » a reçu une valeur une valeur erronée « $1 » pour le paramètre d’alignement. Les valeurs valides sont « left » (gauche), « center » (centre), ou « right » (droite).",
"embedvideo-error-valignment": "« EmbedVideo » a reçu une valeur une valeur erronée « $1 » pour le paramètre d’alignement vertical. Les valeurs valides sont « top » (haut), « middle » (milieu), « bottom » (bas) ou « baseline » (ligne de base).",
"embedvideo-error-urlargs": "« EmbedVideo » a reçu une liste d’arguments d’URL qui contiennent des données malformées ou des arguments vides.",
"embedvideo-error-unknown": "« EmbedVideo » a rencontré une erreur inconnue en essayant de générer ce bloc d’intégration vidéo. ($1)",
Expand Down
32 changes: 25 additions & 7 deletions includes/EmbedService/EmbedHtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ public static function toHtml( AbstractEmbedService $service, array $config = []
}
}

$iframeConfig = '';
try {
$consent = MediaWikiServices::getInstance()
->getConfigFactory()
->makeConfig( 'EmbedVideo' )
->get( 'EmbedVideoRequireConsent' );
if ( $consent === true ) {
$attributes = $service->getIframeAttributes();
$attributes['width'] = $service->getWidth();
$attributes['height'] = $service->getHeight();
$attributes['src'] = $service->getUrl();
$iframeConfig = sprintf(
"data-iframeconfig='%s'",
json_encode( $attributes, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES )
);
}
} catch ( JsonException | ConfigException $e ) {
//
}

/**
* TODO: Sync syntax with core image syntax
* @see: https://www.mediawiki.org/wiki/Help:Images
Expand All @@ -83,7 +103,7 @@ public static function toHtml( AbstractEmbedService $service, array $config = []
* @see https://www.mediawiki.org/wiki/Specs/HTML/2.7.0#Audio/Video
*/
$template = <<<HTML
<figure class="%s" data-service="%s" %s><!--
<figure class="%s" data-service="%s" %s %s><!--
--><span class="embedvideo-wrapper" %s>%s%s</span>%s
</figure>
HTML;
Expand All @@ -92,6 +112,7 @@ public static function toHtml( AbstractEmbedService $service, array $config = []
$template,
$config['class'] ?? '',
$config['service'] ?? '',
$iframeConfig,
$inlineStyles['container'],
$inlineStyles['wrapper'],
( $config['withConsent'] ?? false ) === true ? self::makeConsentContainerHtml( $service ) : '',
Expand Down Expand Up @@ -127,13 +148,10 @@ public static function makeIframe( AbstractEmbedService $service ): string {
->makeConfig( 'EmbedVideo' )
->get( 'EmbedVideoRequireConsent' );
if ( $consent === true ) {
$attributes['src'] = $service->getUrl();
return sprintf(
'<div data-iframeconfig=\'%s\'></div>',
json_encode( $attributes, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES )
);
// Iframe is created through JS
return '';
}
} catch ( JsonException | ConfigException $e ) {
} catch ( ConfigException $e ) {
//
}

Expand Down
4 changes: 3 additions & 1 deletion includes/EmbedVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ private function setContainer( $container ): bool {
private function setAlignment( $alignment ): bool {
if ( !empty( $alignment ) && in_array( $alignment, [ 'left', 'right', 'center', 'none' ], true ) ) {
$this->alignment = $alignment;
} elseif ( !empty( $alignment ) ) {
} elseif ( !empty( $alignment ) && $alignment !== 'inline' ) {
// 'inline' is removed since v3.2.3, but kept for backwards compatibility
// TODO: Remove check after some releases
return false;
}

Expand Down
11 changes: 6 additions & 5 deletions resources/ext.embedVideo.consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
};

mw.hook( 'wikipage.content' ).add( () => {
document.querySelectorAll('.embedvideo-wrapper').forEach(function (wrapper) {
document.querySelectorAll('.embedvideo').forEach(function (ev) {
const wrapper = ev.querySelector('.embedvideo-wrapper');

const makeIframe = function (event) {
wrapper.removeChild(iframeConfigEl);
const iframe = document.createElement('iframe');

for (const [key, value] of Object.entries(iframeConfig)) {
Expand All @@ -115,13 +116,13 @@

/** @type HTMLDivElement|null */
const consentDiv = wrapper.querySelector('.embedvideo-consent');
const iframeConfigEl = wrapper.querySelector('[data-iframeconfig]');
let iframeConfig = ev.dataset.iframeconfig;

if (consentDiv === null || iframeConfigEl === null) {
if (consentDiv === null || iframeConfig === null) {
return;
}

const iframeConfig = JSON.parse(iframeConfigEl.dataset.iframeconfig);
iframeConfig = JSON.parse(iframeConfig);

const loader = consentDiv.querySelector('.embedvideo-loader');
const privacyNotice = consentDiv.querySelector('.embedvideo-privacyNotice');
Expand Down

0 comments on commit 0dbdd9a

Please sign in to comment.