https://en.seminaverbi.bibleget.io/w/index.php?title=Module:Bibleverse&feed=atom&action=history
Module:Bibleverse - Revision history
2024-03-29T07:29:23Z
Revision history for this page on the wiki
MediaWiki 1.41.0
https://en.seminaverbi.bibleget.io/w/index.php?title=Module:Bibleverse&diff=26338&oldid=prev
Johnrdorazio: 1 revision imported
2021-10-11T17:31:31Z
<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 17:31, October 11, 2021</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
Johnrdorazio
https://en.seminaverbi.bibleget.io/w/index.php?title=Module:Bibleverse&diff=26337&oldid=prev
en>Johnuniq: update from Module:Bibleverse/sandbox with edit by User:Akeosnhaoe to use '+' instead of '%20' for biblegateway
2021-05-05T04:56:13Z
<p>update from <a href="/w/index.php?title=Module:Bibleverse/sandbox&action=edit&redlink=1" class="new" title="Module:Bibleverse/sandbox (page does not exist)">Module:Bibleverse/sandbox</a> with edit by <a href="/w/index.php?title=User:Akeosnhaoe&action=edit&redlink=1" class="new" title="User:Akeosnhaoe (page does not exist)">User:Akeosnhaoe</a> to use '+' instead of '%20' for biblegateway</p>
<p><b>New page</b></p><div>-- This module implements Template:Bibleverse.<br />
local p = {}<br />
<br />
--codes from bvf that may be in use<br />
local version_num_codes = {<br />
[9] = 'kjv', [31] = 'niv', [45] = 'amp', [49] = 'nasb', [64] = 'nivuk',<br />
[51] = 'nlt', [65] = 'msg', [76] = 'nirv', [105] = 'he', [104] = 'jps',<br />
[120] = 'opb', [121] = 'bb', [122] = 'bbc', [123] = 'bbl', [131] = 'nrsv',<br />
}<br />
<br />
--possible book inputs, based on Chicago Manual<br />
local book_aliases = {<br />
['genesis'] = {'gen', 'gn'}, --old testament/tanakh<br />
['exodus'] = {'exod', 'ex'},<br />
['leviticus'] = {'lev', 'lv'},<br />
['numbers'] = {'num', 'nm'},<br />
['deuteronomy'] = {'deut', 'dt'},<br />
['joshua'] = {'josh' , 'jo'},<br />
['judges'] = {'judg', 'jgs'},<br />
['ruth'] = {'ru'},<br />
['1_samuel'] = {'1sam', '1sm'},<br />
['2_samuel'] = {'2sam', '2sm'},<br />
['1_kings'] = {'1kgs'},<br />
['2_kings'] = {'2kgs'},<br />
['1_chronicles'] = {'1chron', '1chr'},<br />
['2_chronicles'] = {'2chron', '2chr'},<br />
['ezra'] = {'ezr'},<br />
['nehemiah'] = {'neh'},<br />
['esther'] = {'est'},<br />
['job'] = {'jb'},<br />
['psalms'] = {'ps', 'pss', 'psalm'},<br />
['proverbs'] = {'prov', 'prv'},<br />
['ecclesiastes'] = {'eccles', 'eccl', 'qoheleth'},<br />
['song_of_solomon'] = {'songofsol', 'songofsongs', 'song', 'sg', 'canticles', 'canticleofcanticles'},<br />
['isaiah'] = {'isa', 'is'},<br />
['jeremiah'] = {'jer'},<br />
['lamentations'] = {'lam'},<br />
['ezekiel'] = {'ezek', 'ez'},<br />
['daniel'] = {'dan', 'dn'},<br />
['hosea'] = {'hos'},<br />
['joel'] = {'jl'},<br />
['amos'] = {'am'},<br />
['obadiah'] = {'obad', 'ob'},<br />
['jonah'] = {'jon'},<br />
['micah'] = {'mic', 'mi'},<br />
['nahum'] = {'nah', 'na'},<br />
['habakkuk'] = {'hab', 'hb'},<br />
['zephaniah'] = {'zeph', 'zep'},<br />
['haggai'] = {'hag', 'hg'},<br />
['zechariah'] = {'zech', 'zec'},<br />
['malachi'] = {'mal'},<br />
['baruch'] = {'bar'}, --apocrypha/deuterocanon<br />
['ecclesiasticus'] = {'ecclus', 'wisdomofsirach', 'sirach', 'sir'},<br />
['1_esdras'] = {'1esd'},<br />
['2_esdras'] = {'2esd'},<br />
['judith'] = {'jth', 'jdt'},<br />
['1_maccabees'] = {'1macc', '1mc'},<br />
['2_maccabees'] = {'2macc', '2mc'},<br />
['3_maccabees'] = {'3macc', '3mc'},<br />
['4_maccabees'] = {'4macc', '4mc'},<br />
['prayer_of_manasseh'] = {'profman', 'prayerofmanasses'},<br />
['susanna'] = {'sus'},<br />
['tobit'] = {'tob', 'tb'},<br />
['wisdom_of_solomon'] = {'ws', 'wisdom', 'wisofsol'},<br />
['prayer_of_azariah'] = {'prayerofazariahandhymnofthethreechildren'},<br />
['rest_of_esther'] = {'additionstoesther'},<br />
['bel_and_the_dragon'] = {'bel'},<br />
['epistle_of_jeremiah'] = {'letterofjeremiah'},<br />
['matthew'] = {'matt', 'mt'}, --new testament<br />
['mark'] = {'mk'},<br />
['luke'] = {'lk'},<br />
['john'] = {'jn'},<br />
['acts'] = {'actsoftheapostles'},<br />
['romans'] = {'rom'},<br />
['1_corinthians'] = {'1cor'},<br />
['2_corinthians'] = {'2cor'},<br />
['galatians'] = {'gal'},<br />
['ephesians'] = {'eph'},<br />
['philippians'] = {'phil'},<br />
['colossians'] = {'col'},<br />
['1_thessalonians'] = {'1thess', '1thes'},<br />
['2_thessalonians'] = {'2thess', '2thes'},<br />
['1_timothy'] = {'1tim', '1tm'},<br />
['2_timothy'] = {'2tim', '2tm'},<br />
['titus'] = {'ti'},<br />
['philemon'] = {'philem', 'phlm'},<br />
['hebrews'] = {'heb'},<br />
['james'] = {'jas'},<br />
['1_peter'] = {'1pet', '1pt'},<br />
['2_peter'] = {'2pet', '2pt'},<br />
['1_john'] = {'1jn'},<br />
['2_john'] = {'2jn'},<br />
['3_john'] = {'3jn'},<br />
['jude'] = {'jude'},<br />
['revelation'] = {'rev', 'apocalypse', 'apoc', 'rv'},<br />
}<br />
<br />
local apoc = {<br />
['1_esdras'] = true, ['2_esdras'] = true, ['judith'] = true, ['1_maccabees'] = true,<br />
['2_maccabees'] = true, ['3_maccabees'] = true, ['4_maccabees'] = true,<br />
['prayer_of_manasseh'] = true, ['susanna'] = true, ['tobit'] = true,<br />
['wisdom_of_solomon'] = true, ['prayer_of_azariah'] = true, ['rest_of_esther'] = true,<br />
['bel_and_the_dragon'] = true, ['epistle_of_jeremiah'] = true,<br />
['sirach'] = true, ['ecclesiasticus'] = true,<br />
}<br />
<br />
--these books only have one chapter, have to be handled differently<br />
local no_chapters = {<br />
['obadiah'] = true, ['epistle_of_jeremiah'] = true, ['prayer_of_azariah'] = true,<br />
['susanna'] = true, ['bel_and_the_dragon'] = true, ['prayer_of_manasseh'] = true,<br />
['philemon'] = true, ['2_john'] = true, ['3_john'] = true, ['jude'] = true,<br />
}<br />
<br />
--sets the website to be used for each version, biblegateway is the fallback so don't define any for it<br />
local site_tbl = {<br />
nrsv = 'oremus', nrsvae = 'oremus',<br />
kjv = 'wikisource', asv = 'wikisource',<br />
he = 'mechon_mamre', jps = 'mechon_mamre',<br />
niv = 'biblica', nivuk = 'biblica', amp = 'biblica', ab = 'biblica',<br />
nasb = 'biblica', msg = 'biblica', nlt = 'biblica', nirv = 'biblica',<br />
nab = 'usccb',<br />
bb = 'bible_hub', bbc = 'bible_hub', bbl = 'bible_hub', opb = 'bible_hub',<br />
esv = 'esv_bible',<br />
}<br />
<br />
--pattern for the url of each site using _book etc. (underscore then letters [a-z]) for variables<br />
local urlpat_tbl = {<br />
oremus = 'https://bible.oremus.org/?passage=_book%20_vrange&version=_version',<br />
wikisource = 's:Bible (_version)/_book#_schap:_svers',<br />
mechon_mamre = 'https://www.mechon-mamre.org/_version_book_schap.htm#_svers',<br />
biblica = 'https://www.biblica.com/bible/?osis=_version:_book%20_vrange',<br />
usccb = 'https://bible.usccb.org/bible/_book/_schap?_svers',<br />
biblegateway = 'https://www.biblegateway.com/passage/?search=_book+_vrange&version=_version',<br />
bible_hub = 'https://_version/_book/_schap-_svers.htm',<br />
esv_bible = 'https://www.esv.org/_book+_schap:_svers',<br />
}<br />
<br />
--changes book name to use in url for each site, only if necessary<br />
local site_book_tbl = {<br />
oremus = {<br />
['epistle_of_jeremiah'] = 'letter of jeremiah',<br />
},<br />
usccb = {<br />
['song_of_solomon'] = 'song_of_songs',<br />
['wisdom_of_solomon'] = 'wisdom',<br />
['ecclesiasticus'] = 'sirach',<br />
},<br />
mechon_mamre = {<br />
['genesis'] = '01', ['exodus'] = '02', ['leviticus'] = '03',<br />
['numbers'] = '04', ['deuteronomy'] = '05', ['joshua'] = '06',<br />
['judges'] = '07', ['1_samuel'] = '08a', ['2_samuel'] = '08b',<br />
['1_kings'] = '09a', ['2_kings'] = '09b', ['isaiah'] = '10',<br />
['jeremiah'] = '11', ['ezekiel'] = '12', ['hosea'] = '13',<br />
['joel'] = '14', ['amos'] = '15', ['obadiah'] = '16', ['jonah'] = '17',<br />
['micah'] = '18', ['nahum'] = '19', ['habakkuk'] = '20',<br />
['zephaniah'] = '21', ['haggai'] = '22', ['zechariah'] = '23',<br />
['malachi'] = '24', ['1_chronicles'] = '25a', ['2_chronicles'] = '25b',<br />
['psalms'] = '26', ['job'] = '27', ['proverbs'] = '28', ['ruth'] = '29',<br />
['song_of_solomon'] = '30', ['ecclesiastes'] = '31', ['lamentations'] = '32',<br />
['esther'] = '33', ['daniel'] = '34', ['ezra'] = '35a', ['nehemiah'] = '35b',<br />
}<br />
}<br />
<br />
--changes to the version name to be used in urls, only if necessary<br />
local site_version_tbl = {<br />
mechon_mamre = {<br />
he = 'p/pt/pt',<br />
jps = 'e/et/et',<br />
},<br />
wikisource = {<br />
kjv = 'King James', ['9'] = 'King James',<br />
asv = 'American Standard',<br />
},<br />
bible_hub = {<br />
bb = 'biblebrowser.com',<br />
bbc = 'biblecommenter.com',<br />
bbl = 'scripturetext.com',<br />
opb = 'bible.cc',<br />
}<br />
}<br />
<br />
local function trimArg(text)<br />
if type(text) == 'string' then<br />
text = text:match('(%S.-)%s*$') --trimmed text or nil if empty<br />
end<br />
return text<br />
end<br />
<br />
local function valueExists(tbl, value)<br />
for _, v in pairs(tbl) do<br />
if value == v then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
<br />
local function titlecase(arg)<br />
-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html<br />
-- recommended by The U.S. Government Printing Office Style Manual:<br />
-- 'Capitalize all words in titles of publications and documents,<br />
-- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.'<br />
local alwayslower = {<br />
['a'] = true, ['an'] = true, ['the'] = true,<br />
['and'] = true, ['but'] = true, ['or'] = true, ['for'] = true,<br />
['nor'] = true, ['on'] = true, ['in'] = true, ['at'] = true, ['to'] = true,<br />
['from'] = true, ['by'] = true, ['of'] = true, ['up'] = true,<br />
}<br />
local words = mw.text.split(mw.text.trim(arg or ''), '_')<br />
for i, s in ipairs(words) do<br />
s = string.lower(s)<br />
if i > 1 then<br />
if not alwayslower[s] then<br />
s = mw.getContentLanguage():ucfirst(s)<br />
end<br />
else<br />
s = mw.getContentLanguage():ucfirst(s)<br />
end<br />
words[i] = s<br />
end<br />
return table.concat(words, '_')<br />
end<br />
<br />
function p.main(frame)<br />
local targs = frame:getParent().args<br />
local args = {}<br />
for _, param in ipairs({1, 2, 3, 4, 5, 'nobook'}) do<br />
args[param] = trimArg(targs[param])<br />
end<br />
local default_version = 'nrsv'<br />
local input_book = ''<br />
local ref = ''<br />
local version = ''<br />
local version_num<br />
local text = ''<br />
local mainspace = mw.title.getCurrentTitle():inNamespaces(0)<br />
if args[1] == nil or args[2] == nil or tonumber(args[1]) ~= nil then<br />
-- first argument is a numeric prefix and second is book name<br />
input_book = trimArg((args[1] or '') .. ' ' .. (args[2] or '')) or ''<br />
ref = args[3] or ''<br />
version = mw.ustring.lower(args[4] or default_version)<br />
text = args[5] or trimArg((input_book .. ' ' .. ref))<br />
else<br />
-- first argument is the whole book name<br />
input_book = args[1] or ''<br />
ref = args[2] or ''<br />
version = mw.ustring.lower(args[3] or default_version)<br />
text = args[4] or (input_book .. ' ' .. ref)<br />
end<br />
if args.nobook == 'yes' then<br />
text = ref<br />
end<br />
text = text:gsub('-', '–') --change hyphens to en dashes (3:2-5 → 3:2–5)<br />
<br />
if tonumber(version) then<br />
version = version_num_codes[tonumber(version)] or version<br />
version_num = true<br />
end<br />
<br />
local errors = {}<br />
if version == 'jpr' or version == 'jp' then --chabad doesn't work so reroute<br />
version = 'he'<br />
if mainspace then<br />
table.insert(errors, '[[Category:Pages with Bible version errors]]')<br />
end<br />
end<br />
<br />
local book = input_book:gsub('%p', ''):gsub(' ', '_')<br />
book = mw.ustring.lower(book)<br />
<br />
local book_found = false<br />
local standard = book:gsub('_', '')<br />
for full_book, aliases in pairs(book_aliases) do<br />
if standard == full_book:gsub('_', '') or valueExists(aliases, standard) then<br />
book = full_book<br />
book_found = true<br />
break<br />
end<br />
end<br />
<br />
local site = site_tbl[version] or 'biblegateway' --fall back on biblegateway for unrecognized version because it has so many versions<br />
<br />
if apoc[book] and version == 'nrsv' and site == 'oremus' then --oremus's nrsv doesn't have the apocrypha<br />
version = 'nrsvae' --the anglicized version does<br />
end<br />
<br />
local urlpat = urlpat_tbl[site]<br />
<br />
local split_ref = mw.text.split(ref, '[-–—]') --split the ref into the part before and after the dash/hyphen<br />
local s_ref = mw.text.split(split_ref[1], '%p') --any punctuation can be used to separate chapter from verse<br />
local e_ref = split_ref[2] or split_ref[1]<br />
e_ref = mw.text.split(e_ref, '%p')<br />
for i, v in ipairs(s_ref) do s_ref[i] = v:gsub('%D', '') end --remove any non-numeric character (such as f)<br />
for i, v in ipairs(e_ref) do e_ref[i] = v:gsub('%D', '') end<br />
<br />
local e_chap, e_vers, s_chap, s_vers<br />
local chapter_only = not s_ref[2]<br />
if no_chapters[book] then<br />
chapter_only = false<br />
s_chap = 1<br />
s_vers = s_ref[2] or s_ref[1] or 1 --verse 3 can be specified as "3" or "1:3"<br />
e_chap = 1<br />
e_vers = e_ref[2] or e_ref[1] or 1<br />
else<br />
s_chap = s_ref[1] or 1<br />
s_vers = s_ref[2] or 1<br />
if e_ref[2] or not s_ref[2] then --chapter-chapter or chapter(:verse)?-chapter:verse<br />
e_chap = e_ref[1] or s_chap<br />
else --chapter:verse-verse<br />
e_chap = s_chap<br />
end<br />
e_vers = e_ref[2] or e_ref[1] or s_vers<br />
end<br />
<br />
if type(site_book_tbl[site]) == 'table' then<br />
book = site_book_tbl[site][book] or book<br />
end<br />
<br />
book = titlecase(book) --title case looks better at oremus where they display the input<br />
<br />
if site == 'mechon_mamre' then --special case handling for components of the url<br />
if not tonumber(s_chap) then --non-numeric characters were omitted above so this may not be what was entered<br />
error('Bibleverse error: start chapter should be a number', 0)<br />
end<br />
s_chap = string.format('%x', s_chap/10) .. (s_chap % 10)<br />
elseif site == 'biblica' or site == 'oremus' then<br />
book = book:gsub('_', '%%20')<br />
elseif site == 'esv_bible' or site == 'biblegateway' then<br />
book = book:gsub('_', '+')<br />
elseif site == 'bible_hub' then<br />
book = string.lower(book)<br />
elseif site == 'usccb' then<br />
book = book:gsub('_', '')<br />
end<br />
if type(site_version_tbl[site]) == 'table' then<br />
version = site_version_tbl[site][version]<br />
end<br />
<br />
local v_range<br />
if chapter_only then<br />
if e_chap == s_chap then<br />
v_range = s_chap<br />
else<br />
v_range = s_chap .. '–' .. e_chap<br />
end<br />
else<br />
if e_chap == s_chap and e_vers == s_vers then<br />
v_range = s_chap ..':' .. s_vers<br />
elseif e_chap == s_chap then<br />
v_range = s_chap .. ':' .. s_vers .. '–' .. e_vers<br />
else<br />
v_range = s_chap .. ':' .. s_vers .. '–' .. e_chap .. ':' .. e_vers<br />
end<br />
end<br />
<br />
local url = urlpat:gsub('_%l+', { --get the components into the url<br />
_book = book,<br />
_schap = s_chap,<br />
_svers = s_vers,<br />
_echap = e_chap,<br />
_evers = e_vers,<br />
_vrange = v_range,<br />
_version = version,<br />
})<br />
<br />
local fulllink<br />
if site == 'wikisource' then --interwikilink<br />
fulllink = '[[' .. url .. '|' .. text .. ']]'<br />
else<br />
fulllink = '[' .. url .. ' ' .. text .. ']'<br />
end<br />
<br />
if mainspace then<br />
if not book_found then<br />
table.insert(errors, '<span style="color:red">Template:Bibleverse with invalid book</span>[[Category:Pages with Bible book errors]]')<br />
end<br />
if version_num then<br />
table.insert(errors, '[[Category:Pages with numeric Bible version references]]')<br />
end<br />
end<br />
return fulllink .. table.concat(errors)<br />
end<br />
<br />
return p</div>
en>Johnuniq