Module:Main: Difference between revisions

Content deleted Content added
moved to Template:Tax
refactor to use a shared fallback_pages function
 
(2 intermediate revisions 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.fallback_pages( list )
for key, value in ipairs( list ) do
local p2p = 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
else
 
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' )
else})
 
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 66 ⟶ 56:
local language = frame.args.language
local country = frame.args.country
local page = p1
 
if ( tax_message == '' and country == 'FRUS' ) then
tax_messagepage = mw.title.new( 'FRTemplate:Tax/LinkOnly' )
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 = p2p.fallback_pages({
local p1 = mw.title.new( 'Template:Tax/' .. tax_message .. '/' .. language, -- custom )message
'Template:Tax/' .. country .. '/' .. language, -- special countries e.g. FR/NL
'Template:Tax/Default/' .. language,
'Template:Tax/LinkOnly'
})
end
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
return expanded
 
end