Bahaipedia
Bahaipedia
Menu
About Bahaipedia
Ask a question
General help
Random page
Recent changes
In other projects
Tools
What links here
Related changes
Upload file
Special pages
Printable version
Permanent link
Page information
Module
Discussion
View history
Talk
Contributions
Create account
Log in
Navigation
About Bahaipedia
Ask a question
General help
Random page
Recent changes
In other projects
Learn more
Core topics
Bahá’í Faith
Central Figures
Teachings
Practices
Tools
What links here
Related changes
Upload file
Special pages
Printable version
Permanent link
Page information
Translations

Module:WorldOrder2

From Bahaipedia
Jump to:navigation, search
Module documentation[view] [edit] [history] [purge]

Note: If you make changes to this module please also update Module:WorldOrder2 on bahai.media.

The above documentation is transcluded from Module:WorldOrder2/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.

local module = {}

-- Define a list of volume numbers and map to the pdf page offset
-- [11] means volume 1 issue 1, so 114 is volume 1 issue 14
local pdfOffset_map = {}

-- Set default value for all combinations
for volume = 1, 38 do
    for issue = 1, 4 do
        local key = string.format("%02d%02d", volume, issue)
        pdfOffset_map[key] = "2"
    end
end

-- Specify exceptions
pdfOffset_map["0101"] = "0"
pdfOffset_map["0102"] = "0"
pdfOffset_map["0103"] = "0"
pdfOffset_map["0104"] = "0"
pdfOffset_map["0201"] = "0"
pdfOffset_map["0202"] = "0"

local publicationDate_map = {
	["0101"] = "Fall, 1966",
	["0102"] = "Winter, 1966",
	["0103"] = "Spring, 1967",
	["0104"] = "Summer, 1967",
	["0201"] = "Fall, 1967",
	["0202"] = "Winter, 1967",
	["0203"] = "Spring, 1968",
	["0204"] = "Summer, 1968",
	["0301"] = "Fall, 1968",
	["0302"] = "Winter, 1968-69",
	["0303"] = "Spring, 1969",
	["0304"] = "Summer, 1969",
	["0401"] = "Fall, 1969",
	["0402"] = "Winter, 1969-70",
	["0403"] = "Spring, 1970",
	["0404"] = "Summer, 1970",
	["0501"] = "Fall, 1970",
	["0502"] = "Winter, 1970-71",
	["0503"] = "Spring, 1971",
	["0504"] = "Summer, 1971",
	["0601"] = "Fall, 1971",
	["0602"] = "Winter, 1971-72",
	["0603"] = "Spring, 1972",
	["0604"] = "Summer, 1972",
	["0701"] = "Fall, 1972",
	["0702"] = "Winter, 1972-73",
	["0703"] = "Spring, 1973",
	["0704"] = "Summer, 1973",
	["0801"] = "Fall, 1973",
	["0802"] = "Winter, 1973-74",
	["0803"] = "Spring, 1974",
	["0804"] = "Summer, 1974",
	["0901"] = "Fall, 1974",
	["0902"] = "Winter, 1974-75",
	["0903"] = "Spring, 1975",
	["0904"] = "Summer, 1975",
	["1001"] = "Fall, 1975",
	["1002"] = "Winter, 1975-76",
	["1003"] = "Spring, 1976",
	["1004"] = "Summer, 1976",
	["1101"] = "Fall, 1976",
	["1102"] = "Winter, 1976-77",
	["1103"] = "Spring, 1977",
	["1104"] = "Summer, 1977",
	["1201"] = "Fall, 1977",
	["1202"] = "Winter, 1977-78",
	["1203"] = "Spring, 1978",
	["1204"] = "Summer, 1978",
	["1301"] = "Fall, 1978",
	["1302"] = "Winter, 1978-79",
	["1303"] = "Spring, 1979",
	["1304"] = "Summer, 1979",
	["1401"] = "Fall, 1979",
	["1402"] = "Winter, 1979",
	["1403"] = "Spring/Summer, 1980",
	["1404"] = "Spring/Summer, 1980",
	["1501"] = "Fall 1980/Winter 1981",
	["1502"] = "Fall 1980/Winter 1981",
	["1503"] = "Spring/Summer, 1981",
	["1504"] = "Spring/Summer, 1981",
	["1601"] = "Fall, 1981",
	["1602"] = "Winter, 1981-02",
	["1603"] = "Spring, 1982",
	["1604"] = "Summer, 1982",
	["1701"] = "Fall, 1982",
	["1702"] = "Winter, 1982-83",
	["1703"] = "Spring, 1983",
	["1704"] = "Summer, 1983",
	["1801"] = "Fall, 1983",
	["1802"] = "Winter, 1983-84",
	["1803"] = "Spring, 1984",
	["1804"] = "Summer, 1984",
	["1901"] = "Fall 1984/Winter 1984-85",
	["1902"] = "Fall 1984/Winter 1984-85",
	["1903"] = "Spring/Summer, 1985",
	["1904"] = "Spring/Summer, 1985",
	["2001"] = "Fall, 1985",
	["2002"] = "Winter, 1985-86",
	["2003"] = "Spring/Summer, 1986",
	["2004"] = "Spring/Summer, 1986",
	["2101"] = "Fall 1986/Winter, 1986-87",
	["2102"] = "Fall 1986/Winter, 1986-87",
	["2103"] = "Spring/Summer, 1987",
	["2104"] = "Spring/Summer, 1987",
	["2201"] = "Fall 1987/Winter, 1987-88",
	["2202"] = "Fall 1987/Winter, 1987-88",
	["2203"] = "Spring/Summer, 1988",
	["2204"] = "Spring/Summer, 1988",
	["2301"] = "Fall 1988/Winter, 1988-89",
	["2302"] = "Fall 1988/Winter, 1988-89",
	["2303"] = "Spring/Summer, 1989",
	["2304"] = "Spring/Summer, 1989",
	["2401"] = "Fall 1989/Winter, 1989-90",
	["2402"] = "Fall 1989/Winter, 1989-90",
	["2403"] = "Spring/Summer, 1990",
	["2404"] = "Spring/Summer, 1990",
	["2501"] = "Fall, 1993",
	["2502"] = "Winter, 1993-94",
	["2503"] = "Spring, 1994",
	["2504"] = "Summer, 1994",
	["2601"] = "Fall, 1994",
	["2602"] = "Winter, 1994-95",
	["2603"] = "Spring, 1995",
	["2604"] = "Summer, 1995",
	["2701"] = "Fall, 1995",
	["2702"] = "Winter, 1995-96",
	["2703"] = "Spring, 1996",
	["2704"] = "Summer, 1996",
	["2801"] = "Fall, 1996",
	["2802"] = "Winter, 1996-97",
	["2803"] = "Spring, 1997",
	["2804"] = "Summer, 1997",
	["2901"] = "Fall, 1997",
	["2902"] = "Winter, 1997-98",
	["2903"] = "Spring, 1998",
	["2904"] = "Summer, 1998",
	["3001"] = "Fall, 1998",
	["3002"] = "Winter, 1998-99",
	["3003"] = "Spring, 1999",
	["3004"] = "Summer, 1999",
	["3101"] = "Fall, 1999",
	["3102"] = "Winter, 1999-2000",
	["3103"] = "Spring, 2000",
	["3104"] = "Summer, 2000",
	["3201"] = "Fall, 2000",
	["3202"] = "Winter, 2000-01",
	["3203"] = "Spring, 2001",
	["3204"] = "Summer, 2001",
	["3301"] = "Fall, 2001",
	["3302"] = "Winter, 2001-02",
	["3303"] = "Spring, 2002",
	["3304"] = "Summer, 2002",
	["3401"] = "Fall, 2002",
	["3402"] = "Winter, 2002-03",
	["3403"] = "Spring, 2003",
	["3404"] = "Summer, 2003",
	["3501"] = "Fall, 2003",
	["3502"] = "Winter, 2003-04",
	["3503"] = "Spring, 2004",
	["3504"] = "Summer, 2004",
	["3601"] = "Fall, 2004",
	["3602"] = "Winter, 2004-05",
	["3603"] = "Spring, 2005",
	["3604"] = "Summer, 2005",
	["3701"] = "Fall, 2005",
	["3702"] = "Winter, 2005-06",
	["3703"] = "Spring, 2006",
	["3704"] = "Summer, 2006",
	["3801"] = "Fall, 2006",
	["3802"] = "Winter, 2006-07",
	["3803"] = "Spring, 2007",
}

local itemNumber_map = {
    ["0101"] = "Q2354",
    ["0102"] = "Q2355",
    ["0103"] = "Q2356",
    ["0104"] = "Q2357",
    ["0201"] = "Q2359",
    ["0202"] = "Q2360",
    ["0203"] = "Q2361",
    ["0204"] = "Q2362",
    ["0301"] = "Q2364",
    ["0302"] = "Q2365",
    ["0303"] = "Q2366",
    ["0304"] = "Q2367",
    ["0401"] = "Q2509",
    ["0402"] = "Q2510",
    ["0403"] = "Q2511",
    ["0404"] = "Q2512",
    ["0501"] = "Q2618",
    ["0502"] = "Q2619",
    ["0503"] = "Q2620",
    ["0504"] = "Q2621",
    ["0601"] = "Q2623",
    ["0602"] = "Q2624",
    ["0603"] = "Q2625",
    ["0604"] = "Q2626",
    ["0701"] = "Q2628",
    ["0702"] = "Q2629",
    ["0703"] = "Q2630",
    ["0704"] = "Q2631",
    ["0801"] = "Q2633",
    ["0802"] = "Q2634",
    ["0803"] = "Q2635",
    ["0804"] = "Q2636",
    ["0901"] = "Q2638",
    ["0902"] = "Q2639",
    ["0903"] = "Q2640",
    ["0904"] = "Q2641",
    ["1001"] = "Q2643",
    ["1002"] = "Q2644",
    ["1003"] = "Q2645",
    ["1004"] = "Q2646",
    ["1101"] = "Q2648",
    ["1102"] = "Q2649",
    ["1103"] = "Q2650",
    ["1104"] = "Q2651",
    ["1201"] = "Q2653",
    ["1202"] = "Q2654",
    ["1203"] = "Q2655",
    ["1204"] = "Q2656",
    ["1301"] = "Q2658",
    ["1302"] = "Q2659",
    ["1303"] = "Q2660",
    ["1304"] = "Q2661",
    ["1401"] = "Q3072",
    ["1402"] = "Q3073",
    ["1403"] = "Q3074",
    ["1501"] = "Q3105",
    ["1503"] = "Q3106",
    ["1601"] = "Q3123",
    ["1602"] = "Q3124",
    ["1603"] = "Q3125",
    ["1604"] = "Q3126",
    ["1701"] = "Q3128",
    ["1702"] = "Q3129",
    ["1703"] = "Q3130",
    ["1704"] = "Q3131",
    ["1801"] = "Q3133",
    ["1802"] = "Q3134",
    ["1803"] = "Q3135",
    ["1804"] = "Q3136",
    ["1901"] = "Q3304",
    ["1903"] = "Q3305",
    ["2001"] = "Q3307",
    ["2002"] = "Q3308",
    ["2003"] = "Q3309",
    ["2101"] = "Q3311",
    ["2103"] = "Q3312",
    ["2201"] = "Q3314",
    ["2203"] = "Q3315",
    ["2301"] = "Q3317",
    ["2303"] = "Q3318",
    ["2401"] = "Q3320",
    ["2403"] = "Q3321",
    ["2501"] = "Q3476",
    ["2502"] = "Q3477",
    ["2503"] = "Q3478",
    ["2504"] = "Q3479",
    ["2601"] = "Q3481",
    ["2602"] = "Q3482",
    ["2603"] = "Q3483",
    ["2604"] = "Q3484",
    ["2701"] = "Q3486",
    ["2702"] = "Q3487",
    ["2703"] = "Q3488",
    ["2704"] = "Q3489",
    ["2801"] = "Q3491",
    ["2802"] = "Q3492",
    ["2803"] = "Q3493",
    ["2804"] = "Q3494",
    ["2901"] = "Q3496",
    ["2902"] = "Q3497",
    ["2903"] = "Q3498",
    ["2904"] = "Q3499",
    ["3001"] = "Q3501",
    ["3002"] = "Q3502",
    ["3003"] = "Q3503",
    ["3004"] = "Q3504",
    ["3101"] = "Q3506",
    ["3102"] = "Q3507",
    ["3103"] = "Q3508",
    ["3104"] = "Q3509",
    ["3201"] = "Q3511",
    ["3202"] = "Q3512",
    ["3203"] = "Q3513",
    ["3204"] = "Q3514",
    ["3301"] = "Q3516",
    ["3302"] = "Q3517",
    ["3303"] = "Q3518",
    ["3304"] = "Q3519",
    ["3401"] = "Q3521",
    ["3402"] = "Q3522",
    ["3403"] = "Q3523",
    ["3404"] = "Q3524",
    ["3501"] = "Q3526",
    ["3502"] = "Q3527",
    ["3503"] = "Q3528",
    ["3504"] = "Q3529",
    ["3601"] = "Q3531",
    ["3602"] = "Q3532",
    ["3603"] = "Q3533",
    ["3604"] = "Q3534",
    ["3701"] = "Q3536",
    ["3702"] = "Q3537",
    ["3703"] = "Q3538",
    ["3704"] = "Q3539",
    ["3801"] = "Q3541",
    ["3802"] = "Q3542",
    ["3803"] = "Q3543",
}

-- Function to generate padded keys
function getPaddedKey(vol, iss)
    local volPadded = string.format("%02d", vol)
    local issPadded = string.format("%02d", iss)
    return volPadded .. issPadded
end

-- Accept the input as the volume/issue number, return date published
function module.publicationDate(frame)
    local volNumber = tonumber(frame.args[1])
    local issNumber = tonumber(frame.args[2])
    local key = getPaddedKey(volNumber, issNumber)
    return publicationDate_map[key]
end

-- Accept the input as volume number, return pdf page number offset
function module.pdfOffset(frame)
    local volumeNumber = tonumber(frame.args[1])
    local issueNumber = tonumber(frame.args[2])
    local key = string.format("%02d%02d", volumeNumber, issueNumber)
    return pdfOffset_map[key]
end

-- BEGIN SECTION WHICH RETURNS AN ARTICLE OR AUTHOR BY VOL/ISSUE/PAGE NUMBER --
-- Usage: [[Template:Citewo]] 

-- Internal function to fetch article IDs from an issue item
function module.fetchArticleIDs(issueItemID)
    local issueItem = mw.wikibase.getEntity(issueItemID)
    local articleIDs = {}

    if not issueItem or not issueItem.claims then
        return articleIDs
    end

    local articlesPropertyID = 'P4'
    local articles = issueItem.claims[articlesPropertyID]

    if not articles then
        return articleIDs
    end

    for _, articleSnak in ipairs(articles) do
        if articleSnak.mainsnak and articleSnak.mainsnak.datavalue then
            local articleID = articleSnak.mainsnak.datavalue.value.id
            table.insert(articleIDs, articleID)
        end
    end

    return articleIDs
end

-- Internal function to parse a page range string
function module.parsePageRange(pageRange)
    local startPage, endPage = pageRange:match("(%d+)-?(%d*)")
    startPage = tonumber(startPage)
    endPage = (endPage ~= "" and tonumber(endPage)) or startPage
    return startPage, endPage
end

-- Internal function to fetch article page ranges from a list of article IDs
function module.fetchArticlePageRanges(articleIDs)
    local articlePageRanges = {}

    for _, articleID in ipairs(articleIDs) do
        local articleItem = mw.wikibase.getEntity(articleID)
        
        if articleItem and articleItem.claims then
            local pagesPropertyID = 'P6'
            local pagesClaims = articleItem.claims[pagesPropertyID]

            if pagesClaims then
                for _, pagesSnak in ipairs(pagesClaims) do
                    if pagesSnak.mainsnak and pagesSnak.mainsnak.datavalue then
                        local pageRange = pagesSnak.mainsnak.datavalue.value
                        local startPage, endPage = module.parsePageRange(pageRange)
                        table.insert(articlePageRanges, {id = articleID, startPage = startPage, endPage = endPage})
                    end
                end
            end
        end
    end

    return articlePageRanges
end

-- Function to find an article by page number
function module.findArticleByPageNumber(articlePageRanges, queriedPage)
    local primaryMatch = nil
    local secondaryMatch = nil

    -- Check for Article Start
    for _, article in ipairs(articlePageRanges) do
        if article.startPage == queriedPage then
            primaryMatch = article.id
            break
        elseif queriedPage >= article.startPage and queriedPage <= article.endPage then
            secondaryMatch = article.id
        end
    end

    -- Return primary match or secondary match
    return primaryMatch or secondaryMatch
end

-- Internal function to get the article ID based on volume, issue, and page
function module.getArticleIDByPage(vol, iss, page)
    local mapKey = string.format("%02d%02d", tonumber(vol), tonumber(iss))
    local issueItemID = itemNumber_map[mapKey]
    if not issueItemID then
        return nil, "Issue item ID not found for the given volume and issue."
    end

    local articleIDs = module.fetchArticleIDs(issueItemID)
    local articlePageRanges = module.fetchArticlePageRanges(articleIDs)
    local articleID = module.findArticleByPageNumber(articlePageRanges, page)

    return articleID
end

-- Function to fetch the author of an article item
function module.fetchArticleAuthor(articleID)
    local articleItem = mw.wikibase.getEntity(articleID)
    if articleItem and articleItem.claims then
        local authorPropertyID = 'P10'  -- Replace with the actual property ID for "author"
        local authorClaims = articleItem.claims[authorPropertyID]

        -- Check for author
        if authorClaims then
            for _, authorSnak in ipairs(authorClaims) do
                if authorSnak.mainsnak and authorSnak.mainsnak.datavalue then
                    -- Assuming the author is stored as an item
                    local authorID = authorSnak.mainsnak.datavalue.value.id
                    local authorItem = mw.wikibase.getEntity(authorID)
                    if authorItem then
                        local authorName = authorItem.labels.en.value  -- Assuming the name is in English
                        return authorName
                    end
                end
            end
        end

        -- Check for editorial (Q19)
        local editorialPropertyID = 'P12'
        local editorialClaims = articleItem.claims[editorialPropertyID]
        if editorialClaims then
            for _, editorialSnak in ipairs(editorialClaims) do
                if editorialSnak.mainsnak and editorialSnak.mainsnak.datavalue then
                    local editorialID = editorialSnak.mainsnak.datavalue.value.id
                    if editorialID == "Q19" then  -- Assuming Q19 is the ID for "editorial"
                        return "Editorial"
                    end
                end
            end
        end
    end
    return 'Unknown Author'
end

-- External function to be invoked by templates to get article name by page number
function module.getArticleByPage(frame)
    local vol = frame.args.vol
    local iss = frame.args.iss
    local page = tonumber(frame.args.page)

    local articleID, errMsg = module.getArticleIDByPage(vol, iss, page)

    if not articleID then
        return errMsg or "No article found on page " .. tostring(page)
    end

    local articleItem = mw.wikibase.getEntity(articleID)
    local articleName = articleItem and articleItem.labels and articleItem.labels.en and articleItem.labels.en.value or 'Unknown Article Name'
    return articleName
end

-- External function to get article author by page number
function module.getAuthorByPage(frame)
    local vol = frame.args.vol
    local iss = frame.args.iss
    local page = tonumber(frame.args.page)

    local articleID, errMsg = module.getArticleIDByPage(vol, iss, page)

    if not articleID then
        return errMsg or "No article found on page " .. tostring(page)
    end

    return module.fetchArticleAuthor(articleID)
end
-- END SECTION WHICH RETURNS AN ARTICLE OR AUTHOR BY VOL/ISSUE/PAGE NUMBER --

--External function to check if itemNumber exists given vol/iss/page
function module.checkItemNumber(frame)
    local vol = frame.args.vol
    local iss = frame.args.iss
    local mapKey = string.format("%02d%02d", tonumber(vol), tonumber(iss))
    local itemNumber = itemNumber_map[mapKey]

    if itemNumber then
        return "true" -- itemNumber exists
    else
        return "false" -- itemNumber does not exist
    end
end

-- External function to retrieve a list of article titles for a given volume and issue
function module.getArticleTitles(frame)
    local vol = frame.args.vol
    local iss = frame.args.iss

    local mapKey = string.format("%02d%02d", tonumber(vol), tonumber(iss))
    local issueItemID = itemNumber_map[mapKey]
    if not issueItemID then
        return "Issue item ID not found for the given volume and issue."
    end

    local articleIDs = module.fetchArticleIDs(issueItemID)
    local articleTitles = {}

    for _, articleID in ipairs(articleIDs) do
        local articleItem = mw.wikibase.getEntity(articleID)
        if articleItem and articleItem.labels and articleItem.labels.en then
            local articleTitle = articleItem.labels.en.value or 'Unknown Article Title'
            table.insert(articleTitles, articleTitle)
        end
    end

    return table.concat(articleTitles, ", ")
end

return module
Retrieved from "https://bahaipedia.org/index.php?title=Module:WorldOrder2&oldid=131393"
This page was last edited on 21 March 2024, at 22:25.
Text is available under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
Privacy policy
About Bahaipedia
Disclaimers
Powered by MediaWiki