getinnerXML

This commit is contained in:
jacek 2015-05-08 16:56:44 +02:00
parent 748518f8a1
commit 2a9d0193ea
4 changed files with 14 additions and 4 deletions

View file

@ -50,6 +50,11 @@ class Node {
return !( isset( $data[ 'value' ] ) ) || empty( $data[ 'value' ] );
}
protected function getInnerXML( \SimpleXMLElement $node ) {
$tag = $node->getName();
return preg_replace( '!<'. $tag .'(?:[^>]*)>(.*)</'. $tag .'>!Ums', '$1', $node->asXml() );
}
protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) {
$source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME );
$value = null;
@ -58,7 +63,12 @@ class Node {
}
if ( !$value ) {
if ( $xmlNode->{self::DEFAULT_TAG_NAME} ) {
$value = (string)$xmlNode->{self::DEFAULT_TAG_NAME};
/*
* <default> tag can contain <ref> or other WikiText parser hooks
* We should not parse it's contents as XML but return pure text in order to let MediaWiki Parser
* parse it.
*/
$value = $this->getInnerXML( $xmlNode->{self::DEFAULT_TAG_NAME} );
$value = $this->getExternalParser()->parseRecursive( $value );
}
}

View file

@ -5,7 +5,7 @@ class NodeData extends Node {
public function getData() {
return [
'label' => $this->getExternalParser()->parseRecursive( (string) $this->xmlNode->{self::LABEL_TAG_NAME} ),
'label' => $this->getExternalParser()->parseRecursive( $this->getInnerXML( $this->xmlNode->{self::LABEL_TAG_NAME} ) ),
'value' => $this->getValueWithDefault( $this->xmlNode )
];
}

View file

@ -4,7 +4,7 @@ namespace Wikia\PortableInfobox\Parser\Nodes;
class NodeFooter extends Node {
public function getData() {
return [ 'value' => $this->getExternalParser()->parseRecursive( (string)$this->xmlNode ) ];
return [ 'value' => $this->getExternalParser()->parseRecursive( $this->getInnerXML( $this->xmlNode ) ) ];
}
public function isEmpty( $data ) {

View file

@ -4,6 +4,6 @@ namespace Wikia\PortableInfobox\Parser\Nodes;
class NodeHeader extends Node {
public function getData() {
return [ 'value' => $this->getExternalParser()->parseRecursive( (string)$this->xmlNode ) ];
return [ 'value' => $this->getExternalParser()->parseRecursive( $this->getInnerXML( $this->xmlNode ) ) ];
}
}