add hook to node image

This commit is contained in:
jacek 2015-05-11 14:36:23 +02:00
parent e97750a3bc
commit f32f24689a

View file

@ -8,10 +8,15 @@ class NodeImage extends Node {
public function getData() { public function getData() {
$imageName = $this->getValueWithDefault( $this->xmlNode ); $imageName = $this->getValueWithDefault( $this->xmlNode );
$ref = null;
$alt = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $this->getImageAsTitleObject( $imageName ), &$ref, $alt ] );
return [ return [
'url' => $this->resolveImageUrl( $imageName ), 'url' => $this->resolveImageUrl( $imageName ),
'name' => $imageName, 'name' => $imageName,
'alt' => $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} ) 'alt' => $alt,
'ref' => $ref
]; ];
} }
@ -19,12 +24,17 @@ class NodeImage extends Node {
return !( isset( $data[ 'url' ] ) ) || empty( $data[ 'url' ] ); return !( isset( $data[ 'url' ] ) ) || empty( $data[ 'url' ] );
} }
public function resolveImageUrl( $filename ) { private function getImageAsTitleObject( $imageName ) {
global $wgContLang; global $wgContLang;
$title = \Title::newFromText( $title = \Title::newFromText(
ImageFilenameSanitizer::getInstance()->sanitizeImageFileName( $filename, $wgContLang ), ImageFilenameSanitizer::getInstance()->sanitizeImageFileName( $imageName, $wgContLang ),
NS_FILE NS_FILE
); );
return $title;
}
public function resolveImageUrl( $filename ) {
$title = $this->getImageAsTitleObject( $filename );
if ( $title && $title->exists() ) { if ( $title && $title->exists() ) {
return \WikiaFileHelper::getFileFromTitle( $title )->getUrlGenerator()->url(); return \WikiaFileHelper::getFileFromTitle( $title )->getUrlGenerator()->url();
} else { } else {