-- This module includes little helper functions for the Wiki Loves Living Heritage pages
local p = {}
-- Any time you use {{#invoke:}}, the object passed in is a frame (representing the page using the module as well as arguments passed to the {{#invoke:}} call).
function p.wikidata_source_link(frame)
local entity_id = frame.args[1] -- Wikidata entity ID
local property_id = "P856" -- Wikidata property ID
local value = mw.wikibase.getEntity(entity_id):getPropertyValue(property_id)
local source_url = mw.wikibase.getBestStatements(entity_id, property_id)[1]:getSourceUrl()
return string.format("[[%s|%s]]", source_url, value)
end
function p.wikipediaLink(frame)
local entity = frame.args[1] -- Wikidata entity ID
local lang = frame.args[2] -- Wikidata property ID
local link
if type(entity) == 'table' then
link = entity:getSitelink(lang .. 'wiki')
else
link = mw.wikibase.getSitelink(entity, lang .. 'wiki')
end
if link then
linktxt = ':' .. lang .. ':' .. link
return string.format("[[%s|%s]]", linktxt, link)
end
return nil
end
function p.organizerlistsimple(frame)
local output = ""
-- Get the first argument passed to the {{#invoke:}} call (after the name of the module and the function name).
local input = frame.args[1]
-- Use 'mw.ustring' rather than 'string', since strings that are passed in are almost always Unicode text.
for i in mw.ustring.gmatch(input, "[^,]+") do
-- Get the result from using the {{label}} template, with i as an argument, on this page.
current_label = frame:expandTemplate{
title='Wiki Loves Living Heritage/Organizerlinksimple',
args={i}
}
-- Add a bullet point before every label except the first.
if output ~= "" then
output = output .. ", "
end
-- Add the current label to the output.
output = output .. current_label
end
return output
end
function p.organizerlist(frame)
local output = ""
-- Get the first argument passed to the {{#invoke:}} call (after the name of the module and the function name).
local input = frame.args[1]
-- Use 'mw.ustring' rather than 'string', since strings that are passed in are almost always Unicode text.
for i in mw.ustring.gmatch(input, "[^,]+") do
-- Get the result from using the {{label}} template, with i as an argument, on this page.
current_label = frame:expandTemplate{
title='Wiki Loves Living Heritage/Organizerlink',
args={i}
}
-- Add a bullet point before every label except the first.
if output ~= "" then
output = output .. "<br />"
end
-- Add the current label to the output.
output = output .. current_label
end
return output
end
function p.labellist(frame)
-- Get the first argument passed to the {{#invoke:}} call (after the name of the module and the function name).
local input = frame.args[1]
-- Return nothing if the input is nil or an empty string
if not input or input == "" then
return ""
end
local output = ""
-- Use 'mw.ustring' rather than 'string', since strings that are passed in are almost always Unicode text.
for i in mw.ustring.gmatch(input, "[^,]+") do
-- Get the result from using the {{label}} template, with i as an argument, on this page.
local current_label = frame:expandTemplate{
title = 'Wiki Loves Living Heritage/Originlink',
args = { i }
}
-- Add a bullet point before every label except the first.
if output ~= "" then
output = output .. " • "
end
-- Add the current label to the output.
output = output .. current_label
end
-- Wrap the output in a div with the class "labellist" and return
return '<div class="labellist">' .. output .. '</div>'
end
function p.inventorylist(frame)
local output = ""
local inventories = frame.args.inventories
local item = frame.args.item
local ichid = frame.args.ichid
-- Use 'mw.ustring' rather than 'string', since strings that are passed in are almost always Unicode text.
for i in mw.ustring.gmatch(inventories, "[^,]+") do
current_label = frame:expandTemplate{
title='Wiki Loves Living Heritage/Inventorylink',
args = {
item = item,
inventory = i,
ichid = ichid
}
}
output = output .. "<div class='boxrow'>" .. current_label .. "</div>"
end
return output
end
function p.participantlist(frame)
local output = ""
local arguments = {}
local input = frame.args[1]
for i in mw.ustring.gmatch(input, "[^,]+") do
arguments['item'] = i
current_label = frame:expandTemplate{
title='Wiki Loves Living Heritage/Contact',
args = arguments
}
output = output .. current_label
end
return output
end
-- Function to convert Solar Hijri date to Gregorian and return in ISO format
local function hijriToGregorianISO(hijriYear, hijriMonth, hijriDay)
-- Constants for Solar Hijri Calendar (Persian Calendar)
local baseYearGregorian = 621 -- Base year for Hijri-Gregorian correspondence
local hijriNewYearOffset = 79 -- Offset for Persian New Year around March 21
-- Calculate the Gregorian year
local gregorianYear = hijriYear + baseYearGregorian
local approximateGregorianDayOfYear = (hijriMonth - 1) * 30 + hijriDay + hijriNewYearOffset
-- Adjust to convert the day and month accurately
local day = approximateGregorianDayOfYear
local month = 3 -- Start around March
while day > 30 do
day = day - 30
month = month + 1
if month > 12 then
month = 1
gregorianYear = gregorianYear + 1
end
end
-- Format the date in ISO format (YYYY-MM-DD)
local isoDate = string.format("%04d-%02d-%02d", gregorianYear, month, day)
return isoDate
end
-- Once you've finished adding functions to 'p', you need to return it.
return p