mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
add hook to node image
This commit is contained in:
parent
e97750a3bc
commit
f32f24689a
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue