mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
XW-2415 | handle groups when format=xml
This commit is contained in:
parent
80a9500997
commit
cefbe11d71
|
@ -40,13 +40,40 @@ class ApiQueryPortableInfobox extends ApiQueryBase {
|
|||
$infobox['parser_tag_version']
|
||||
);
|
||||
|
||||
// FIXME ?format=xml throws error
|
||||
$pageSet->getResult()->setIndexedTagName( $infobox['metadata'], 'metadata' );
|
||||
$metadata = $infobox['metadata'];
|
||||
|
||||
$pageSet->getResult()->addValue(
|
||||
[ 'query', 'pages', $id, 'infoboxes', $count ], 'metadata', $infobox['metadata']
|
||||
[ 'query', 'pages', $id, 'infoboxes', $count ], 'metadata', $metadata
|
||||
);
|
||||
$pageSet->getResult()->setIndexedTagName_internal(
|
||||
[ 'query', 'pages', $id, 'infoboxes', $count, 'metadata' ],
|
||||
'metadata'
|
||||
);
|
||||
$this->setIndexedTagNamesForGroupMetadata(
|
||||
$metadata,
|
||||
[ 'query', 'pages', $id, 'infoboxes', $count, 'metadata' ],
|
||||
$pageSet->getResult()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XML format requires all indexed arrays to have _element defined
|
||||
* This method adds it recursively for all groups
|
||||
*
|
||||
* @param array $metadata
|
||||
* @param array $rootPath
|
||||
* @param ApiResult $result
|
||||
*/
|
||||
private function setIndexedTagNamesForGroupMetadata( array $metadata, array $rootPath, ApiResult $result ) {
|
||||
foreach ( $metadata as $nodeCount => $node ) {
|
||||
if ( $node['type'] === 'group' ) {
|
||||
$path = array_merge( $rootPath, [ $nodeCount, 'metadata' ] );
|
||||
$result->setIndexedTagName_internal( $path, 'metadata' );
|
||||
$this->setIndexedTagNamesForGroupMetadata( $node[ 'metadata' ], $path, $result );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue