FANDOM


--<nowiki>
local p = {}
local getArgs = require("Dev:Arguments").getArgs
local userError = require('Dev:User error')
 
-- Show text and a link to a main article or image category.
-- {{#invoke:Link|main|Olga}} for "Main article: [[Olga]]"
-- {{#invoke:Link|main|Olga|images}} for "For a complete list of images..."
function p.main(frame)
    local args = getArgs(frame)
    return p._main(args[1], args[2])
end
 
function p._main(name, pagetype)
    if not pagetype then
        pagetype = ''
    end
    if string.lower(pagetype) == 'images' then
        return p._media(name, nil, nil, 'images')
    else
        return p._article(name)
    end
end
 
-- images: Show text and a link: "For a complete list of images of ..."
-- {{#invoke:Link|images|Olga}}
function p.images(frame)
    local args = getArgs(frame)
    return p._media(args[1], args['preposition'], args['display'],
        'images')
end
 
-- videos: Pretty much the same as images
-- {{#invoke:Link|videos|Underworld}}
function p.videos(frame)
    local args = getArgs(frame)
    return p._media(args[1], args['preposition'], args['display'],
        'videos')
end
 
function p._media(name, preposition, disp, mediatype)
    if not preposition then
        preposition = 'of'
    end
    -- style the name in italics, if preposition == 'from'
    -- for film titles
    if not disp then
        disp = name
    end
    return "''For a complete list of " .. mediatype .. " " ..
        preposition .. " " .. disp .. ", please visit the [[:Category:" ..
        name .. " " .. mediatype .. "|" .. name .. " " .. mediatype ..
        " category]].''"
end
 
-- article: Prints a "main article" link
function p.article(frame)
    local args = getArgs(frame)
    return p._article(args[1])
end
 
function p._article(name)
    if string.sub(string.lower(name), 1, 9) == 'category:' then
        name=string.sub(name, 10)
        return ":''Main category: [[:Category:" .. name .. "|" .. name ..
            "]]''"
    else
        return ":''Main article: [[" .. name .. "]]''"
    end
 
end
 
return p
--</nowiki>