Yurik has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/326906 )
Change subject: Reindex tabular data array for easier lua access
......................................................................
Reindex tabular data array for easier lua access
Bug: T152809
Change-Id: I5262edc279cd7737623e721faed968fa43b170b6
---
M includes/JCLuaLibrary.php
1 file changed, 14 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/JsonConfig
refs/changes/06/326906/1
diff --git a/includes/JCLuaLibrary.php b/includes/JCLuaLibrary.php
index 1bc5ee6..5b6f0e3 100644
--- a/includes/JCLuaLibrary.php
+++ b/includes/JCLuaLibrary.php
@@ -72,6 +72,20 @@
} else {
/** @var JCDataContent $content */
$result = $content->getLocalizedData( $language );
+
+ if ( $content instanceof JCTabularContent ) {
+ // Tabular data should be Lua-reindexed for
easier processing
+ $columns = count( $result->schema->fields );
+ if ( $columns > 0 ) {
+ $rowIndexes = range( 1, $columns );
+ $result->schema->fields =
array_combine( $rowIndexes, $result->schema->fields );
+ $result->data =
+ array_combine( range( 1, count(
$result ) ),
+ array_map( function (
$row ) use ( $rowIndexes ) {
+ return
array_combine( $rowIndexes, $row );
+ }, $result->data ) );
+ }
+ }
}
return [ $result ];
--
To view, visit https://gerrit.wikimedia.org/r/326906
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5262edc279cd7737623e721faed968fa43b170b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits