Jackmcbarn has uploaded a new change for review.

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

Change subject: Add frame.argKeys
......................................................................

Add frame.argKeys

Currently, it's impossible to get a list of all provided arguments without
expanding them all. This is problematic, since they often contain
references, and expanding them all results in references being created in
the wrong order. To mitigate this problem, allow modules to list argument
keys without expanding their values. Depends on I63485d24 in core.

Change-Id: I008805cb892fb6c954124727f32063a4cefc0430
---
M engines/LuaCommon/LuaCommon.php
M engines/LuaCommon/lualib/mw.lua
2 files changed, 22 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/08/165108/1

diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php
index a9d6aee..9cfc1e2 100644
--- a/engines/LuaCommon/LuaCommon.php
+++ b/engines/LuaCommon/LuaCommon.php
@@ -92,6 +92,7 @@
                                'loadPHPLibrary',
                                'frameExists',
                                'newChildFrame',
+                               'getArgumentKeys',
                                'getExpandedArgument',
                                'getAllExpandedArguments',
                                'expandTemplate',
@@ -577,6 +578,15 @@
        }
 
        /**
+        * Handler for getArgumentKeys()
+        */
+       function getArgumentKeys( $frameId ) {
+               $frame = $this->getFrameById( $frameId );
+               $this->getInterpreter()->pauseUsageTimer();
+               return array( $frame->getArgumentKeys() );
+       }
+
+       /**
         * Handler for getExpandedArgument()
         */
        function getExpandedArgument( $frameId, $name ) {
diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua
index 06a670c..99c037e 100644
--- a/engines/LuaCommon/lualib/mw.lua
+++ b/engines/LuaCommon/lualib/mw.lua
@@ -130,7 +130,8 @@
        local parentFrameIds = { ... }
        local argCache = {}
        local argNames
-       local args_mt = {}
+       local frame_mt, args_mt = {}, {}
+       local gotArgKeys = false
 
        local function checkSelf( self, method )
                if self ~= frame then
@@ -431,13 +432,22 @@
                return php.getFrameTitle( frameId )
        end
 
+       function frame_mt.__index( t, k )
+               if not gotArgKeys and k == 'argKeys' then
+                       gotArgKeys = true
+                       local argKeys = php.getArgumentKeys( frameId )
+                       t.argKeys = argKeys
+                       return argKeys
+               end
+       end
+
        -- For backwards compat
        function frame:argumentPairs()
                checkSelf( self, 'argumentPairs' )
                return pairs( self.args )
        end
 
-       return frame
+       return setmetatable( frame, frame_mt )
 end
 
 --- Set up a cloned environment for execution of a module chunk, then execute

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I008805cb892fb6c954124727f32063a4cefc0430
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to