mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-16 12:35:31 +00:00
35 lines
906 B
PHP
35 lines
906 B
PHP
<?php
|
|
namespace Wikia\PortableInfobox\Parser\Nodes;
|
|
|
|
use Wikia\PortableInfobox\Helpers\ImageFilenameSanitizer;
|
|
|
|
class NodeImage extends Node {
|
|
const ALT_TAG_NAME = 'alt';
|
|
|
|
public function getData() {
|
|
$imageName = $this->getValueWithDefault( $this->xmlNode );
|
|
return [
|
|
'url' => $this->resolveImageUrl( $imageName ),
|
|
'name' => $imageName,
|
|
'alt' => $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} )
|
|
];
|
|
}
|
|
|
|
public function isEmpty( $data ) {
|
|
return !( isset( $data[ 'url' ] ) ) || empty( $data[ 'url' ] );
|
|
}
|
|
|
|
public function resolveImageUrl( $filename ) {
|
|
global $wgContLang;
|
|
$title = \Title::newFromText(
|
|
ImageFilenameSanitizer::getInstance()->sanitizeImageFileName( $filename, $wgContLang ),
|
|
NS_FILE
|
|
);
|
|
if ( $title && $title->exists() ) {
|
|
return \WikiaFileHelper::getFileFromTitle( $title )->getUrlGenerator()->url();
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
}
|