mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
add video functionality to image tag
This commit is contained in:
parent
4bfe7cf215
commit
ba0a923fd9
|
@ -3,10 +3,12 @@ namespace Wikia\PortableInfobox\Parser\Nodes;
|
||||||
|
|
||||||
use Wikia\PortableInfobox\Helpers\ImageFilenameSanitizer;
|
use Wikia\PortableInfobox\Helpers\ImageFilenameSanitizer;
|
||||||
use Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag;
|
use Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag;
|
||||||
|
use WikiaFileHelper;
|
||||||
|
|
||||||
class NodeImage extends Node {
|
class NodeImage extends Node {
|
||||||
const ALT_TAG_NAME = 'alt';
|
const ALT_TAG_NAME = 'alt';
|
||||||
const CAPTION_TAG_NAME = 'caption';
|
const CAPTION_TAG_NAME = 'caption';
|
||||||
|
const MEDIA_TYPE_VIDEO = 'VIDEO';
|
||||||
|
|
||||||
public function getData() {
|
public function getData() {
|
||||||
if ( !isset( $this->data ) ) {
|
if ( !isset( $this->data ) ) {
|
||||||
|
@ -17,6 +19,7 @@ class NodeImage extends Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = $this->getImageAsTitleObject( $imageData );
|
$title = $this->getImageAsTitleObject( $imageData );
|
||||||
|
$file = $this->getFilefromTitle( $title );
|
||||||
$this->getExternalParser()->addImage( $title ? $title->getDBkey() : $imageData );
|
$this->getExternalParser()->addImage( $title ? $title->getDBkey() : $imageData );
|
||||||
$ref = null;
|
$ref = null;
|
||||||
$alt = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
|
$alt = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
|
||||||
|
@ -25,13 +28,17 @@ class NodeImage extends Node {
|
||||||
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $title, &$ref, $alt ] );
|
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $title, &$ref, $alt ] );
|
||||||
|
|
||||||
$this->data = [
|
$this->data = [
|
||||||
'url' => $this->resolveImageUrl( $title ),
|
'url' => $this->resolveImageUrl( $file ),
|
||||||
'name' => ( $title ) ? $title->getText() : '',
|
'name' => ( $title ) ? $title->getText() : '',
|
||||||
'key' => ( $title ) ? $title->getDBKey() : '',
|
'key' => ( $title ) ? $title->getDBKey() : '',
|
||||||
'alt' => $alt,
|
'alt' => $alt,
|
||||||
'caption' => $caption,
|
'caption' => $caption,
|
||||||
'ref' => $ref
|
'ref' => $ref
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ( $this->isVideo( $file ) ) {
|
||||||
|
$this->data = $this->videoDataDecorator( $this->data, $file );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
|
@ -68,20 +75,42 @@ class NodeImage extends Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc returns image url for given image title
|
* @desc get file object from title object
|
||||||
*
|
* @param Title|null $title
|
||||||
* @param string $title
|
* @return File|null
|
||||||
*
|
|
||||||
* @return string url or '' if image doesn't exist
|
|
||||||
*/
|
*/
|
||||||
public function resolveImageUrl( $title ) {
|
private function getFilefromTitle( $title ) {
|
||||||
if ( $title ) {
|
return $title ? WikiaFileHelper::getFileFromTitle( $title ) : null;
|
||||||
$file = \WikiaFileHelper::getFileFromTitle( $title );
|
|
||||||
if ( $file ) {
|
|
||||||
return $file->getUrl();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
/**
|
||||||
|
* @desc returns image url for given image title
|
||||||
|
* @param File|null $file
|
||||||
|
* @return string url or '' if image doesn't exist
|
||||||
|
*/
|
||||||
|
public function resolveImageUrl( $file ) {
|
||||||
|
return $file ? $file->getUrl() : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc checks if file media type is VIDEO
|
||||||
|
* @param File|null $file
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isVideo( $file ) {
|
||||||
|
return $file ? $file->getMediaType() === self::MEDIA_TYPE_VIDEO : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc add addtional data required for video media type
|
||||||
|
* @param array $data
|
||||||
|
* @param File $file
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function videoDataDecorator( $data, $file ) {
|
||||||
|
$data['isVideo'] = true;
|
||||||
|
$data['duration'] = WikiaFileHelper::formatDuration( $file->getMetadataDuration());
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue