Jump to content

Module:Incident

From Srcfy Wiki
Revision as of 00:46, 31 October 2026 by Admin (talk | contribs) (Incident index)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Incident/doc

-- Helpers for {{Incident infobox}} and the incident index pages.
-- Every user-facing string exists in English (en) and Malayalam (ml); the language
-- comes from {{PAGELANGUAGE}}, which the Translate extension sets to "ml" on /ml subpages.
local p = {}

local MONTHS = {
	en = { 'January', 'February', 'March', 'April', 'May', 'June', 'July',
		'August', 'September', 'October', 'November', 'December' },
	ml = { 'ജനുവരി', 'ഫെബ്രുവരി', 'മാർച്ച്', 'ഏപ്രിൽ', 'മേയ്', 'ജൂൺ', 'ജൂലൈ',
		'ഓഗസ്റ്റ്', 'സെപ്റ്റംബർ', 'ഒക്ടോബർ', 'നവംബർ', 'ഡിസംബർ' },
}

local LABELS = {
	date = { en = 'Date', ml = 'തീയതി' },
	place = { en = 'Location', ml = 'സ്ഥലം' },
	district = { en = 'District', ml = 'ജില്ല' },
	state = { en = 'State', ml = 'സംസ്ഥാനം' },
	coordinates = { en = 'Coordinates', ml = 'നിർദ്ദേശാങ്കങ്ങൾ' },
	victims = { en = 'Victims', ml = 'ഇരകൾ' },
	killed = { en = 'Killed', ml = 'കൊല്ലപ്പെട്ടവർ' },
	injured = { en = 'Injured', ml = 'പരിക്കേറ്റവർ' },
	trigger = { en = 'Alleged trigger', ml = 'ആരോപിത കാരണം' },
	allegation = { en = 'Allegation', ml = 'ആരോപണം' },
	legal_status = { en = 'Legal status', ml = 'നിയമനടപടികളുടെ നില' },
	osm = { en = 'View on OpenStreetMap', ml = 'ഓപ്പൺസ്ട്രീറ്റ്മാപ്പിൽ കാണുക' },
	references = { en = 'References', ml = 'അവലംബങ്ങൾ' },
	incidents = { en = 'Incidents', ml = 'സംഭവങ്ങൾ' },
	people_killed = { en = 'People killed', ml = 'കൊല്ലപ്പെട്ടവർ' },
	people_injured = { en = 'People injured', ml = 'പരിക്കേറ്റവർ' },
	summary = { en = 'Summary', ml = 'സംഗ്രഹം' },
	years = { en = 'Years covered', ml = 'കാലയളവ്' },
	article = { en = 'Article', ml = 'ലേഖനം' },
	navbox_title = { en = 'Cow-related mob violence in India (2014–2025)',
		ml = 'ഇന്ത്യയിലെ പശു സംബന്ധമായ ആൾക്കൂട്ട ആക്രമണങ്ങൾ (2014–2025)' },
	index_link = { en = 'Index of all incidents', ml = 'എല്ലാ സംഭവങ്ങളുടെയും സൂചിക' },
}

local TRIGGERS = {
	['beef consumption'] = { en = 'Beef consumption or storage', ml = 'ബീഫ് കഴിക്കുകയോ സൂക്ഷിക്കുകയോ ചെയ്തെന്ന ആരോപണം' },
	['cattle transport'] = { en = 'Cattle transport', ml = 'കന്നുകാലികളെ കടത്തൽ' },
	['cattle theft'] = { en = 'Cattle theft', ml = 'കന്നുകാലി മോഷണം' },
	['cow slaughter'] = { en = 'Cow slaughter', ml = 'പശുവിനെ കശാപ്പ് ചെയ്യൽ' },
	['other'] = { en = 'Other', ml = 'മറ്റുള്ളവ' },
}

local CATEGORY = {
	en = 'Cow-related mob violence in India',
	ml = 'ഇന്ത്യയിലെ പശു സംബന്ധമായ ആൾക്കൂട്ട ആക്രമണങ്ങൾ',
}

local function lang(frame)
	local l = frame.args.lang or frame.args[2] or 'en'
	if l == 'ml' then return 'ml' end
	return 'en'
end

local function trim(s)
	return s and mw.text.trim(s) or ''
end

-- {{#invoke:Incident|label|date|ml}}
function p.label(frame)
	local entry = LABELS[trim(frame.args[1])]
	if not entry then return '' end
	return entry[lang(frame)]
end

-- {{#invoke:Incident|category|ml}} → language-specific incident category name
function p.category(frame)
	local l = trim(frame.args[1]) == 'ml' and 'ml' or 'en'
	return CATEGORY[l]
end

-- {{#invoke:Incident|date|2015-09-28|ml}} → "2015 സെപ്റ്റംബർ 28" / "28 September 2015"
function p.date(frame)
	local iso = trim(frame.args[1])
	local y, m, d = iso:match('^(%d%d%d%d)%-(%d%d)%-(%d%d)$')
	if not y then
		y, m = iso:match('^(%d%d%d%d)%-(%d%d)$')
	end
	if not y then return iso end
	local month = MONTHS[lang(frame)][tonumber(m)]
	if lang(frame) == 'ml' then
		return y .. ' ' .. month .. (d and (' ' .. tonumber(d)) or '')
	end
	return (d and (tonumber(d) .. ' ') or '') .. month .. ' ' .. y
end

-- {{#invoke:Incident|year|2015-09-28}} → 2015
function p.year(frame)
	return trim(frame.args[1]):match('^(%d%d%d%d)') or ''
end

-- {{#invoke:Incident|trigger|cattle transport|ml}}
function p.trigger(frame)
	local key = mw.ustring.lower(trim(frame.args[1]))
	local entry = TRIGGERS[key]
	if not entry then return trim(frame.args[1]) end
	return entry[lang(frame)]
end

local function dms(value, pos, neg)
	local hemi = value < 0 and neg or pos
	return string.format('%.4f°%s', math.abs(value), hemi)
end

-- {{#invoke:Incident|coord|28.5986|77.5874|lang=ml}} → "28.5986°N 77.5874°E" + OpenStreetMap link
function p.coord(frame)
	local lat, lon = tonumber(trim(frame.args[1])), tonumber(trim(frame.args[2]))
	if not lat or not lon then return '' end
	local text = dms(lat, 'N', 'S') .. ' ' .. dms(lon, 'E', 'W')
	local url = string.format('https://www.openstreetmap.org/?mlat=%.5f&mlon=%.5f#map=12/%.5f/%.5f', lat, lon, lat, lon)
	return text .. '<br><span class="incident-osm">[' .. url .. ' ' .. LABELS.osm[lang(frame)] .. ']</span>'
end

-- {{#invoke:Incident|victims|Name A; Name B}} → plain text for one name, a list for several
function p.victims(frame)
	local names = {}
	for name in mw.text.gsplit(trim(frame.args[1]), ';', true) do
		name = trim(name)
		if name ~= '' then table.insert(names, name) end
	end
	if #names <= 1 then return names[1] or '' end
	return '\n* ' .. table.concat(names, '\n* ')
end

-- {{#invoke:Incident|isSourceCopy}} → "yes" on the "/en" copy Translate makes of each source page.
-- The infobox skips SMW annotations and categories there so incidents are not counted twice.
function p.isSourceCopy(frame)
	local title = mw.title.getCurrentTitle().text
	if title:sub(-3) == '/en' then return 'yes' end
	return ''
end

return p