Module:Main: Difference between revisions

Content deleted Content added
new tax message function
refactor to use a shared fallback_pages function
 
(One intermediate revision by the same user not shown)
Line 2:
 
local p = {} -- p stands for package
 
-- Given an array of titles as strings, check them in order and return the first page which exists
function p.get_tax_messagefallback_pages( framelist )
for key, value in ipairs( list ) do
local p4p = mw.title.new( 'Template:Tax/LinkOnly'value )
if p1p.exists then
return p
end
end
end
 
function p.get_appeal( frame )
Line 8 ⟶ 18:
local language = frame.args.language
local country = frame.args.country
 
local p1page = mwp.title.newfallback_pages({
'Template:Appeal/' .. appeal_name .. '/' .. language .. '/' .. country ),
local p2 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language ),
local p3 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/en' ),
local p4 = mw.title.new( 'Template:Appeal/default/' .. language ),
local p5 = mw.title.new( 'Template:Appeal/default/en' )
end})
 
if p1.exists then
page = p1
elseif p2.exists then
page = p2
elseif p3.exists then
page = p3
elseif p4.exists then
page = p4
else
page = p5
end
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
Line 37:
local language = frame.args.language
local country = frame.args.country
end
 
local p1page = mwp.title.newfallback_pages({
'Template:Infobox/' .. infobox_name .. '/' .. language .. '/' .. country ),
local p2 = mw.title.new( 'Template:Infobox/' .. infobox_name .. '/' .. language ),
local p3 = mw.title.new( 'Template:Infobox/' .. infobox_name .. '/en' ),
local p4 = mw.title.new( 'Template:Infobox/Default/' .. language ),
local p5 = mw.title.new( 'Template:Infobox/Default/en' )
end})
 
if p1.exists then
page = p1
elseif p2.exists then
page = p2
elseif p3.exists then
page = p3
elseif p4.exists then
page = p4
else
page = p5
end
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
Line 61 ⟶ 51:
end
 
function p.get_tax_message_newget_tax_message( frame )
-- TODO: Refactor this and others, could just build an array of titles and then pass to
-- another function to do fallback
function p.get_tax_message_new( frame )
 
local tax_message = frame.args.tax_message
local language = frame.args.language
local country = frame.args.country
local page = p1
 
local p1 = mw.title.new( 'Template:Tax/' .. tax_message .. '/' .. language ) -- custom message
local p2 = mw.title.new( 'Template:Tax/' .. country .. '/' .. language ) -- special countries e.g. FR/NL
local p3 = mw.title.new( 'Template:Tax/Default/' .. language )
local p4 = mw.title.new( 'Template:Tax/LinkOnly' )
 
if ( country == 'US' ) then
page = p4mw.title.new( 'Template:Tax/LinkOnly' )
elseif p1.exists then
page = p1
elseif p2.exists then
page = p2
elseif p3.exists then
page = p3
else
page = p4p.fallback_pages({
local p1 = mw.title.new( 'Template:Tax/' .. tax_message .. '/' .. language ), -- custom message
local p2 = mw.title.new( 'Template:Tax/' .. country .. '/' .. language ), -- special countries e.g. FR/NL
local p3 = mw.title.new( 'Template:Tax/Default/' .. language ),
local p2 = mw.title.new( 'Template:Tax/LinkOnly' )
else })
end
 
Line 89 ⟶ 72:
return expanded
end
 
function p.get_tax_message( frame )
 
local tax_message = frame.args.tax_message
local language = frame.args.language
local country = frame.args.country
 
if ( tax_message == '' and country == 'FR' ) then
tax_message = 'FR'
end
if ( tax_message == '' and country == 'ES' ) then
tax_message = 'ES'
end
 
local p1 = mw.title.new( 'Template:Tax/' .. tax_message .. '/' .. language )
local p2 = mw.title.new( 'Template:Tax/LinkOnly' )
 
if p1.exists then
page = p1
else
page = p2
end
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
return expanded
 
end