PortableInfobox/services/Parser/Nodes/NodeImage.php
Adam Robak d14e824151 Merge branch 'portable_infobox_mvp' into DAT-2745
Conflicts:
	extensions/wikia/PortableInfobox/services/Parser/Nodes/NodeImage.php
2015-05-07 14:54:23 +02:00

34 lines
879 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() {
return [
'url' => $this->resolveImageUrl( $imageName ),
'name' => $this->getValueWithDefault( $this->xmlNode ),
'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 "";
}
}
}