Module:GregCitation
From BIONICLEsector01
Documentation for this module may be created at Module:GregCitation/doc
local bionicleStoryWebsiteCitation = require("Module:BionicleStoryWebsiteCitation")
local bionicleWebsiteCitation = require("Module:BionicleWebsiteCitation")
local bzpowerCitation = require("Module:BZPowerCitation")
local forumCitation = require("Module:ForumCitation")
local websiteCitation = require("Module:WebsiteCitation")
local p = {}
-- Note that NICKNAME_TO_FUNCTIONS_MAP is defined further below, after the
-- functions it depends upon.
--------------------------------------------------------------------------------
------------------------- FORUMS (OGD, FFo, OGDi, OGQ, CwGF) ------------------------
--------------------------------------------------------------------------------
-- Gather the arguments necessary to produce a citation for a post in a forum,
-- and then call the given function with those arguments to build the citation.
-- Assumes that frame and getCitationFunction are not nil.
local function gatherForumArguments(frame, getCitationFunction)
local pageNumber = frame.args["page"]
local postId = frame.args["post"]
local lineNumbers = frame.args["lines"]
if lineNumbers == "" then
lineNumbers = nil
end
assert(pageNumber ~= nil,
[[GregCitation received no page number;
all GregCitations citing a forum must have a page
number specified through the `page` parameter]])
assert(postId ~= nil,
[[GregCitation received no post id;
all GregCitations citing a forum must have a post
id specified through the `post` parameter]])
return getCitationFunction(pageNumber, postId, lineNumbers)
end
-- Build and return the desired Official Greg Discussion citation.
-- Asserts that pageNumber and postId are not nil.
function p.getOfficialGregDiscussionCitation(pageNumber, postId, lineNumbers)
assert(pageNumber ~= nil)
assert(postId ~= nil)
local pageTitle = "Official Greg Discussion"
local archiveUrl = "http://greg.thegreatarchives.com/2003-2008/page" .. pageNumber .. "#post" .. postId
if lineNumbers ~= nil then
archiveUrl = archiveUrl .. "-line" .. lineNumbers
end
return bzpowerCitation.getBZPowerForumCitation(pageTitle, nil, archiveUrl, nil, postId)
end
-- Build and return the desired Farshtey Forum citation.
-- Asserts that pageNumber and postId are not nil.
function p.getFarshteyForumCitation(pageNumber, postId, lineNumbers)
assert(pageNumber ~= nil)
assert(postId ~= nil)
local websiteTitle = "Mask Of Destiny"
local topicTitle = "Farshtey Forum"
local archiveUrl = "https://greg.thegreatarchives.com/mod-2007-2008/page" .. pageNumber .. "#post" .. postId
if lineNumbers ~= nil then
archiveUrl = archiveUrl .. "-line" .. lineNumbers
end
return forumCitation.getForumCitation(websiteTitle, topicTitle, nil, archiveUrl, nil, postId)
end
-- Build and return the desired Official Greg Dialogue citation.
-- Asserts that pageNumber and postId are not nil.
function p.getOfficialGregDialogueCitation(pageNumber, postId, lineNumbers)
assert(pageNumber ~= nil)
assert(postId ~= nil)
local pageTitle = "Official Greg Dialogue"
local archiveUrl = "http://greg.thegreatarchives.com/2008-2010/page" .. pageNumber .. "#post" .. postId
if lineNumbers ~= nil then
archiveUrl = archiveUrl .. "-line" .. lineNumbers
end
return bzpowerCitation.getBZPowerForumCitation(pageTitle, nil, archiveUrl, nil, postId)
end
-- Build and return the desired Official Greg Quotes citation.
-- Asserts that pageNumber and postId are not nil.
function p.getOfficialGregQuotesCitation(pageNumber, postId, lineNumbers)
assert(pageNumber ~= nil)
assert(postId ~= nil)
local pageTitle = "Official Greg Quotes"
local archiveUrl = "http://greg.thegreatarchives.com/2010-2011/page" .. pageNumber .. "#post" .. postId
if lineNumbers ~= nil then
archiveUrl = archiveUrl .. "-line" .. lineNumbers
end
return bzpowerCitation.getBZPowerForumCitation(pageTitle, nil, archiveUrl, nil, postId)
end
-- Build and return the desired Chat with Greg Farshtey citation.
-- Asserts that pageNumber and postId are not nil.
function p.getChatWithGregFarshteyCitation(pageNumber, postId, lineNumbers)
assert(pageNumber ~= nil)
assert(postId ~= nil)
local websiteTitle = "LEGO Message Boards"
local topicTitle = "Chat with Greg Farshtey"
local archiveUrl = "http://greg.thegreatarchives.com/2013-2017/page" .. pageNumber .. "#post" .. postId
if lineNumbers ~= nil then
archiveUrl = archiveUrl .. "-line" .. lineNumbers
end
return forumCitation.getForumCitation(websiteTitle, topicTitle, nil, archiveUrl, nil, postId)
end
--------------------------------------------------------------------------------
------------------------------ FARSHTEY FEED (FF) ------------------------------
--------------------------------------------------------------------------------
-- Gather the arguments necessary to produce a citation for a Farshtey Feed
-- entry, and then call the given function with those arguments to build the
-- citation. Assumes that frame and getCitationFunction are not nil.
local function gatherFarshteyFeedArguments(frame, getCitationFunction)
local entryDate = frame.args["date"]
local itemNumber = frame.args["item"]
if itemNumber == "" then
itemNumber = nil
end
assert(entryDate ~= nil,
[[GregCitation received no date;
all GregCitations citing a Farshtey Feed entry must have a date
specified through the `date` parameter]])
return getCitationFunction(entryDate, itemNumber)
end
-- Build and return the desired Farshtey Feed citation.
-- Asserts that date is not nil.
function p.getFarshteyFeedCitation(entryDate, itemNumber)
assert(entryDate ~= nil)
local pageTitle = "Farshtey Feed, " .. entryDate
local archiveUrl = "https://greg.thegreatarchives.com/farshtey-feed/" .. entryDate
if itemNumber ~= nil then
archiveUrl = archiveUrl .. "#item" .. itemNumber
end
return bzpowerCitation.getBZPowerBlogCitation(pageTitle, nil, archiveUrl, nil, nil)
end
--------------------------------------------------------------------------------
----------------------------- ASK GREG (AG04, AG07) ----------------------------
--------------------------------------------------------------------------------
-- Gather the arguments necessary to produce a citation for some other
-- archived page (specifically, one of the Ask Greg pages),
-- and then call the given function with those arguments to build the
-- citation. Assumes that frame and getCitationFunction are not nil.
local function gatherAskGregArguments(frame, getCitationFunction)
-- There's no need to gather any more parameters!
return getCitationFunction()
end
-- Build and return the desired Ask Greg 2004 citation.
-- Note that the archive link does not point to the actual interview, since
-- The Great Archives is not aware of any archive link.
-- Instead, the link points to a page explaining that fact.
function p.getAskGreg2004Citation()
local mainLinkText = "Ask Greg (2004)"
local brokenUrl = "https://greg.thegreatarchives.com/sources"
return bionicleWebsiteCitation.getBionicleWebsiteCitation(mainLinkText, nil, brokenUrl)
end
-- Build and return the desired Ask Greg 2007 citation.
function p.getAskGreg2007Citation()
local mainLinkText = "Ask Greg (2007)"
local archiveUrl = "http://biomediaproject.com/bmp/data/sites/bioniclestory/2007-2/Launcher.html"
return bionicleStoryWebsiteCitation.getBionicleStoryWebsiteCitation(mainLinkText, archiveUrl, nil)
end
--------------------------------------------------------------------------------
------------------------------- DATA (CONTINUED) -------------------------------
--------------------------------------------------------------------------------
-- A mapping from each source's nickname to relevant functions to call for that
-- source:
-- the function to call to gather its arguments from Template:GregCitation, and
-- the function to call to generate the final citation.
-- Because Lua discovers data top-to-bottom, this table is placed below
-- the functions that it mentions.
NICKNAME_TO_FUNCTIONS_MAP = {
["OGD"] = {
["gatherArgumentsFunction"] = gatherForumArguments,
["getCitationFunction"] = p.getOfficialGregDiscussionCitation
},
["FFo"] = {
["gatherArgumentsFunction"] = gatherForumArguments,
["getCitationFunction"] = p.getFarshteyForumCitation
},
["OGDi"] = {
["gatherArgumentsFunction"] = gatherForumArguments,
["getCitationFunction"] = p.getOfficialGregDialogueCitation
},
["OGQ"] = {
["gatherArgumentsFunction"] = gatherForumArguments,
["getCitationFunction"] = p.getOfficialGregQuotesCitation
},
["CwGF"] = {
["gatherArgumentsFunction"] = gatherForumArguments,
["getCitationFunction"] = p.getChatWithGregFarshteyCitation
},
["FF"] = {
["gatherArgumentsFunction"] = gatherFarshteyFeedArguments,
["getCitationFunction"] = p.getFarshteyFeedCitation
},
["AG04"] = {
["gatherArgumentsFunction"] = gatherAskGregArguments,
["getCitationFunction"] = p.getAskGreg2004Citation
},
["AG07"] = {
["gatherArgumentsFunction"] = gatherAskGregArguments,
["getCitationFunction"] = p.getAskGreg2007Citation
}
}
--------------------------------------------------------------------------------
------------------------------ TEMPLATE INTERFACE ------------------------------
--------------------------------------------------------------------------------
-- Return a string containing all the valid nicknames, separated by spaces.
-- Useful for error messages.
local function getNicknameListString()
local nicknameListString = "{ "
for nickname, _ in pairs(NICKNAME_TO_FUNCTIONS_MAP) do
nicknameListString = nicknameListString .. nickname .. " "
end
nicknameListString = nicknameListString .. "}"
return nicknameListString
end
-- Pull out the relevant args for use.
function p.gregCitation(frame)
local nickname = frame.args[1]
assert(NICKNAME_TO_FUNCTIONS_MAP[nickname] ~= nil,
[[GregCitation received an invalid nickname (first argument);
all GregCitations must have the first parameter set to one of the
values in ]] .. getNicknameListString())
local gatherArgumentsFunction = NICKNAME_TO_FUNCTIONS_MAP[nickname]["gatherArgumentsFunction"]
local getCitationFunction = NICKNAME_TO_FUNCTIONS_MAP[nickname]["getCitationFunction"]
return gatherArgumentsFunction(frame, getCitationFunction)
end
return p