Final Fantasy Wiki
Advertisement

A documentação para este módulo pode ser criada em Módulo:Refs/doc

p = {}

local getArgs = require('Dev:Arguments').getArgs
local userError = require('Dev:User error')

local errorcatname = "Articles with incomplete citations"

function p.refwebsite(frame)
    
    local args = getArgs(frame)

    local pageurl = args["page url"]
    local siteurl = args["site url"]

    local pagename = args["page name"] or "?"
    local sitename = args["site name"] or "?"

    local accesstime = args["access time"]
    
    local screenshot = args["screenshot"]

    pagename = mw.text.nowiki(pagename)
    sitename = mw.text.nowiki(sitename)

    local pagelink
    local sitelink
    
    if pageurl then
        pagelink = "[" .. pageurl .. " " .. pagename .. "]"
    else
        pagelink = pagename .. userError("Missing page URL", errorcatname)
    end

    if siteurl then
        sitelink = "[" .. siteurl .. " " .. sitename .. "]"
    else
        sitelink = sitename .. userError("Missing site URL", errorcatname)
    end
    
    local lang = mw.language.getContentLanguage()
    
    local accessdate = lang:formatDate("F d, Y", accesstime)
    local accesstimestamp = lang:formatDate("YmdHis", accesstime)
    
    local accesslink = ""
    
    if screenshot then
        if screenshot:sub(1, 4) == "http" then
            if screenshot:find("finalfantasy/images") then
                if accesstime then
                    accesslink = "[" .. screenshot .. " Accessed: " .. accessdate .. "]"
                else
                    accesslink = "[" .. screenshot .. " Accessed: Unknown]" .. userError("Missing date screenshot taken in <code>access time</code> field", errorcatname)
                end
            else
                accesslink = userError("Screenshot must be hosted on site", errorcatname)
            end
        else
            local image = require "Module:Image"
            local foot = require "Module:Foot"
            local sshotdata = image.new(screenshot)
            sshotdata:setSize(200, 150):setCaption(pagename)

            if accesstime then
                accesslink = tostring(foot.render({
                    text = "[[:" .. sshotdata:getPagename() .. "|Accessed: " .. accessdate .. "]]",
                    tip = tostring(sshotdata)
                }))
            else
                accesslink = tostring(foot.render({
                    text = "[[:" .. sshotdata:getPagename() .. "|Accessed: Unknown]]" .. userError("Missing date screenshot taken in <code>access time</code> field", errorcatname),
                    tip = tostring(sshotdata)
                }))
            end
        end
    elseif pageurl then
        if accesstime then
            accesslink = "[https://web.archive.org/web/" .. accesstimestamp .. "/" .. pageurl .. " Accessed: " .. accessdate .. "]"
        else
            accesslink = "[https://web.archive.org/save/" .. pageurl .. " Accessed: Unknown]" .. userError("See [[Project:Citations and Sources#Website|this]] for how to archive", errorcatname)
        end
    end
    
    return pagelink .. " <small>(" .. accesslink .. ")</small> at " .. sitelink
end

return p
Advertisement