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: Zurückgesetzt
KKeine Bearbeitungszusammenfassung
Markierung: Zurückgesetzt
Zeile 40: Zeile 40:
local brackets
local brackets
local brackets2
local brackets2
if string.match (certraw, "%(") then
if certraw then
certraw, brackets = mw.ustring.match (certraw, "(.+)%((.-)%)")
if mw.ustring.match (certraw, "%(") then
certraw, brackets = mw.ustring.match (certraw, "(.+)%((.-)%)")
end
end
end
if certraw2 then
if certraw2 then
Zeile 51: Zeile 53:
local number
local number
local number2
local number2
if mw.ustring.match(certraw, "%d+") then
if certraw then
if mw.ustring.match(certraw, "%d+") then
number = mw.ustring.match(certraw, "(%d+)")
number = mw.ustring.match(certraw, "(%d+)")
else
else
number = 1
number = 1
end
end
end
if certraw2 then
if certraw2 then
Zeile 63: Zeile 67:
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 certraw then
if mw.ustring.match (certraw, key) then
certname = key
certname = key
end
end
end
if certraw2 then
if certraw2 then
Zeile 96: Zeile 102:
-- direct files
-- direct files
if not certtable[certname] then
if not certtable[certname] then
icon = certraw
icon = certraw or ""
else
else

Version vom 16. Juni 2025, 22:33 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)
--[=[
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 = {
		["S"] = {"silver", "silber"},
		["G"] = {"gold", "gold"},
		["P"] = {"platinum", "platin"},
		["D"] = {"diamond", "diamant"},
		["X"] = {"", ""},
	}
	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 mw.ustring.match (certraw, "%[%[Datei:") or mw.ustring.match (certraw, "%[%[File:") or mw.ustring.match (certraw, "%[%[Bild:") then
		icon = certraw
	end
	
	local certraw2
	if mw.ustring.match (certraw, ".%+") then
		certraw, certraw2 = mw.ustring.match (certraw, "(.+)%+(.+)")
	end

	-- find brackets
	local brackets
	local brackets2
	if certraw then
		if mw.ustring.match (certraw, "%(") then
			certraw, brackets = mw.ustring.match (certraw, "(.+)%((.-)%)")
		end
	end
	if certraw2 then
		if mw.ustring.match (certraw2, "%(") then
			certraw2, brackets2 = mw.ustring.match (certraw2, "(.+)%((.-)%)")
		end
	end
	
	local number
	local number2
	if certraw then
		if mw.ustring.match(certraw, "%d+") then
			number = mw.ustring.match(certraw, "(%d+)")
		else
			number = 1
		end
	end
	if certraw2 then
		number2 = mw.ustring.match(certraw2, "(%d+)") or 1
	end
	
	local certname
	local certname2
	for key, value in pairs (certtable) do
		if certraw then
			if mw.ustring.match (certraw, key) then
				certname = key
			end
		end
		if certraw2 then
			if mw.ustring.match (certraw2, key) 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 = mw.ustring.gsub(certtable[certname][2], "^%l", mw.ustring.upper)
	else
		capcertname = certname
	end
	if certtable[certname2] then
		capcertname2 = mw.ustring.gsub(certtable[certname2][2], "^%l", mw.ustring.upper)
	else
		capcertname2 = certname2 or ""
	end
	
	-- direct files
	if not certtable[certname] then
		icon = certraw or ""
	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