From f32f24689af36d60cf59ed67bec56c2fae5269a9 Mon Sep 17 00:00:00 2001 From: jacek Date: Mon, 11 May 2015 14:36:23 +0200 Subject: [PATCH] add hook to node image --- services/Parser/Nodes/NodeImage.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/Parser/Nodes/NodeImage.php b/services/Parser/Nodes/NodeImage.php index 3ca650d..9e5c562 100644 --- a/services/Parser/Nodes/NodeImage.php +++ b/services/Parser/Nodes/NodeImage.php @@ -8,10 +8,15 @@ class NodeImage extends Node { public function getData() { $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 [ 'url' => $this->resolveImageUrl( $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' ] ); } - public function resolveImageUrl( $filename ) { + private function getImageAsTitleObject( $imageName ) { global $wgContLang; $title = \Title::newFromText( - ImageFilenameSanitizer::getInstance()->sanitizeImageFileName( $filename, $wgContLang ), + ImageFilenameSanitizer::getInstance()->sanitizeImageFileName( $imageName, $wgContLang ), NS_FILE ); + return $title; + } + + public function resolveImageUrl( $filename ) { + $title = $this->getImageAsTitleObject( $filename ); if ( $title && $title->exists() ) { return \WikiaFileHelper::getFileFromTitle( $title )->getUrlGenerator()->url(); } else {