diff --git a/includes/Engines/LuaCommon/lualib/mw.title.lua b/includes/Engines/LuaCommon/lualib/mw.title.lua index 73918b4d..c5e32641 100644 --- a/includes/Engines/LuaCommon/lualib/mw.title.lua +++ b/includes/Engines/LuaCommon/lualib/mw.title.lua @@ -168,6 +168,7 @@ local function makeTitleObject( data ) end function data:getContent() + -- deprecated: should use `title.content` instead checkSelf( self, 'getContent' ) local content = php.getContent( self.fullText ) data.getContent = function ( self ) @@ -301,6 +302,12 @@ local function makeTitleObject( data ) end return data.redirectTarget end + if k == 'content' then + if data.content == nil then + data.content = php.getContent( data.prefixedText ) or false + end + return data.content + end if k == 'categories' then if data.categories == nil then data.categories = php.getCategories( data.prefixedText ) diff --git a/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua b/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua index 9a815b49..a2003791 100644 --- a/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua +++ b/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua @@ -75,6 +75,11 @@ local function test_getContent() mw.title.new( 'ScribuntoTestNonExistingPage' ):getContent() end +local function test_content() + return mw.title.new( 'ScribuntoTestPage' ).content, + mw.title.new( 'ScribuntoTestNonExistingPage' ).content +end + local function test_redirectTarget() local targets = {} local titles = { @@ -412,6 +417,13 @@ local tests = { } }, + { name = '.content', func = test_content, + expect = { + '{{int:mainpage}}......', + false, + } + }, + { name = '.redirectTarget', func = test_redirectTarget, type = 'ToString', expect = { 'ScribuntoTestTarget', false, false } },