Add title.content alias for Title::getContent()

No other access in the Title class contains a `get` prefix, so this
makes the title methods consistent.

Bug: T373047
Change-Id: I4a3a7498462b7b3b6143dc61f529e526ccb112e2
This commit is contained in:
C. Scott Ananian 2023-12-14 15:14:12 -05:00
parent 9c4fc5a95c
commit 13b7e5ab31
2 changed files with 19 additions and 0 deletions

View file

@ -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 )

View file

@ -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}}<includeonly>...</includeonly><noinclude>...</noinclude>',
false,
}
},
{ name = '.redirectTarget', func = test_redirectTarget, type = 'ToString',
expect = { 'ScribuntoTestTarget', false, false }
},