From 0763e2229279487bcfd6caefe9c427458fb0a8d5 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 6 Dec 2013 13:10:39 -0500 Subject: [PATCH] Expose PPFrame::getTitle to Lua This field already exists in PHP with exactly the content requested in bug 47089, so we may as well expose it on the frame object. Bug: 47089 Change-Id: I672820589f6ebc7c4daad29b5eb156733a5bc5cc --- engines/LuaCommon/LuaCommon.php | 9 +++++++++ engines/LuaCommon/lualib/mw.lua | 5 +++++ tests/engines/LuaCommon/luaParserTests.txt | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php index 0514c997..f79bd161 100644 --- a/engines/LuaCommon/LuaCommon.php +++ b/engines/LuaCommon/LuaCommon.php @@ -81,6 +81,7 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase { 'preprocess', 'incrementExpensiveFunctionCount', 'isSubsting', + 'getFrameTitle', ); $lib = array(); @@ -401,6 +402,14 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase { return array( $newFrameId ); } + /** + * Handler for getTitle() + */ + function getFrameTitle( $frameId ) { + $frame = $this->getFrameById( $frameId ); + return array( $frame->getTitle()->getPrefixedText() ); + } + /** * Handler for getExpandedArgument() */ diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua index 8d342ef3..f53da201 100644 --- a/engines/LuaCommon/lualib/mw.lua +++ b/engines/LuaCommon/lualib/mw.lua @@ -536,6 +536,11 @@ local function newFrame( frameId, ... ) ) end + function frame:getTitle() + checkSelf( self, 'getTitle' ) + return php.getFrameTitle( frameId ) + end + -- For backwards compat function frame:argumentPairs() checkSelf( self, 'argumentPairs' ) diff --git a/tests/engines/LuaCommon/luaParserTests.txt b/tests/engines/LuaCommon/luaParserTests.txt index f271cf86..6468cf34 100644 --- a/tests/engines/LuaCommon/luaParserTests.txt +++ b/tests/engines/LuaCommon/luaParserTests.txt @@ -137,6 +137,10 @@ function p.isSubsting( frame ) return tostring( mw.isSubsting() ) end +function p.getFrameTitle( frame ) + return frame:getTitle() +end + return p !! endarticle @@ -385,3 +389,12 @@ Scribunto: isSubsting during normal parse

false

!! end + +!! test +Scribunto: frame:getTitle +!! input +{{#invoke:test|getFrameTitle}} +!! result +

Module:Test +

+!! end