Module:TTVCitation
From BIONICLEsector01
Documentation for this module may be created at Module:TTVCitation/doc
local forumCitation = require("Module:ForumCitation")
local p = {}
-- The title of The TTV Message Boards as it should appear in the desired citation.
local WEBSITE_TITLE = "The TTV Message Boards"
-- Return the forum post id gleaned from the given URL, or nil if none is found.
-- Assumes that mainUrl is not nil.
local function getPostId(mainUrl)
return string.match(mainUrl, "t/%d+/(%d+)")
end
-- Build and return the desired TTV citation.
-- Asserts that topicTitle is are not nil
-- and that at least one of originalUrl, archiveUrl, or brokenUrl are not nil.
function p.getTTVCitation(topicTitle, originalUrl, archiveUrl, brokenUrl, postId)
assert(topicTitle ~= nil)
assert(originalUrl ~= nil or archiveUrl ~= nil or brokenUrl ~= nil)
return forumCitation.getForumCitation(WEBSITE_TITLE, topicTitle, originalUrl, archiveUrl, brokenUrl, postId)
end
-- Pull out the relevant args for use.
function p.ttvCitation(frame)
local topicTitle = frame.args["pagetitle"]
local originalUrl = frame.args["originalurl"]
if originalUrl == "" then
originalUrl = nil
end
local archiveUrl = frame.args["archiveurl"]
if archiveUrl == "" then
archiveUrl = nil
end
local brokenUrl = frame.args["brokenurl"]
if brokenUrl == "" then
brokenUrl = nil
end
assert(topicTitle ~= nil,
[[TTVCitation received no page title;
all TTVCitations must have a title specified
through the `pagetitle` parameter]])
assert(originalUrl ~= nil or archiveUrl ~= nil or brokenUrl ~= nil,
[[TTVCitation received no topic URL;
all TTVCitations must have a URL specified through
at least one of the following parameters:
`originalurl`, `archiveurl`, or `brokenurl`]])
local postId = getPostId(originalUrl or archiveUrl or brokenUrl)
return p.getTTVCitation(topicTitle, originalUrl, archiveUrl, brokenUrl, postId)
end
return p