mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
getinnerXML
This commit is contained in:
parent
748518f8a1
commit
2a9d0193ea
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 ) ) ];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue