2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
|
|
|
namespace Wikia\PortableInfobox\Parser\Nodes;
|
|
|
|
|
|
|
|
class NodeImage extends Node {
|
|
|
|
const ALT_TAG_NAME = 'alt';
|
|
|
|
|
|
|
|
public function getData() {
|
|
|
|
$node = [];
|
2015-05-04 14:43:53 +00:00
|
|
|
|
|
|
|
$imageName = $this->getValueWithDefault( $this->xmlNode );
|
2015-04-27 14:05:31 +00:00
|
|
|
$node['value'] = $this->resolveImageUrl( $imageName );
|
|
|
|
$node['alt'] = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
|
2015-05-04 14:43:53 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
|
2015-05-04 14:43:53 +00:00
|
|
|
public function resolveImageUrl( $filename ) {
|
2015-05-04 15:43:09 +00:00
|
|
|
global $wgContLang;
|
2015-05-04 14:43:53 +00:00
|
|
|
$title = \Title::newFromText( \Wikia\PortableInfobox\Helpers\ImageFilenameSanitizer::getInstance()
|
2015-05-04 15:43:09 +00:00
|
|
|
->sanitizeImageFileName($filename, $wgContLang), NS_FILE );
|
2015-04-27 14:05:31 +00:00
|
|
|
if ( $title && $title->exists() ) {
|
2015-05-04 14:43:53 +00:00
|
|
|
return \WikiaFileHelper::getFileFromTitle( $title )->getUrlGenerator()->url();
|
|
|
|
} else {
|
|
|
|
return "";
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|