Zum Inhalt springen

„Modul:Musikcharts/certifications“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
[gesichtete Version][gesichtete Version]
Inhalt gelöscht Inhalt hinzugefügt
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
handle brackets as only input
Zeile 2: Zeile 2:
p.certicon = function (frame, certification, icontype, size)
p.certicon = function (frame, certification, icontype, size)
--[=[
ACHTUNG! Diese Funktion enthält noch einen Bug!
Bei bestimmten Aufrufbedingungen wird die Variable "certraw" gelöscht (also nil zugewiesen)
und die Funktion mw.ustring.match erhält nil statt String!
]=]
local certtable = {
local certtable = {
["S"] = {"silver", "silber"},
["S"] = {"silver", "silber"},
Zeile 27: Zeile 23:
local icon
local icon
if mw.ustring.match (certraw, "%[%[Datei:") or mw.ustring.match (certraw, "%[%[File:") or mw.ustring.match (certraw, "%[%[Bild:") then
if string.match (certraw, "%[%[Datei:") or string.match (certraw, "%[%[File:") or string.match (certraw, "%[%[Bild:") then
icon = certraw
icon = certraw
end
end
local certraw2
local certraw2
if mw.ustring.match (certraw, ".%+") then
if string.match (certraw, ".%+") then
certraw, certraw2 = mw.ustring.match (certraw, "(.+)%+(.+)")
certraw, certraw2 = string.match (certraw, "(.+)%+(.+)")
end
end


Zeile 39: Zeile 35:
local brackets
local brackets
local brackets2
local brackets2
if string.match (certraw, "%(") then
if string.match (certraw, ".+%(") then
certraw, brackets = mw.ustring.match (certraw, "(.+)%((.-)%)")
certraw, brackets = string.match (certraw, "(.+)%((.-)%)")
end
end
if certraw2 then
if certraw2 then
if mw.ustring.match (certraw2, "%(") then
if string.match (certraw2, ".+%(") then
certraw2, brackets2 = mw.ustring.match (certraw2, "(.+)%((.-)%)")
certraw2, brackets2 = string.match (certraw2, "(.+)%((.-)%)")
end
end
end
end
Zeile 50: Zeile 46:
local number
local number
local number2
local number2
if mw.ustring.match(certraw, "%d+") then
if string.match(certraw, "%d+") then
number = mw.ustring.match(certraw, "(%d+)")
number = string.match(certraw, "(%d+)")
else
else
number = 1
number = 1
end
end
if certraw2 then
if certraw2 then
number2 = mw.ustring.match(certraw2, "(%d+)") or 1
number2 = string.match(certraw2, "(%d+)") or 1
end
end
Zeile 62: Zeile 58:
local certname2
local certname2
for key, value in pairs (certtable) do
for key, value in pairs (certtable) do
if mw.ustring.match (certraw, key) then
if string.match (certraw, key) and not string.match (certraw, "%(") then
certname = key
certname = key
end
end
if certraw2 then
if certraw2 then
if mw.ustring.match (certraw2, key) then
if string.match (certraw2, key) and not string.match (certraw2, "%(") then
certname2 = key
certname2 = key
end
end
Zeile 83: Zeile 79:
local capcertname2
local capcertname2
if certtable[certname] then
if certtable[certname] then
capcertname = mw.ustring.gsub(certtable[certname][2], "^%l", mw.ustring.upper)
capcertname = string.gsub(certtable[certname][2], "^%l", string.upper)
else
else
capcertname = certname
capcertname = certname
end
end
if certtable[certname2] then
if certtable[certname2] then
capcertname2 = mw.ustring.gsub(certtable[certname2][2], "^%l", mw.ustring.upper)
capcertname2 = string.gsub(certtable[certname2][2], "^%l", string.upper)
else
else
capcertname2 = certname2 or ""
capcertname2 = certname2 or ""

Version vom 18. Juni 2025, 01:27 Uhr

Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


local p = {}
	
p.certicon = function (frame, certification, icontype, size)
	
	local certtable = {
		["S"] = {"silver", "silber"},
		["G"] = {"gold", "gold"},
		["P"] = {"platinum", "platin"},
		["D"] = {"diamond", "diamant"}
	}
	local numbers =  { "", "Double", "Triple", "Quadruple", "Quintuple", "Sextuple", "Septuple", "Octuple", "Nonuple", "Decuple" }
	local numbers2 = { "", "Doppel", "Drei", "Vier", "Fünf", "Sechs", "Sieben", "Acht", "Neun", "Zehn", "Elf", "Zwölf" }
	
	local certraw = certification or frame.args[1]
	local icontype = icontype or frame.args["icontype"]
	
	-- delete strip markers
	if certraw then
		certraw = mw.text.unstrip( certraw )
	else
		certraw = ""
	end
	
	local icon
	if string.match (certraw, "%[%[Datei:") or string.match (certraw, "%[%[File:") or string.match (certraw, "%[%[Bild:") then
		icon = certraw
	end
	
	local certraw2
	if string.match (certraw, ".%+") then
		certraw, certraw2 = string.match (certraw, "(.+)%+(.+)")
	end

	-- find brackets
	local brackets
	local brackets2
	if string.match (certraw, ".+%(") then
		certraw, brackets = string.match (certraw, "(.+)%((.-)%)")
	end
	if certraw2 then
		if string.match (certraw2, ".+%(") then
			certraw2, brackets2 = string.match (certraw2, "(.+)%((.-)%)")
		end
	end
	
	local number
	local number2
	if string.match(certraw, "%d+") then
		number = string.match(certraw, "(%d+)")
	else
		number = 1
	end
	if certraw2 then
		number2 = string.match(certraw2, "(%d+)") or 1
	end
	
	local certname
	local certname2
	for key, value in pairs (certtable) do
		if string.match (certraw, key) and not string.match (certraw, "%(") then
			certname = key
		end
		if certraw2 then
			if string.match (certraw2, key) and not string.match (certraw2, "%(") then
				certname2 = key
			end
		end
	end
	
	local oldicon
	local tooltip
	local tooltip2
	local newicon
	local texticon
	local supicon
	local caption
	local caption2
	local capcertname
	local capcertname2
	if certtable[certname] then
		capcertname = string.gsub(certtable[certname][2], "^%l", string.upper)
	else
		capcertname = certname
	end
	if certtable[certname2] then
		capcertname2 = string.gsub(certtable[certname2][2], "^%l", string.upper)
	else
		capcertname2 = certname2 or ""
	end
	
	-- direct files
	if not certtable[certname] then
		icon = certraw
	else
		
	-- create tooltip and caption
		if tonumber(number) > 1 then
			if tonumber(number) == 2 then
				tooltip = numbers2[tonumber(number)] .. certtable[certname][2]
			elseif tonumber(number) < 13 then
				tooltip = numbers2[tonumber(number)] .. "fach" .. certtable[certname][2]
			else
				tooltip = number .. "-fach-" .. capcertname
			end
			caption = number .. "×&nbsp;" .. capcertname
		else
			tooltip = capcertname
			caption = tooltip
		end
		if brackets then
			tooltip = tooltip .. " (" .. brackets .. ")"
			caption = caption .. " (" .. brackets .. ")"
		end
		if certraw2 then
			if tonumber(number2) > 1 then
				if tonumber(number2) == 2 then
					tooltip2 = numbers2[tonumber(number2)] .. certtable[certname2][2]
				elseif tonumber(number2) < 13 then
					tooltip2 = numbers2[tonumber(number2)] .. "fach" .. certtable[certname2][2]
				else
					tooltip2 = number2 .. "-fach-" .. capcertname2
				end
				caption2 = number2 .. "×&nbsp;" .. capcertname2
			else
				tooltip2 = capcertname2
				caption2 = tooltip2
			end
		end
		if brackets2 then
			tooltip2 = tooltip2 .. " (" .. brackets2 .. ")"
			caption2 = caption2 .. " (" .. brackets2 .. ")"
		end
		if tooltip2 then
			tooltip = tooltip .. "&nbsp;+ " .. tooltip2
		end
		if caption2 then
			caption = caption .. "&nbsp;+ " .. caption2
		end
		
	-- create old files
		local certfile = ""
		local certfile2 = ""
--[[		if tonumber(number) > 1 then			ONLY SINGLE FILES
			if tonumber(number) < 11 then
				certfile = numbers[tonumber(number)] .. " "
			else
				certfile = "Decuple "
			end
		end
		if certraw2 then
			if tonumber(number2) > 1 then
				if tonumber(number2) < 11 then
					certfile2 = numbers[tonumber(number2)] .. " "
				else
					certfile2 = "Decuple "
				end
			end
		end ]]
		certfile = certfile .. certtable[certname][1] .. " record icon.svg"
		if certraw2 and certtable[certname2] then
			certfile = certfile .. "|15px|link=]][[File:" .. certfile2 .. certtable[certname2][1] .. " record icon.svg"
		end
		
	-- create old icon style
		oldicon = "<div class='charts-certc'>[[File:" .. certfile .. "|15px|link=|alt=" .. tooltip .. "]]"
		oldicon = oldicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"
		
	-- create new icon style
		if not size then
			size = "17"
		end
		newicon = "<div class='charts-certc'><div class='charts-cert'>[[File:" .. certtable[certname][1] .. " record icon2.svg|"
		newicon = newicon .. size .. "px|link=|alt=" .. tooltip .. "]]"
		if tonumber(number) then
			if tonumber(number) > 1 then
				newicon = newicon .. "<div class='charts-certn'"
				if tonumber(number2) then
					newicon = newicon .. " style='left:50%; z-index:10;'"
				end
				newicon = newicon .. ">×" .. number .. "</div>"
			end
		end
		newicon = newicon .. "</div>"
		if certraw2 and certtable[certname2] then
			newicon = newicon .. "<div class='charts-cert' style='margin-left:-8px'>[[File:" .. certtable[certname2][1] .. " record icon2.svg|"
			newicon = newicon .. size .. "px|link=|alt=" .. tooltip .. "]]"
			if tonumber(number2) then
				if tonumber(number2) > 1 then
					newicon = newicon .. "<div class='charts-certn'>×" .. number2 .. "</div>"
				end
			end
			newicon = newicon .. "</div>"
		end
		newicon = newicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"
		
	-- create sup icon style
		supicon = "<div class='charts-certc'><div class='charts-cert'>[[File:" .. certtable[certname][1] .. " record icon.svg|15px|link=|alt=" .. tooltip .. "]]"
		if tonumber(number) then
			if tonumber(number) > 1 then
				supicon = supicon .. "<div class='charts-certn'"
				if tonumber(number2) then
					supicon = supicon .. " style='left:50%; z-index:10;'"
				end
				supicon = supicon .. ">×" .. number .. "</div>"
			end
		end
		supicon = supicon .. "</div>"
		if certraw2 and certtable[certname2] then
			supicon = supicon .. "<div class='charts-cert' style='margin-left:-5px'>[[File:" .. certtable[certname2][1] .. " record icon.svg|15px|link=|alt=" .. tooltip .. "]]"
			if tonumber(number2) then
				if tonumber(number2) > 1 then
					supicon = supicon .. "<div class='charts-certn'>×" .. number2 .. "</div>"
				end
			end
			supicon = supicon .. "</div>"
		end
		supicon = supicon .. "<span class='charts-certt'>" .. tooltip .."<i></i></span></div>"

	-- create text icon
		texticon = "[[File:" .. certfile .. "|15px|link=]]&nbsp;" .. caption
	end
	
	local ret = ""
	if icon then 
		ret = ret .. "<div style='display:inline-block;'>" .. icon .. "</div>"
	elseif icontype == "text" then
		ret = texticon
	elseif icontype == "sup" then
		ret = supicon
	elseif icontype == "new" then
		ret = ret .. newicon
	elseif icontype == "old" then
		ret = ret .. oldicon
	else
		ret = ret .. supicon
	end
	

	return ret

end

return p