mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +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\PortableInfoboxDataBag;
|
||||
use WikiaFileHelper;
|
||||
|
||||
class NodeImage extends Node {
|
||||
const ALT_TAG_NAME = 'alt';
|
||||
const CAPTION_TAG_NAME = 'caption';
|
||||
const MEDIA_TYPE_VIDEO = 'VIDEO';
|
||||
|
||||
public function getData() {
|
||||
if ( !isset( $this->data ) ) {
|
||||
|
@ -17,6 +19,7 @@ class NodeImage extends Node {
|
|||
}
|
||||
|
||||
$title = $this->getImageAsTitleObject( $imageData );
|
||||
$file = $this->getFilefromTitle( $title );
|
||||
$this->getExternalParser()->addImage( $title ? $title->getDBkey() : $imageData );
|
||||
$ref = null;
|
||||
$alt = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
|
||||
|
@ -25,13 +28,17 @@ class NodeImage extends Node {
|
|||
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $title, &$ref, $alt ] );
|
||||
|
||||
$this->data = [
|
||||
'url' => $this->resolveImageUrl( $title ),
|
||||
'url' => $this->resolveImageUrl( $file ),
|
||||
'name' => ( $title ) ? $title->getText() : '',
|
||||
'key' => ( $title ) ? $title->getDBKey() : '',
|
||||
'alt' => $alt,
|
||||
'caption' => $caption,
|
||||
'ref' => $ref
|
||||
];
|
||||
|
||||
if ( $this->isVideo( $file ) ) {
|
||||
$this->data = $this->videoDataDecorator( $this->data, $file );
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
|
@ -67,21 +74,43 @@ class NodeImage extends Node {
|
|||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc get file object from title object
|
||||
* @param Title|null $title
|
||||
* @return File|null
|
||||
*/
|
||||
private function getFilefromTitle( $title ) {
|
||||
return $title ? WikiaFileHelper::getFileFromTitle( $title ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc returns image url for given image title
|
||||
*
|
||||
* @param string $title
|
||||
*
|
||||
* @param File|null $file
|
||||
* @return string url or '' if image doesn't exist
|
||||
*/
|
||||
public function resolveImageUrl( $title ) {
|
||||
if ( $title ) {
|
||||
$file = \WikiaFileHelper::getFileFromTitle( $title );
|
||||
if ( $file ) {
|
||||
return $file->getUrl();
|
||||
}
|
||||
}
|
||||
public function resolveImageUrl( $file ) {
|
||||
return $file ? $file->getUrl() : '';
|
||||
}
|
||||
|
||||
return '';
|
||||
/**
|
||||
* @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