Skip to content

Commit f98a408

Browse files
committed
Merge branch 'release/v3.0.6'
2 parents 30863ed + 0f8a0be commit f98a408

File tree

9 files changed

+219
-6
lines changed

9 files changed

+219
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Feature request
3+
about: Request a new feature / enhancement
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
<!--- Provide a general summary of the issue in the Title above -->
11+
12+
## Detailed Description
13+
<!--- Provide a detailed description of the change or addition you are proposing -->
14+
15+
## Context
16+
<!--- Why is this change important to you? How would you use it? -->
17+
<!--- How can it benefit other users? -->
18+
19+
## Possible Implementation
20+
<!--- Not obligatory, but suggest an idea for implementing addition or change -->
21+

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ To specify the start and end timestamps in the media use the start and end param
7878

7979
[[File:Example.mp4|start=2|end=6]]
8080

81-
Additionally a cover image can be set for video files by specifying a `cover=` key.
81+
Additionally, a cover image can be set for video files by specifying a `cover=` key.
8282

8383
[[File:Example.mp4|start=2|end=6|cover=File:LocalFile.png]]
8484

@@ -124,6 +124,23 @@ However, if needed optional arguments may be left blank by not putting anything
124124

125125
* `{{#ev:service|id|||description}}`
126126

127+
Alternatively each parameter can be used in any order as a named parameter. The following parameter are available:
128+
* `id`
129+
* `dimensions`
130+
* `alignment`
131+
* `description`
132+
* `container`
133+
* `urlArgs`
134+
* `autoResize`
135+
* `vAlignment`
136+
* `width`
137+
* `height`
138+
* `cover`
139+
* `title`
140+
141+
**Do note** mixing named and unnamed parameters will require you to add all unnamed parameters (and blanks) in the previously mentioned order.
142+
E.g. using named id and unnamed description `{{#ev:service||||This is the Description|id=abc}}`/ `{{#ev:service|id=abc|||This is the Description}}`
143+
127144
## Examples
128145

129146
### Example #1
@@ -159,6 +176,21 @@ Using the service name as a parser tag
159176

160177
<youtube>https://www.youtube.com/watch?v=eAORm-8b1Eg</youtube>
161178

179+
### Example #5
180+
Using a local file as an embed thumbnail
181+
182+
{{#ev:youtube|pSsYTj9kCHE|thumbnail=File:LocalFile.jpg}}
183+
184+
### Example #6
185+
Using a local file as an embed thumbnail and specifying a title
186+
187+
{{#ev:youtube|pSsYTj9kCHE|cover=File:LocalFile.jpg|title=Title of the Embed}}
188+
189+
### Example #7
190+
Using named parameters
191+
192+
{{#ev:youtube|id=pSsYTj9kCHE|dimensions=320x320}}
193+
162194
## Supported Services
163195

164196
As of version 3.x, EmbedVideo supports embedding video content from the following services:
@@ -176,6 +208,9 @@ As of version 3.x, EmbedVideo supports embedding video content from the followin
176208
| [YouTube](http://www.youtube.com/) | `youtubeplaylist` - Playlists | PLY0KbDiiFYeNgQkjujixr7qD-FS8qecoP | https://www.youtube.com/embed/?listType=playlist&list=PLY0KbDiiFYeNgQkjujixr7qD-FS8qecoP |
177209
| [YouTube](http://www.youtube.com/) | `youtubevideolist` - Video List | pSsYTj9kCHE - urlargs=playlist=pSsYTj9kCHE,pSsYTj9kCHE | https://www.youtube.com/embed/pSsYTj9kCHE?playlist=pSsYTj9kCHE,pSsYTj9kCHE |
178210

211+
### New Services
212+
New services can be requested by using the following [link](https://github.com/StarCitizenWiki/mediawiki-extensions-EmbedVideo/issues/new?assignees=&labels=enhancement&template=embed-service-request.md&title=Embed+Service+Request%3A+Service+Name) or clicking `New Issue`.
213+
179214
# Configuration Settings
180215

181216
| Variable | Default Value | Description |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "starcitizenwiki/embedvideo",
3-
"version": "3.0.5",
3+
"version": "3.0.6",
44
"type": "mediawiki-extension",
55
"description": "Adds a parser function embedding video from popular sources.",
66
"license": "MIT",

extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EmbedVideo",
3-
"version": "3.0.5",
3+
"version": "3.0.6",
44
"author": [
55
"Jim R. Wilson",
66
"Andrew Whitworth",

i18n/zh-hant.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"@metadata": {
3+
"authors": [
4+
"Kly"
5+
]
6+
},
7+
"embedvideo-description": "此分叉版本添加可用於內嵌來自熱門來源的影片之解析功能。",
8+
"embedvideo-consent-text": "點擊載入內容",
9+
"embedvideo-error-missingparams": "EmbedVideo 缺少一個必要的參數。",
10+
"embedvideo-error-service": "EmbedVideo 無法識別影片服務「$1」。",
11+
"embedvideo-error-id": "EmbedVideo 接收到用於服務「$1」的錯誤 ID「$2」。",
12+
"embedvideo-error-width": "EmbedVideo 接收到錯誤的寬度參數「$1」。",
13+
"embedvideo-error-height": "EmbedVideo 接收到錯誤的高度參數「$1」。",
14+
"embedvideo-error-alignment": "給予了 EmbedVideo 調準參數「$1」一個無效的值。有效值為「left」、「center」、「right」、或是「inline」。",
15+
"embedvideo-error-valignment": "給予了 EmbedVideo 直向調準參數「$1」一個無效的值。有效值為「top」、「middle」、「bottom」、或是「baseline」。",
16+
"embedvideo-error-urlargs": "EmbedVideo 接收到包含異常資料或是引數為空白的 URL 引數清單。",
17+
"embedvideo-error-unknown": "EmbedVideo 在嘗試產生影片內嵌區塊時發生未知錯誤。($1)",
18+
"embedvideo-error-evp_deprecated": "#evp 解析函式在 EmbedVideo 2.0 已棄用。請將您的解析函式標籤轉換成 #ev。",
19+
"embedvideo-error-container": "提供給「container」的參數無效。",
20+
"embedvideo-video-long-desc": "$1,編解碼器 $2,長度 $3,$4 x $5 像素,總體 $6",
21+
"embedvideo-audio-long-desc": "$1,編解碼器 $2,長度 $3,總體 $4",
22+
"embedvideo-error-cantdecode_evu": "無法解析來自 $1 的影片",
23+
"apihelp-embedvideo-summary": "取得給予指定參數所產生的影片內嵌代碼。",
24+
"apihelp-embedvideo-param-service": "服務名稱(youtube、twitch、等等)",
25+
"apihelp-embedvideo-param-id": "用於該服務的影片 ID",
26+
"apihelp-embedvideo-param-dimensions": "數字寬度(100)或是寬 x 高(100 x 100)",
27+
"apihelp-embedvideo-param-alignment": "影片調準",
28+
"apihelp-embedvideo-param-description": "影片描述",
29+
"apihelp-embedvideo-param-container": "接受影格,或留下空白",
30+
"apihelp-embedvideo-param-urlargs": "在影片 URL 裡的額外引數(用於部分服務)",
31+
"apihelp-embedvideo-param-autoresize": "自動調整影片大小?(true 或 false)"
32+
}

includes/EmbedService/AbstractEmbedService.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
use Config;
88
use InvalidArgumentException;
9+
use MediaTransformOutput;
910
use MediaWiki\MediaWikiServices;
11+
use RuntimeException;
12+
use ThumbnailImage;
13+
use Title;
1014

1115
abstract class AbstractEmbedService {
1216
/**
@@ -62,6 +66,18 @@ abstract class AbstractEmbedService {
6266
*/
6367
protected $urlArgs = [];
6468

69+
/**
70+
* @var ThumbnailImage|MediaTransformOutput|null
71+
*/
72+
protected $localThumb;
73+
74+
/**
75+
* Local title for this embed
76+
*
77+
* @var string|null
78+
*/
79+
protected $title;
80+
6581
/**
6682
* Config object
6783
*
@@ -331,4 +347,53 @@ public function addIframeAttribute( string $key, $value ): void {
331347
public function getIframeAttributes(): array {
332348
return array_merge( $this->iframeAttributes, $this->additionalIframeAttributes );
333349
}
350+
351+
/**
352+
* Set a local filename to be used as the thumbnail for this embed
353+
*
354+
* @param string $localFileName
355+
* @throws InvalidArgumentException When the local file was not found
356+
* @throws RuntimeException When the local file could not be transformed
357+
*/
358+
public function setLocalThumb( string $localFileName ): void {
359+
$title = Title::newFromText( $localFileName, NS_FILE );
360+
361+
if ( $title !== null && $title->exists() ) {
362+
$coverFile = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
363+
$transform = $coverFile->transform( [ 'width' => $this->getWidth() ] );
364+
365+
if ( $transform === false ) {
366+
throw new RuntimeException( sprintf( 'Could not transform file "%s".', $coverFile->getHashPath() ) );
367+
}
368+
369+
$this->localThumb = $transform;
370+
} else {
371+
throw new InvalidArgumentException( sprintf( 'Local file "%s" not found.', $localFileName ) );
372+
}
373+
}
374+
375+
/**
376+
* @return ThumbnailImage|MediaTransformOutput|null
377+
*/
378+
public function getLocalThumb() {
379+
return $this->localThumb;
380+
}
381+
382+
/**
383+
* This title takes precedence over any external fetching
384+
*
385+
* @param string|null $title
386+
*/
387+
public function setTitle( ?string $title ): void {
388+
if ( ( $title ?? '' ) !== '' ) {
389+
$this->title = $title;
390+
}
391+
}
392+
393+
/**
394+
* @return string|null
395+
*/
396+
public function getTitle(): ?string {
397+
return $this->title;
398+
}
334399
}

includes/EmbedService/EmbedHtmlFormatter.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace MediaWiki\Extension\EmbedVideo\EmbedService;
66

77
use ConfigException;
8+
use Exception;
89
use MediaWiki\Extension\EmbedVideo\OEmbed;
910
use MediaWiki\MediaWikiServices;
1011
use UnexpectedValueException;
@@ -48,4 +49,42 @@ public static function toHtml( AbstractEmbedService $service ): string {
4849

4950
return sprintf( '<iframe %s></iframe>', implode( ' ', $out ) );
5051
}
52+
53+
/**
54+
* Generates the html used for embed thumbnails
55+
*
56+
* @param AbstractEmbedService $service
57+
* @return string The final html (can be empty on error or missing data)
58+
*/
59+
public static function makeThumbHtml( AbstractEmbedService $service ): string {
60+
if ( $service->getLocalThumb() === null ) {
61+
return "";
62+
}
63+
64+
try {
65+
$url = wfExpandUrl( $service->getLocalThumb()->getUrl() );
66+
67+
return <<<HTML
68+
<picture class="embedvideo-consent__thumbnail"><!--
69+
--><img src="{$url}" loading="lazy" class="embedvideo-consent__thumbnail__image" alt="Thumbnail for {$service->getTitle()}"/><!--
70+
--></picture>
71+
HTML;
72+
} catch ( Exception $e ) {
73+
return "";
74+
}
75+
}
76+
77+
/**
78+
* Generates the html used for embed titles
79+
*
80+
* @param AbstractEmbedService $service
81+
* @return string The final html (can be empty on error or missing data)
82+
*/
83+
public static function makeTitleHtml( AbstractEmbedService $service ): string {
84+
if ( $service->getTitle() === null ) {
85+
return "";
86+
}
87+
88+
return sprintf( '<div class="embedvideo-consent__title">%s</div>', $service->getTitle() );
89+
}
5190
}

includes/EmbedVideo.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Message;
1616
use Parser;
1717
use PPFrame;
18+
use RuntimeException;
1819

1920
class EmbedVideo {
2021
/**
@@ -204,6 +205,8 @@ private function parseArgs( array $args, bool $fromTag ): array {
204205
'vAlignment' => '',
205206
'width' => null,
206207
'height' => null,
208+
'cover' => null,
209+
'title' => null,
207210
];
208211

209212
if ( $fromTag === true ) {
@@ -285,6 +288,8 @@ private function init(): void {
285288
'description' => $description,
286289
'urlArgs' => $urlArgs,
287290
'vAlignment' => $vAlignment,
291+
'cover' => $cover,
292+
'title' => $title,
288293
] = $this->args;
289294

290295
// I am not using $parser->parseWidthParam() since it can not handle height only. Example: x100
@@ -327,6 +332,16 @@ private function init(): void {
327332
if ( !$this->setVerticalAlignment( $vAlignment ) ) {
328333
throw new InvalidArgumentException( $this->error( 'valignment', $vAlignment )[0] );
329334
}
335+
336+
if ( !empty( $cover ?? '' ) ) {
337+
try {
338+
$this->service->setLocalThumb( $cover );
339+
} catch ( InvalidArgumentException | RuntimeException $e ) {
340+
wfLogWarning( $e->getMessage() );
341+
}
342+
}
343+
344+
$this->service->setTitle( $title );
330345
}
331346

332347
/**
@@ -407,6 +422,8 @@ private function setVerticalAlignment( $vAlignment ): bool {
407422
* Generate the HTML necessary to embed the video with the given alignment
408423
* and text description
409424
*
425+
* TODO: Move into HtmlFormatter
426+
*
410427
* @private
411428
* @param string [Optional] Horizontal Alignment
412429
* @param string [Optional] Description
@@ -444,9 +461,13 @@ private function generateWrapperHTML( $html, $addClass = null, string $service =
444461

445462
$consentClickContainer = '';
446463
if ( !( $this->service instanceof OEmbedServiceInterface ) && $this->config->get( 'EmbedVideoRequireConsent' ) ) {
464+
$titleHtml = EmbedHtmlFormatter::makeTitleHtml( $this->service );
447465
$consentClickContainer = sprintf(
448-
'<div class="embedvideo-consent"><div class="embedvideo-consent__overlay"><div class="embedvideo-consent__message">%s</div></div></div>',
449-
( new Message( 'embedvideo-consent-text' ) )->text()
466+
'<div class="embedvideo-consent"><div class="embedvideo-consent__overlay%s">%s<div class="embedvideo-consent__message">%s</div></div>%s</div>',
467+
$titleHtml !== '' ? ' embedvideo-consent__overlay--hastitle' : '',
468+
$titleHtml,
469+
( new Message( 'embedvideo-consent-text' ) )->text(),
470+
EmbedHtmlFormatter::makeThumbHtml( $this->service )
450471
);
451472
}
452473

resources/ext.embedVideo.consent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
return result.json();
4343
})
4444
.then(json => {
45-
if (typeof json.thumbnail_url === 'undefined') {
45+
if (typeof json.thumbnail_url === 'undefined' || parent.querySelectorAll('.embedvideo-consent__thumbnail').length > 0) {
4646
return;
4747
}
4848

0 commit comments

Comments
 (0)