Shko te përmbajtja

Moduli:Mbyllje diskutimi

Page protected
Nga Wikipedia, enciklopedia e lirë

--------------------------------------------------------------------------------
-- Module: Mbyllje diskutimi
-- 
-- Usage in wiki:
--   {{dmb|1|<decision>}}    or {{Mbyllje diskutimi|fillo|<decision>}}   (Start the discussion box)
--   {{dmb|2|<extra text>}}  or {{Mbyllje diskutimi|mbaro|<extra text>}} (Finish the discussion box)
--------------------------------------------------------------------------------

local p = {}

--------------------------------------------------------------------------------
-- 1. Utility
--------------------------------------------------------------------------------

local function normalize(text)
	text = mw.text.trim(text or "")
	text = mw.ustring.lower(text)
	text = mw.ustring.gsub(text, "[ë]", "e")
	text = mw.ustring.gsub(text, "%s+", "")
	return text
end

local function fileLink(filename)
	return string.format("[[File:%s|20px|link=]]", filename)
end

--------------------------------------------------------------------------------
-- 2. Basic Config
--------------------------------------------------------------------------------

local COLORS = {
	green = "#F5FFF5",
	red   = "#FFF5F5",
	grey  = "#EFEFEF",
	white = "#FFFFFF"
}

-- Template to embed the outcome message
local MSG_TEMPLATE = '<b>Ky diskutim është <u>mbyllur</u>, %s.</b>'

--------------------------------------------------------------------------------
-- 3. Outcomes (including fallback)
--    Each outcome has synonyms, a short message, an optional image, and a color.
--    If a user's decision doesn't match any synonyms, we use Fallback.
--------------------------------------------------------------------------------

local outcomes = {
		
	-- General decisions
	Per = {
		synonyms = {"p", "per", "pro", "aprovo", "aprovuar", "mirato", "miratuar"},
		message  = "rezultati ishte PËR",
		image    = "Symbol support vote.svg",
		color    = COLORS.green
	},
	Kunder = {
		synonyms = {"k", "kunder", "kundra", "moho", "mohuar", "refuzo", "refuzuar"},
		message  = "rezultati ishte KUNDËR",
		image    = "Symbol oppose vote.svg",
		color    = COLORS.red
	},
	Asnjanes = {
		synonyms = {"n", "asnjanes", "neutral"},
		message  = "rezultati ishte ASNJANËS",
		image    = "Symbol neutral vote.svg",
		color    = COLORS.grey
	},
		
	-- Deletion decisions
	Mbaje = {
		synonyms = {"mbaje", "te mbahet"},
		message  = "vendimi ishte TË MBAHET",
		image    = "Symbol keep vote.svg",
		color    = COLORS.green
	},
	Grise = {
		synonyms = {"grise", "te griset"},
		message  = "vendimi ishte TË GRISET",
		image    = "Symbol delete vote.svg",
		color    = COLORS.red
	},
	
	-- Featured and good articles decisions
	Hiqe = {
		synonyms = {"hiqe", "te hiqet"},
		message  = "vendimi ishte TË HIQET",
		image    = "Symbol unsupport star gold.svg",
		color    = COLORS.red
	},
	AP = {
		synonyms = {"ap", "artikull i perkryer"},
		message  = "artikulli u shpall I PËRKRYER",
		image    = "Cscr-featured.svg",
		color    = COLORS.green
	},
	JoAP = {
		synonyms = {"joap", "jo artikull i perkryer"},
		message  = "artikulli NUK u shpall i përkryer",
		image    = "Cscr-candidate.svg",
		color    = COLORS.red
	},
	AM = {
		synonyms = {"am", "artikull i mire"},
		message  = "artikulli u shpall I MIRË",
		image    = "Good article star 2.svg",
		color    = COLORS.green
	},
	JoAM = {
		synonyms = {"joam", "jo artikull i mire"},
		message  = "artikulli NUK u shpall i mirë",
		image    = "GA candidate.svg",
		color    = COLORS.red
	},
	
	-- Crat and admin decisions
	Krat = {
		synonyms = {"krat"},
		message  = "kandidatura për burokrat qe E SUKSESHME",
		image    = "Pictogram voting keep.svg",
		color    = COLORS.green
	},
	JoKrat = {
		synonyms = {"jokrat"},
		message  = "kandidatura për burokrat NUK qe e suksessme",
		image    = "Pictogram voting oppose.svg",
		color    = COLORS.red
	},
	Admin = {
		synonyms = {"admin"},
		message  = "kandidatura për administrator qe E SUKSESHME",
		image    = "Pictogram voting keep.svg",
		color    = COLORS.green
	},
	JoAdmin = {
		synonyms = {"joadmin"},
		message  = "kandidatura për administrator NUK qe e suksessme",
		image    = "Pictogram voting oppose.svg",
		color    = COLORS.red
	},
	KratShkarkim = {
		synonyms = {"kratshkarkim"},
		message  = "privilegjet e burokratit U HOQËN",
		image    = "Pictogram voting oppose.svg",
		color    = COLORS.red
	},
	JoKratShkarkim = {
		synonyms = {"jokratshkarkim"},
		message  = "privilegjet e burokratit NUK u hoqën",
		image    = "Pictogram voting keep.svg",
		color    = COLORS.red
	},
	AdminShkarkim = {
		synonyms = {"adminshkarkim"},
		message  = "privilegjet e administratorit U HOQËN",
		image    = "Pictogram voting oppose.svg",
		color    = COLORS.red
	},
	JoAdminShkarkim = {
		synonyms = {"joadminshkarkim"},
		message  = "privilegjet e administratorit NUK u hoqën",
		image    = "Pictogram voting keep.svg",
		color    = COLORS.red
	},
	KratDoreheqje = {
		synonyms = {"kratdoreheqje"},
		message  = "burokrati U DORËHOQ",
		image    = "Neutral icon C.svg",
		color    = COLORS.grey
	},
	AdminDoreheqje = {
		synonyms = {"admindoreheqje"},
		message  = "administratori U DORËHOQ",
		image    = "Neutral icon C.svg",
		color    = COLORS.grey
	},
	
	-- Fallback for unrecognized decisions
	Fallback = {
		synonyms = {},
		message  = "rezultati ishte: ???",
		image    = nil,
		color    = COLORS.white
	}
}

--------------------------------------------------------------------------------
-- 4. Build synonyms lookup
--------------------------------------------------------------------------------

local synonymsLookup = {}
for key, data in pairs(outcomes) do
	if key ~= "Fallback" then
		synonymsLookup[ normalize(key) ] = key
		for _, s in ipairs(data.synonyms or {}) do
			synonymsLookup[ normalize(s) ] = key
		end
	end
end

--------------------------------------------------------------------------------
-- 5. getOutcome
--------------------------------------------------------------------------------

local function getOutcome(decision)
	local norm = normalize(decision)
	local canonical = synonymsLookup[norm]
	if canonical and outcomes[canonical] then
		return outcomes[canonical]
	end
	-- Fallback
	local fb = outcomes.Fallback
	local msg = fb.message:gsub("%?%?%?", decision)
	return {
		message  = msg,
		image    = fb.image,
		color    = fb.color
	}
end

--------------------------------------------------------------------------------
-- 6. startHTML / finishHTML
--------------------------------------------------------------------------------

local function startHTML(outcome)
	local iconPart = outcome.image and (" " .. fileLink(outcome.image)) or ""
	local fullMsg = string.format(MSG_TEMPLATE, outcome.message) .. iconPart
	return string.format(
		'<div style="border:1px solid black; background-color:%s; padding:10px;">\n\t<i style="color:#000000; vertical-align:middle;">%s</i>',
		outcome.color,
		fullMsg
	)
end

local function finishHTML(extra)
	extra = extra or ""
	return "\n</div>" .. extra
end

--------------------------------------------------------------------------------
-- 7. Interpret the mode: "1"/"fillo" => start, "2"/"mbaro" => finish
--------------------------------------------------------------------------------

local function getMode(modeInput)
	local m = normalize(modeInput)
	if m == "1" or m == "fillo" then
		return "start"
	elseif m == "2" or m == "mbaro" then
		return "finish"
	else
		return "unknown"
	end
end

--------------------------------------------------------------------------------
-- 8. Main
--------------------------------------------------------------------------------

function p.main(frame)
	local userMode = frame.args[1] or ""
	local finalMode = getMode(userMode)
	
	if finalMode == "start" then
		local decision = frame.args[2] or ""
		local outcome = getOutcome(decision)
		return startHTML(outcome)
	elseif finalMode == "finish" then
		local extra = frame.args[2] or ""
		return finishHTML(extra)
	else
		return "Gabim në kod"
	end
end

return p