Jens Ohlig has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/96232


Change subject: (Bug 54324) Sequences in Lua should start with 1
......................................................................

(Bug 54324) Sequences in Lua should start with 1

Change-Id: I26c2526cc6258c18ccd83c6e1404eb9269802178
---
M client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
1 file changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/32/96232/1

diff --git 
a/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php 
b/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
index 077f4c7..8644699 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseLibraryImplementation.php
@@ -45,6 +45,25 @@
                $this->siteLinkTable = $siteLinkTable;
        }
 
+       /**
+        * Recursively renumber a serialized array in place, so it is indexed 
at 1, not 0.
+        * Just like Lua wants it.
+        *
+        * @since 0.5
+        *
+        * @param array &$entityArr
+        */
+       public function renumber( &$entityArr ) {
+               foreach( $entityArr as $key => &$value ) {
+                       if ( is_array( $value ) ) {
+                               if ( array_key_exists( 0, $value ) ) {
+                                       $value = array_combine( range( 1, 
count( $value ) ), array_values( $value ) );
+                               }
+                               $this->renumber( $value );
+                       }
+               }
+       }
+
 
        /**
         * Get entity from prefixed ID (e.g. "Q23") and return it as serialized 
array.
@@ -94,6 +113,8 @@
                $serializer = $serializerFactory->newSerializerForObject( 
$entityObject, $opt );
 
                $entityArr = $serializer->getSerialized( $entityObject );
+               $this->renumber( $entityArr ); // Renumber the array
+
                return array( $entityArr );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/96232
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26c2526cc6258c18ccd83c6e1404eb9269802178
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jens Ohlig <jens.oh...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to