Module:LDSverse: Difference between revisions

Content deleted Content added
m Updated bomBooks table to reflect new WS pages for the Title Page and the testimonies of the 3/8 witnesses
m Protected "Module:LDSverse": request at RfPP ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require autoconfirmed or confirmed access] (indefinite))
 
(7 intermediate revisions by one other user not shown)
Line 3:
 
-- TODO:
-- Check the verse parameter to make sure it's a number (sometimes users
-- Take out the assert statements and handle errors more gracefully?
-- mistakenly include the en dash and ending verse number in this
-- Handle situations where the book name parameter is mistakenly left out (e.g., {{LDS|Alma|7|11}}): if the "bookParam" evaluates to a number, shift all the parameters "down" one (i.e., bookParam->chapterParam, chapterParam->verseParam, etc.) and treat the display text (minus any period or other punctuation) is the bookParam.
-- parameter, e.g., {{LDS|Alma|alma|7|11–12}}). If it isn't a number,
-- default to citing to the chapter as a whole?
-- Take out the remaining error statements and handle errors more gracefully.
-- (As of September 2020, many have already been removed, so that's good.)
-- Functions with error statements left in them:
-- getFullBookName
-- handleOD
-- getStandardWork (only throws an error if pre-conditions not met)
-- getLectureOrdinal (only called with pcall)
 
--[[
Line 26 ⟶ 35:
["Testimony of Three Witnesses"] = {"three", "3witnesses"},
["Testimony of Eight Witnesses"] = {"eight", "8witnesses"},
["1 Nephi"] = {"1-ne", "1_ne", "1ne", "1 ne"},
["2 Nephi"] = {"2-ne", "2_ne", "2ne", "2 ne"},
["Jacob"] = {"jac"},
["Enos"] = {"en"},
Line 36 ⟶ 45:
["Alma"] = {},
["Helaman"] = {"hel"},
["3 Nephi"] = {"3-ne", "3_ne", "3ne", "3 ne"},
["4 Nephi"] = {"4-ne", "4_ne", "4ne", "4 ne"},
["Mormon"] = {"morm", "mormon"},
["Ether"] = {},
Line 58 ⟶ 67:
["JST Matthew"] = {"js-m", "jsm", "joseph smith matthew", "jst matt",
"jst-matt", "jst-matthew", "js matthew"}, -- NB: This is a special case!
["History"] = {"js-h", "jsh", "js history", "joseph smith history", "js-hist"},
"js-hist", "js hist"},
["Articles of Faith"] = {"a-of-f", "a_of_f", "aoff", "the articles of faith"}
}
Line 71 ⟶ 81:
["Judges"] = {"judg", "jgs"},
["Ruth"] = {"ru", "ruth"},
["1 Samuel"] = {"1sam", "1sm", "1_sam", "1-sam", "1 sam"},
["2 Samuel"] = {"2sam", "2sm", "2_sam", "2-sam", "2 sam"},
["1 Kings"] = {"1kgs", "1-kgs", "1_kgs", "1 kgs"},
["2 Kings"] = {"2kgs", "2-kgs", "2_kgs", "2 kgs"},
["1 Chronicles"] = {"1chron", "1chr", "1-chr", "1_chr", "1 chr"},
["2 Chronicles"] = {"2chron", "2chr", "2-chr", "2_chr", "2 chr"},
["Ezra"] = {},
["Nehemiah"] = {"neh"},
Line 103 ⟶ 113:
["Zechariah"] = {"zech", "zec", "zach", "zac"}, -- catch typos
["Malachi"] = {"mal"},
["Matthew"] = {"matt", "mt"}, -- New Testament
["Mark"] = {"mk"},
["Luke"] = {"lk"},
["John"] = {"jn"},
["Acts"] = {"actsoftheapostles", "the acts"}, "acts of the apostles",
"the acts of the apostles"},
["Romans"] = {"rom", "roman"},
["1 Corinthians"] = {"1cor", "1-cor", "1_cor", "1 cor"},
["2 Corinthians"] = {"2cor", "2-cor", "2_cor", "2 cor"},
["Galatians"] = {"gal"},
["Ephesians"] = {"eph"},
Line 116 ⟶ 128:
["Colossians"] = {"col"},
["1 Thessalonians"] = {"1thess", "1thes", "1-thes",
"1_thes", "1-thess", "1_thess", "1 thess", "1 thes"}, -- catch typos
["2 Thessalonians"] = {"2thess", "2thes", "2-thes",
"2_thes", "2-thess", "2_thess", "2 thess", "2 thes"}, -- catch typos
["1 Timothy"] = {"1tim", "1tm", "1-tim", "1_tim", "1 tim"},
["2 Timothy"] = {"2tim", "2tm", "2-tim", "2_tim", "2 tim"},
["Titus"] = {"ti"},
["Philemon"] = {"philem", "phlm"},
["Hebrews"] = {"heb", "hebrew"}, -- catch typos
["James"] = {"jas"},
["1 Peter"] = {"1pet", "1pt", "1-pet", "1_pet", "1 pet"},
["2 Peter"] = {"2pet", "2pt", "2-pet", "2_pet", "2 pet"},
["1 John"] = {"1jn", "1-jn", "1_jn", "1 jn"},
["2 John"] = {"2jn", "2-jn", "2_jn", "2 jn"},
["3 John"] = {"3jn", "3-jn", "3_jn", "3 jn"},
["Jude"] = {},
["Revelation"] = {"rev", "apocalypse", "apoc", "rv",
Line 154 ⟶ 166:
local function getFullBookName(bookParam)
Returns the full name of a book of scripture based on the name/abbrev./alias provided
Pre-condition: bookParam is non-nil
NB: Because both Matthew in the NT and JST Matthew have just the title
"Matthew" on Wikisource, this function returns "JST Matthew" as the full name
Line 161 ⟶ 175:
]]
local function getFullBookName(bookParam)
 
assert(bookParam, "No book name provided")
for title,bookList in pairs(standardWorks) do
if bookList[bookParam] then
Line 197 ⟶ 210:
-- At this point we've searched, without regard to case, creed, or color,
-- for the alleged book of scripture they provided, but it ain't here!
asserterror(false, "Book <" .. bookParam .. "> not found in Standard Works", 0)
return ""
end --function getFullBookName(bookParam)
Line 205 ⟶ 218:
returns the Standard Work (as titled by Wikisource) that contains the book
passed in.
Preconditions: bookName is non-nil and was returned by getFullBookName
]]
local function getStandardWork(bookParambookName)
assert(bookParam, "No book name provided")
local book = getFullBookName(bookParam)
assert(book, "Book <" .. bookParam .. "> not found in Standard Works")
-- check the standardWorks table for any values that have a key with the
-- full name of the book; if so, return the key (the title of the SW)
for title,bookList in pairs(standardWorks) do
if bookList[bookbookName] then return title end
end
asserterror(false, "Book <" .. bookbookName .. "> is not a full book name found in Standard Works", 0)
-- pre-conditions mean that this error should never occur, aka if it does,
-- something went very wrong!
end
 
Line 266 ⟶ 277:
 
-- Special case for handling the Official Declarations in the D&C
local-- functionPre-condition: handleOD(displayTextParam, chapter)is non-nil
local function handleOD(displayTextParam, decNumber)
if chapter == "1" then
if decNumber == "1" then
return wsBaseURL .. "The_Doctrine_and_Covenants/Official_Declaration_1|" .. displayTextParam .. " 1]]"
return wsBaseURL .. "The_Doctrine_and_Covenants/Official_Declaration_1|" .. displayTextParam .. " 1]]"
elseif chapter == "2" then
elseif decNumber == "2" then
return "[https://www.churchofjesuschrist.org/study/scriptures/dc-testament/od/2?lang=eng " .. displayTextParam .. " 2]"
return "[https://www.churchofjesuschrist.org/study/scriptures/dc-testament/od/2?lang=eng " .. displayTextParam .. " 2]"
else -- decNumber wasn't 1 or 2 (and could even be nil)
if decNumber then
error("No such Official Declaration: " .. decNumber, 0)
else
error("No official declaration number provided", 0)
assert(false, "No such Official Declaration: " .. chapter)
end
end
end
 
-- for when the user has provided either no parameters or just one (the display
-- text for the wikilink)
local function handleFewParams(displayTextParam)
if not displayTextParam then
Line 285 ⟶ 303:
end
 
local function removePeriods(arg)
if arg then
return string.gsub(arg, "%.", "")
else
return nil
end
end
 
-- this function removes leading and trailing spaces via regex magic
local function trimSpaces(arg)
if arg then
Line 293 ⟶ 320:
end
 
-- local function extractParams(args):
-- Extracts and returns the parameters from the table of args passed in
-- Includes logic to handle the case where a user forgets to pass in bookParam
local function extractParams(args)
local displayTextParam = trimSpaces(args[1])
local bookParam = removePeriods(trimSpaces(args[2])) -- take out periods and spaces
local chapterParam = trimSpaces(args[3])
local verseParam = trimSpaces(args[4])
Line 301 ⟶ 331:
-- the 6th and 7th parameters, for footnotes and cross-references, have no
-- use on Wikisource (and don't seem to work even on CoCJ.org, but whatever)
-- so they are ignored
local endVerseFlag = trimSpaces(args[8])
-- handle the common mistake where someone forgets the second parameter
-- altogether (e.g., {{LDS|Alma|7|11}}).
-- This is done by testing whether the second parameter, which should be the
-- name/abbrev. of the book (e.g., 1ne), is instead a number. In that case
-- we will try assuming that the params should just be "shifted" over 1
-- and use the display text as the bookParam and go from there, fingers crossed.
if tonumber(args[2]) then
-- the second parameter is a number (tonumber returns nil if there is any text in its argument)
bookParam = removePeriods(trimSpaces(args[1])) -- use the display text and hope it's the full name of the book (or a valid abbreviation)!
chapterParam = trimSpaces(args[2])
verseParam = trimSpaces(args[3])
endVerseParam = trimSpaces(args[4])
endVerseFlag = trimSpaces(args[7])
end
return displayTextParam, bookParam, chapterParam, verseParam, endVerseParam, endVerseFlag
end
 
-- pre-condition: lectureNum is non-nil
local function getLectureOrdinal(lectureNum)
if lectureNum == "1" then return "First"
Line 315 ⟶ 363:
end
asserterror(false, "Lecture on Faith number <" .. lectureNum .. "> does not exist (should be between 1 and 7)", 0)
end
 
Line 360 ⟶ 408:
if fullBookName == "Lectures on Faith" then
if chapterParam then
fullBookNamelocal =status, "Lectureordinal "= .. getLectureOrdinalpcall(getLectureOrdinal, chapterParam)
if status then
fullBookName = "Lecture " .. ordinal
else
fullBookName = nil -- just cite to LoF generally
chapterParam = chapterParam .. " (invalid)" -- so user knows there was a problem
mw.log(ordinal) -- print error message to debug console (?)
end
else
fullBookName = nil -- The user has not provided a chapter (lecture) so this is treated as wanting to cite the LoF generally
Line 377 ⟶ 432:
wikiText = wikiText .. "]]" -- DON'T FORGET!!!
return wikiText
end
 
-- like the name says, this just counts the number of keys (aka indexes) in a table
local function countKeys(t)
local i = 0
for k,v in pairs(t) do i = i+1 end
return i
end
 
-- returns a (collapsed by default) wikitable listing all the aliases for every book
-- designed for use on the {{LDS}} template documentation page
function p.getBookAliasesWikiTable()
local wikiTable = [[{| class="wikitable sortable mw-collapsible mw-collapsed"
|+ class="nowrap" |LDS Template Book Name Aliases
! Standard Work !! Book !! Aliases
]]
for sw, bookList in pairs(standardWorks) do
wikiTable = wikiTable .. '|-\n|rowspan="' .. countKeys(bookList) .. '"|' .. sw .. "\n"
for book, aliases in pairs(bookList) do
wikiTable = wikiTable .. "| " .. book .. "\n| " .. table.concat(aliases, ", ") .. "\n|-\n"
end
end
wikiTable = wikiTable .. "|}"
return wikiTable
end