Module:External links

There are no reviewed versions of this page, so it may not have been checked for adherence to standards.

Documentation for this module may be created at Module:External links/doc

--require "mw.text"
--require "mw.page"

local bodge = require "Module:mw"

local z = {}

function IMDB(frame, path, text)
    return "[http://www.imdb.com/" .. path .. " " .. text .. "] at the [[Internet Movie Database]]"
end

-- This is used by the {{IMDBname}} template.
function z.IMDBname(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local ID = args.id or args.ID or args[1] or ""
    local Name = args.name or args[2] or config.pagename -- Should have "or mw.page.title.name" instead, but that isn't available yet.
    return IMDB(frame, "name/nm" .. ID, Name)
end

-- This is used by the {{IMDBaward}} template.
function z.IMDBaward(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local ID = args.id or args.ID or args[1] or ""
    local Name = args.award or args.name or args[2] or config.pagename -- Should have "or mw.page.title.name" instead, but that isn't available yet.
    return IMDB(frame, "Sections/Awards/" .. ID, Name)
end

-- This is used by the {{IMDBtitle}} template.
function z.IMDBtitle(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local ID = args.id or args.ID or args[1]
    local section = args.section
    local Title = args.title or args[2] or config.pagename -- Should have "or mw.page.title.name" instead, but that isn't available yet.
    local Description = args.description
    if Description then Description = " " .. Description else Description = "" end
    local Name = "''" .. Title .. "''" .. Description
    if section == "awards" then
        Name = "Awards for " .. Name
    end
    if ID then
        return IMDB(frame, "title/tt" .. ID, Name)
    else
        return IMDB(frame, "Title?" .. mw.url.encode(Title), Name)
    end
end

-- This is used by the {{Allmusic}} template.
function z.Allmusic(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local Class = args.class or args[1] or "artist"
    local ID = args.id or args[2] or ""
    local Tab = args.tab
    if ( Tab ~= nil ) then Tab = "/" .. Tab else Tab = "" end
    local URL = "http://www.allmusic.com/" .. Class .. "/" .. ID .. Tab
    if ( args.pure_url ~= nil ) then return URL end
    
    local Surname = args.last or args.author    
    local Retrieved = args.accessdate
    local Title = args.title or args.label or config.pagename -- Should have "or mw.page.title.name" instead, but that isn't available yet.
    if ( Surname ~= nil ) then 
        local Given = args.first 
        if ( Given ~= nil ) then Given = ", " .. Given else Given = "" end
        Surname = Surname .. Given .. ". "
    else
        Surname = ""
    end
    if ( Title ~= nil ) then Title = " " .. Title else Title = "" end
    if ( Retrieved ~= nil ) then Retrieved = ". Retrieved " .. Retrieved .. "." else Retrieved = "" end
    return Surname .. "[" .. URL .. Title .. "] at [[Allmusic]]" .. Retrieved    
end

-- This is used by the {{dmoz}} template.
function z.dmoz(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local P1 = args[1] or ""
    local P2 = args[2] or config.pagename
    local P3 = args[3]
    if ( nil ~= P3 or "user" ~= P3 ) then
        P1 = P1 or config.pagename
    else
        P1 = "public/profile?editor=" .. (P1 or "")
    end
    return "[http://www.dmoz.org/" .. P1 .. " " .. P2 .. "] at the [[Open Directory Project]]"    
end

-- This is used by the {{citeseerx}} template.
function z.citeseerx(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local ID = args.id or args.doi or args[1] or ""
    local encodedID = mw.url.encode(ID)
    return "[[CiteSeer#CiteSeerX|CiteSeerX]]: [//citeseerx.ist.psu.edu/viewdoc/summary?doi=" .. encodedID .. " " .. ID .. "]"
end

-- This is used by the {{official website}} template.
function z.officialwebsite(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local URL = args.URL or args[1] or "//localhost/"
    local name = args.name or args[2] or "Official website"
    local format = args.format
    local mobileURL = args.mobile
    local text = {}
    if URL:sub(1,5) ~= "http:" and URL:sub(1,6) ~= "https:" then
        URL = "http:" .. URL
    end
    table.insert(text, mw.text.tag({name="span",contents="[" .. URL .. " " .. name .. "]",params={class="official website"}}))
    if format == "flash" then
        table.insert(text, mw.text.tag({name="span",contents=" Requires Adobe Flash Player",params={style="font-size:smaller;"}}))
    end
    if mobileURL then
        if mobileURL:sub(1,5) ~= "http:" and mobileURL:sub(1,6) ~= "https:" then
            mobileURL = "http:" .. mobileURL
        end
        table.insert(text, mw.text.tag({name="span",contents=mobileURL .. " Mobile",params={class="official website"}}))
    end
    return table.concat(text)
end

-- This is used by the {{tv.com}} template.
function z.tvcom(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    
    local ID = args.id or args[1] or ""
    local URL = "http://www.tv.com/show/" .. ID .. "/summary.html"
    if ( args.pure_url ~= nil ) then return URL end
    local Title = args.name or args.title or args[2] or config.pagename -- Should have "or mw.page.title.name" instead, but that isn't available yet.
    if "episode" == args.type then
        Title = " \"" .. Title .. "\""
    else
        Title = " ''" .. Title .. "''"
    end    
    return "[" .. URL .. Title .. "] at [[TV.com]]"
end

return z