Modul:Datei: Unterschied zwischen den Versionen

Aus FürthWiki

K (Entfernte den Schutz von „Modul:Datei“)
(+ BeschreibungsMaxWortlänge)
Zeile 1: Zeile 1:
local p = {}
local p = {}
local c = require("Module:Common")
 
local com = require("Module:Common")
local str = require("Module:String")


function p.daten(frame, args)
function p.daten(frame, args)
Zeile 11: Zeile 13:
'<th colspan="4">' .. title .. '</th>'
'<th colspan="4">' .. title .. '</th>'
if not c.isEmpty(args.Genre) then
if not com.isEmpty(args.Genre) then
t = t .. '<tr>'..
t = t .. '<tr>'..
'<td>[[Attribut:Genre|Genre]]</td>' ..
'<td>[[Attribut:Genre|Genre]]</td>' ..
Zeile 23: Zeile 25:
a = 'Attribut'..i
a = 'Attribut'..i
w = 'Wert'..i
w = 'Wert'..i
if not c.isEmpty(args[a]) then
if not com.isEmpty(args[a]) then
if not c.isEmpty(args[w]) then
if not com.isEmpty(args[w]) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:'..args[a]..'|'..args[a]..']]</td>'..
'<td>[[Attribut:'..args[a]..'|'..args[a]..']]</td>'..
Zeile 42: Zeile 44:
end
end
if not c.isEmpty(args.Urheber) then
if not com.isEmpty(args.Urheber) then
t = t .. '<tr>'..
t = t .. '<tr>'..
'<td>[[Attribut:Urheber|Urheber]]</td>' ..
'<td>[[Attribut:Urheber|Urheber]]</td>' ..
Zeile 51: Zeile 53:
end
end
if not c.isEmpty(args.Quellangaben) then
if not com.isEmpty(args.Quellangaben) then
t = t .. '<tr>'..
t = t .. '<tr>'..
    '<td>[[Attribut:Quellangaben|Quellangaben]]</td>'..
    '<td>[[Attribut:Quellangaben|Quellangaben]]</td>'..
Zeile 58: Zeile 60:
end
end
if not c.isEmpty(args.Ort) then
if not com.isEmpty(args.Ort) then
t = t .. '<tr>'..
t = t .. '<tr>'..
'<td>[[Attribut:Ort|Ort]]</td>'..
'<td>[[Attribut:Ort|Ort]]</td>'..
Zeile 65: Zeile 67:
'<td><b>ausblenden:</b></td>'
'<td><b>ausblenden:</b></td>'
z = '<td>[[ZeigeNichtInOrt::Nein]]</td>'
z = '<td>[[ZeigeNichtInOrt::Nein]]</td>'
if not c.isEmpty(args.ZeigeNichtInOrt) then
if not com.isEmpty(args.ZeigeNichtInOrt) then
z = '<td>[[ZeigeNichtInOrt::'..args.ZeigeNichtInOrt..']]</td>'
z = '<td>[[ZeigeNichtInOrt::'..args.ZeigeNichtInOrt..']]</td>'
end
end
Zeile 71: Zeile 73:
end
end
if not c.isEmpty(args['Straße']) then
if not com.isEmpty(args['Straße']) then
t = t .. '<tr>' ..
t = t .. '<tr>' ..
'<td>[[Attribut:Straße|Straße]]</td>' ..
'<td>[[Attribut:Straße|Straße]]</td>' ..
Zeile 79: Zeile 81:
'<td><b>ausblenden:</b></td>'
'<td><b>ausblenden:</b></td>'
z = '<td>[[ZeigeNichtInStraße::Nein]]</td>'
z = '<td>[[ZeigeNichtInStraße::Nein]]</td>'
if not c.isEmpty(args['ZeigeNichtInStraße']) then
if not com.isEmpty(args['ZeigeNichtInStraße']) then
z = '<td>[[ZeigeNichtInStraße::'..args['ZeigeNichtInStraße']..']]</td>'
z = '<td>[[ZeigeNichtInStraße::'..args['ZeigeNichtInStraße']..']]</td>'
end
end
Zeile 85: Zeile 87:
end
end
if not c.isEmpty(extension) then
if not com.isEmpty(extension) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Dateiart|Dateiart]]</td>'..
'<td>[[Attribut:Dateiart|Dateiart]]</td>'..
Zeile 94: Zeile 96:
end  
end  
if not c.isEmpty(args.Erstellungsdatum) then
if not com.isEmpty(args.Erstellungsdatum) then
t = t .. '<tr>' ..
t = t .. '<tr>' ..
'<td>[[Attribut:Erstellungsdatum|Erstellungsdatum]]</td>' ..
'<td>[[Attribut:Erstellungsdatum|Erstellungsdatum]]</td>' ..
Zeile 105: Zeile 107:
end
end
if not c.isEmpty(args['ÜberDatum']) then
if not com.isEmpty(args['ÜberDatum']) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:ÜberDatum|Über Datum]]</td>'..
'<td>[[Attribut:ÜberDatum|Über Datum]]</td>'..
Zeile 116: Zeile 118:
end
end
if not c.isEmpty(args.Seitennummer) then
if not com.isEmpty(args.Seitennummer) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Seitennummer|Seitennummer]]</td>'..
'<td>[[Attribut:Seitennummer|Seitennummer]]</td>'..
Zeile 124: Zeile 126:
end
end
if not c.isEmpty(args.Signatur) then
if not com.isEmpty(args.Signatur) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Signatur|Signatur]]</td>'..
'<td>[[Attribut:Signatur|Signatur]]</td>'..
Zeile 131: Zeile 133:
end
end
if not c.isEmpty(args['Länge']) then
if not com.isEmpty(args['Länge']) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Länge|Länge]]</td>'..
'<td>[[Attribut:Länge|Länge]]</td>'..
Zeile 138: Zeile 140:
end
end


if not c.isEmpty(args.Lizenz) then
if not com.isEmpty(args.Lizenz) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Lizenz|Lizenz]]</td>'..
'<td>[[Attribut:Lizenz|Lizenz]]</td>'..
Zeile 145: Zeile 147:
end
end
if not c.isEmpty(args.UploadCommons) then
if not com.isEmpty(args.UploadCommons) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:UploadCommons|Upload zu Commons]]</td>'..
'<td>[[Attribut:UploadCommons|Upload zu Commons]]</td>'..
Zeile 152: Zeile 154:
end
end


if not c.isEmpty(args.Beschreibung) then
if not com.isEmpty(args.Beschreibung) then
t=t..'<tr>'..
t=t..'<tr>'..
'<td>[[Attribut:Beschreibung|Beschreibung]]</td>'..
'<td>[[Attribut:Beschreibung|Beschreibung]]</td>'..
'<td colspan="3">[[Beschreibung::' ..args.Beschreibung .. ']]</td>'..
'<td colspan="3">[[Beschreibung::' ..args.Beschreibung .. ']]</td>'..
'</tr>'
'</tr>'
mw.smw.set{["Beschreibungslänge"]=string.len(args.Beschreibung)}
mw.smw.set{["Beschreibungslänge"] = string.len(args.Beschreibung)}
mw.smw.set{["BeschreibungsMaxWortlänge"] = str.maxWordLen(args.Beschreibung)}
end
end

Version vom 23. November 2025, 11:02 Uhr

local p = {}

local com = require("Module:Common")
local str = require("Module:String")

function p.daten(frame, args)
	local title = mw.title.getCurrentTitle().text
	local extension = p.getExtension(title)
	local filekind = p.getFilekind(extension)
	local a, w, z
	
	local t = '<table class="wikitable">' ..
		'<th colspan="4">' .. title .. '</th>'
	
	if not com.isEmpty(args.Genre) then
		t = t .. '<tr>'..
			'<td>[[Attribut:Genre|Genre]]</td>' ..
			'<td colspan="3">'..frame:callParserFunction(
				'#arraymap', args.Genre, ';', 'x', '[[:Kategorie:x|x]] [[Kategorie:x]]') .. '</td>' ..
		'</tr>'
	end
	
	-- Liste Freiattribute und Werte auf
	for i = 1, 6 do
		a = 'Attribut'..i
		w = 'Wert'..i
		if not com.isEmpty(args[a]) then
			if not com.isEmpty(args[w]) then
				t=t..'<tr>'..
					'<td>[[Attribut:'..args[a]..'|'..args[a]..']]</td>'..
					'<td colspan="3">'
				if args[a] == 'Gebäude' then
					t=t..p.gebaeude(frame, args[w])
				else
					t=t..frame:callParserFunction(
						'#arraymap', args[w], ';', 'x', '[['..args[a]..'::x]]')
				end
				t=t..'</td>'..
				'</tr>'
			else
				t=t..frame:preprocess('[[Kategorie:Freiattribut-Fehler]]')
			end
		end
	end
	
	if not com.isEmpty(args.Urheber) then
		t = t .. '<tr>'..
			'<td>[[Attribut:Urheber|Urheber]]</td>' ..
			'<td colspan="3">'..frame:callParserFunction(
				'#arraymap', args['Urheber'], ';', 'x', '[[Urheber::x]]')..
			'</td>'..
		'</tr>'
	end
	
	if not com.isEmpty(args.Quellangaben) then
		t = t .. '<tr>'..
		    '<td>[[Attribut:Quellangaben|Quellangaben]]</td>'..
		    '<td colspan="3">[[Quellangaben::'..args.Quellangaben..']]</td>'..
		'</tr>'
	end
	
	if not com.isEmpty(args.Ort) then
		t = t .. '<tr>'..
			'<td>[[Attribut:Ort|Ort]]</td>'..
			'<td>' .. frame:callParserFunction(
				'#arraymap', args.Ort, ';', 'x', '[[Ort::x]]') ..'</td>'..
			'<td><b>ausblenden:</b></td>'
		z = '<td>[[ZeigeNichtInOrt::Nein]]</td>'
		if not com.isEmpty(args.ZeigeNichtInOrt) then
			z = '<td>[[ZeigeNichtInOrt::'..args.ZeigeNichtInOrt..']]</td>'
		end
		t = t .. z ..'</tr>'
	end
	
	if not com.isEmpty(args['Straße']) then
		t = t .. '<tr>' ..
			'<td>[[Attribut:Straße|Straße]]</td>' ..
			'<td>' .. frame:callParserFunction(
				'#arraymap', args['Straße'], ';', 'x', '[[Straße::x]]') 
		t = t .. '</td>' ..
			'<td><b>ausblenden:</b></td>'
		z = '<td>[[ZeigeNichtInStraße::Nein]]</td>'
		if not com.isEmpty(args['ZeigeNichtInStraße']) then
			z = '<td>[[ZeigeNichtInStraße::'..args['ZeigeNichtInStraße']..']]</td>'
		end
		t = t .. z .. '</tr>'
	end
	
	if not com.isEmpty(extension) then
		t=t..'<tr>'..
			'<td>[[Attribut:Dateiart|Dateiart]]</td>'..
			'<td>[[Dateiart::' .. filekind .. ']]</td>'..
			'<td>[[Attribut:Dateityp|Dateityp]]</td>'..
			'<td>[[Dateityp::' .. extension .. ']]</td>'..
		'</tr>'
	end 
	
	if not com.isEmpty(args.Erstellungsdatum) then
		t = t .. '<tr>' ..
			'<td>[[Attribut:Erstellungsdatum|Erstellungsdatum]]</td>' ..
			'<td colspan="3">' .. frame:expandTemplate{title='LinkFormDatum', args={
				args.Erstellungsdatum,
				'Erstellungsdatum',
				'Erstellungstag',
				'Erstellungsjahr'}} .. '</td>' ..
		'</tr>'
	end
	
	if not com.isEmpty(args['ÜberDatum']) then
		t=t..'<tr>'..
			'<td>[[Attribut:ÜberDatum|Über Datum]]</td>'..
			'<td colspan="3">'..frame:expandTemplate{title='LinkFormDatum', args={
				args['ÜberDatum'],
				'ÜberDatum',
				'ÜberTag',
				'ÜberJahr'}}..'</td>'..
		'</tr>'
	end
	
	if not com.isEmpty(args.Seitennummer) then
		t=t..'<tr>'..
			'<td>[[Attribut:Seitennummer|Seitennummer]]</td>'..
			'<td colspan="3">'..frame:callParserFunction(
				'#arraymap', args.Seitennummer, ';', 'x', '[[Seitennummer::x]]') ..'</td>'..
		'</tr>'
	end
	
	if not com.isEmpty(args.Signatur) then
		t=t..'<tr>'..
			'<td>[[Attribut:Signatur|Signatur]]</td>'..
			'<td colspan="3">[[Signatur::'..args.Signatur..']]</td>'..
		'</tr>'
	end
	
	if not com.isEmpty(args['Länge']) then
		t=t..'<tr>'..
			'<td>[[Attribut:Länge|Länge]]</td>'..
			'<td colspan="3">'..'[[Länge::'..args['Länge']..']]</td>'..
		'</tr>'
	end

	if not com.isEmpty(args.Lizenz) then
		t=t..'<tr>'..
			'<td>[[Attribut:Lizenz|Lizenz]]</td>'..
			'<td colspan="3">[[Lizenz::' .. args.Lizenz .. ']]</td>'..
		'</tr>'
	end
		
	if not com.isEmpty(args.UploadCommons) then
		t=t..'<tr>'..
			'<td>[[Attribut:UploadCommons|Upload zu Commons]]</td>'..
			'<td colspan="3">[[UploadCommons::' .. args.UploadCommons .. ']]</td>'..
		'</tr>'
	end

	if not com.isEmpty(args.Beschreibung) then
		t=t..'<tr>'..
			'<td>[[Attribut:Beschreibung|Beschreibung]]</td>'..
			'<td colspan="3">[[Beschreibung::' ..args.Beschreibung .. ']]</td>'..
		'</tr>'
		mw.smw.set{["Beschreibungslänge"] = string.len(args.Beschreibung)}
		mw.smw.set{["BeschreibungsMaxWortlänge"] = str.maxWordLen(args.Beschreibung)}
	end
	
	t=t..'<tr>'..
		'<td>[[Bild:IconSearch.svg|16px|semantisches Browsen|link=Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}]]</td>'..
		'<td colspan="3">[[Spezial:Durchsuchen/{{NAMESPACE}}:{{PAGENAME}}|semantisches Browsen]]</td>'..
	'</tr>'
	t=t..'</table>'
	return t
end 

function p.GetExtension(frame)
	-- #invoke wrapper
	return p.getExtension(frame.args[1])
end

function p.getExtension(filename)
	local extension = filename:match("^.+%.([^%.]+)$")
    return mw.ustring.lower(extension)
end

function p.GetFilekind(frame)
	-- #invoke wrapper
	return p.getFilekind(frame.args[1])
end

function p.getFilekind(filetype)
	local t = {
		["Bild"] = {"webp", "png", "gif", "jpg", "jpeg", "svg"},
		["Dokument"] = {"pdf"},
		["Audio"] = {"mp3", "ogg", "oga", "flac", "opus", "wav"},
		["Midi"] = {"midi", "mid"},
		["Video"] = {"webm", "mp4", "m4v", "ogv", "mpg", "mpeg"},
		["3D-Modell"] = {"obj", "glb", "gltf"},
	}
	for key, values in pairs(t) do
        for _, value in ipairs(values) do
            if value == filetype then
                return key  -- Bricht beide Schleifen ab und gibt den Key zurück
            end
        end
	end
	return ""  -- Gib leeren String zurück, wenn nichts gefunden wurde
end

function p.gebaeude(frame, wert)
    return frame:expandTemplate{title='Datei/Gebäude', args = {wert=wert} }
end

return p