Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.
Modul:Vorlage:Literatur: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(2016-05-20) |
(2016-05-28) |
||
Zeile 1: | Zeile 1: | ||
− | local Serial = "2016-05- | + | local Serial = "2016-05-28" |
--[=[ | --[=[ | ||
Unterstützung für {{Literatur}} | Unterstützung für {{Literatur}} | ||
Zeile 7: | Zeile 7: | ||
-- Global | -- Global | ||
local Zitation | local Zitation | ||
+ | local Schrei = "" | ||
local Selbst = "Vorlage:Literatur" | local Selbst = "Vorlage:Literatur" | ||
local KategorieBeginn = "Wikipedia:Vorlagenfehler" | local KategorieBeginn = "Wikipedia:Vorlagenfehler" | ||
local Kategorien = | local Kategorien = | ||
− | + | { Intern = { s = "/Interner Fehler" }, | |
− | + | Parameter = { s = "/Parameterfehler" }, | |
− | + | ISBNistFormalFalsch = { s = "/Parameter ISBNistFormalFalsch" }, | |
− | + | JahrSeitenzahl = { s = "/Jahr mit Seitenzahl" }, | |
− | + | Monat = { s = "/Parameter Monat" }, | |
+ | TitelP = { s = "/Parameter Titel-P" } | ||
+ | } | ||
local ParValid = { | local ParValid = { | ||
Autor = { Autorin=true, | Autor = { Autorin=true, | ||
Zeile 22: | Zeile 25: | ||
Herausgeberin=true }, | Herausgeberin=true }, | ||
Titel = { ["Titel-P"] = { low=true } }, | Titel = { ["Titel-P"] = { low=true } }, | ||
+ | ["Titel-P"] = true, | ||
TitelErg = true, | TitelErg = true, | ||
Sammelwerk = true, | Sammelwerk = true, | ||
Zeile 47: | Zeile 51: | ||
Fundstelle = true, | Fundstelle = true, | ||
ISBN = true, | ISBN = true, | ||
− | ISBNformalFalsch = | + | ISBNformalFalsch = true, |
− | ISBNistFormalFalsch = true, | + | ISBNdefekt = true, |
+ | ISBNistFormalFalsch = { ISBNistFormalFalsch = { leave=true } }, | ||
ISSN = true, | ISSN = true, | ||
ISSNformalFalsch = true, | ISSNformalFalsch = true, | ||
Zeile 107: | Zeile 112: | ||
ISBN = { "id", "ISBN" }, | ISBN = { "id", "ISBN" }, | ||
ISBNformalFalsch = { "id", "ISBNfalsch" }, | ISBNformalFalsch = { "id", "ISBNfalsch" }, | ||
+ | ISBNdefekt = { "id", "ISBNdefekt" }, | ||
ISSN = { "id", "ISSN" }, | ISSN = { "id", "ISSN" }, | ||
ISSNformalFalsch = { "id", "ISSNfalsch" }, | ISSNformalFalsch = { "id", "ISSNfalsch" }, | ||
Zeile 115: | Zeile 121: | ||
Originaltitel = { "orig", "Titel" }, | Originaltitel = { "orig", "Titel" }, | ||
Originalsprache = { "orig", "Sprache" }, | Originalsprache = { "orig", "Sprache" }, | ||
+ | Originalort = { "orig", "Ort" }, | ||
+ | Originaljahr = { "orig", "Jahr" }, | ||
["Übersetzer"] = { "orig", "Translator" }, | ["Übersetzer"] = { "orig", "Translator" }, | ||
OrtEA = { "ed1", "Ort" }, | OrtEA = { "ed1", "Ort" }, | ||
Zeile 141: | Zeile 149: | ||
local FunLit = { } | local FunLit = { } | ||
− | --|Lizenznummer nicht genutzt und nicht länger unterstützt | + | --|Lizenznummer nicht genutzt und nicht länger unterstützt, oder doch? |
+ | |||
+ | |||
+ | |||
+ | local function falsch( a ) | ||
+ | -- Formatiere Fehler mit class=error unbedingt | ||
+ | -- Parameter: | ||
+ | -- a -- string mit Text | ||
+ | Schrei = string.format( "%s <span class=\"error\">%s</span>", | ||
+ | Schrei, a ) | ||
+ | end -- falsch() | ||
local function fault( a ) | local function fault( a ) | ||
− | -- Formatiere Fehler mit class=error | + | -- Formatiere Fehler mit class=error einstellungsabhängig |
-- Parameter: | -- Parameter: | ||
-- a -- string mit Text | -- a -- string mit Text | ||
Zeile 153: | Zeile 171: | ||
r = Zitation.fault( a ) | r = Zitation.fault( a ) | ||
else | else | ||
− | r = | + | r = falsch( a ) |
end | end | ||
return r | return r | ||
Zeile 185: | Zeile 203: | ||
k = "Parameter" }, | k = "Parameter" }, | ||
ISBNistFormalFalsch = { k = "ISBNistFormalFalsch" }, | ISBNistFormalFalsch = { k = "ISBNistFormalFalsch" }, | ||
+ | JahrSeitenzahl = { k = "JahrSeitenzahl" }, | ||
+ | Monat = { k = "Monat" }, | ||
TitelP = { k = "TitelP" } | TitelP = { k = "TitelP" } | ||
} | } | ||
Zeile 253: | Zeile 273: | ||
local Titel = function ( args ) | local Titel = function ( args ) | ||
− | -- OBSOLET nach Bereinigung im ANR | + | -- OBSOLET nach Bereinigung im ANR; Kat zeitweise ausgesetzt |
− | if args[ "Titel-P" ] then | + | if args[ "Titel-P" ] and false then |
fehler( "TitelP" ) | fehler( "TitelP" ) | ||
end | end | ||
Zeile 281: | Zeile 301: | ||
else | else | ||
fehler( "Wert", "'Monat'=" .. args.Monat ) | fehler( "Wert", "'Monat'=" .. args.Monat ) | ||
+ | if args.Nummer then | ||
+ | args.Nummer = string.format( "%s, %s", | ||
+ | args.Nummer, | ||
+ | args.Monat ) | ||
+ | else | ||
+ | args.Nummer = args.Monat | ||
+ | end | ||
+ | fehler( "Monat" ) | ||
r = false | r = false | ||
end | end | ||
Zeile 291: | Zeile 319: | ||
fehler( "Wert", "'Monat'=" .. args.Monat ) | fehler( "Wert", "'Monat'=" .. args.Monat ) | ||
r = false | r = false | ||
− | elseif s ~= args.Monat then | + | elseif s ~= args.Monat and |
+ | "0" .. s ~= args.Monat then | ||
fehler( "Format", "'Monat'=" .. args.Monat ) | fehler( "Format", "'Monat'=" .. args.Monat ) | ||
end | end | ||
Zeile 303: | Zeile 332: | ||
fehler( "Wert", "'Tag'=" .. args.Tag ) | fehler( "Wert", "'Tag'=" .. args.Tag ) | ||
r = false | r = false | ||
− | elseif s ~= args.Tag then | + | elseif s ~= args.Tag and |
+ | "0" .. s ~= args.Tag then | ||
fehler( "Format", "'Tag'=" .. args.Tag ) | fehler( "Format", "'Tag'=" .. args.Tag ) | ||
end | end | ||
Zeile 317: | Zeile 347: | ||
else | else | ||
fehler( "Wert", "'Jahr'=" .. args.Jahr ) | fehler( "Wert", "'Jahr'=" .. args.Jahr ) | ||
+ | if not args.Datum then | ||
+ | args.Datum = args.Jahr | ||
+ | if args.Jahr:match( ", S%. ?%d" ) then | ||
+ | fehler( "JahrSeitenzahl" ) | ||
+ | end | ||
+ | end | ||
end | end | ||
elseif args.Monat or args.Woche or args.Tag then | elseif args.Monat or args.Woche or args.Tag then | ||
Zeile 353: | Zeile 389: | ||
-- OBSOLET nach Bereinigung im ANR | -- OBSOLET nach Bereinigung im ANR | ||
if args.ISBNistFormalFalsch then | if args.ISBNistFormalFalsch then | ||
− | + | local scream = "*** 'ISBNistFormalFalsch' veraltet;" .. | |
− | + | " siehe [[WP:ISBNformalFalsch]]" | |
− | + | falsch( scream ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
fehler( "ISBNistFormalFalsch" ) | fehler( "ISBNistFormalFalsch" ) | ||
end | end | ||
Zeile 409: | Zeile 440: | ||
fehler( "Modul", r ) | fehler( "Modul", r ) | ||
end | end | ||
− | return r .. fehlerliste() | + | return r .. fehlerliste() .. Schrei |
end -- f() | end -- f() | ||
Version vom 30. Mai 2016, 01:35 Uhr
Vorlagenprogrammierung | Diskussionen | Lua | Unterseiten | ||
Modul | Deutsch
|
Modul: | Dokumentation |
Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus |
Dieses Modul (und die Dokumentation) basieren (teilweise) auf Modul:Vorlage:Literatur aus der freien Enzyklopädie Wikipedia und steht unter der GNU Lizenz für freie Dokumentation und der Creative Commons Attribution/Share Alike. Auf Wikipedia ist eine Liste der Autoren verfügbar. Weiteres zum Import aus Wikipedia siehe Seite Imedwiki:Import aus Wikipedia.
local Serial = "2016-05-28"
--[=[
Unterstützung für {{Literatur}}
]=]
-- Global
local Zitation
local Schrei = ""
local Selbst = "Vorlage:Literatur"
local KategorieBeginn = "Wikipedia:Vorlagenfehler"
local Kategorien =
{ Intern = { s = "/Interner Fehler" },
Parameter = { s = "/Parameterfehler" },
ISBNistFormalFalsch = { s = "/Parameter ISBNistFormalFalsch" },
JahrSeitenzahl = { s = "/Jahr mit Seitenzahl" },
Monat = { s = "/Parameter Monat" },
TitelP = { s = "/Parameter Titel-P" }
}
local ParValid = {
Autor = { Autorin=true,
Autoren=true,
Autorinnen=true },
Hrsg = { Herausgeber = { low=true },
Herausgeberin=true },
Titel = { ["Titel-P"] = { low=true } },
["Titel-P"] = true,
TitelErg = true,
Sammelwerk = true,
WerkErg = true,
Reihe = true,
BandReihe = true,
HrsgReihe = true,
NummerReihe = true,
Band = true,
Nummer = true,
Auflage = true,
Verlag = true,
Ort = true,
Datum = true,
Jahr = { Datum=true },
Monat = { Datum=true,
Woche=true },
Woche = { Datum=true },
Tag = { Datum=true,
Woche=true },
Kapitel = true,
Seiten = true,
Spalten = true,
ArtikelNr = true,
Fundstelle = true,
ISBN = true,
ISBNformalFalsch = true,
ISBNdefekt = true,
ISBNistFormalFalsch = { ISBNistFormalFalsch = { leave=true } },
ISSN = true,
ISSNformalFalsch = true,
Umfang = true,
Sprache = true,
Kommentar = true,
Originaltitel = true,
Originalsprache = true,
Originalort = true,
Originaljahr = true,
["Übersetzer"] = { ["Übersetzerin"]=true },
VerlagEA = true,
OrtEA = true,
JahrEA = true,
arXiv = { Arxiv = { low=true },
arxiv = { low=true } },
bibcode = true,
DOI = true,
DNB = true,
JSTOR = true,
LCCN = true,
Lizenznummer = true,
OCLC = true,
PMC = true,
PMID = true,
URN = true,
ZDB = true,
ID = true,
Online = true,
Abruf = { Zugriff = { low=true } },
Format = true,
KBytes = true,
Zitat = true,
Typ = true,
Vorlage = true }
local ParMap = {
Autor = { "bas", "Autor" },
Hrsg = { "bas", "Hrsg" },
Titel = { "bas", "Titel" },
TitelErg = { "bas", "TitelErg" },
Sammelwerk = { "bas", "Werk" },
WerkErg = { "bas", "WerkErg" },
Reihe = { "serie", "Reihe" },
BandReihe = { "serie", "Band" },
HrsgReihe = { "serie", "Hrsg" },
NummerReihe = { "serie", "Nummer" },
Band = { "print", "Band" },
Nummer = { "print", "Nummer" },
Auflage = { "print", "Auflage" },
Verlag = { "bas", "Verlag" },
Ort = { "print", "Ort" },
Datum = { "bas", "Datum" },
Kapitel = { "fragment", "Kapitel" },
Seiten = { "fragment", "Seiten" },
Spalten = { "fragment", "Spalten" },
ArtikelNr = { "fragment", "ArtikelNr" },
Fundstelle = { "fragment", "Fundstelle" },
ISBN = { "id", "ISBN" },
ISBNformalFalsch = { "id", "ISBNfalsch" },
ISBNdefekt = { "id", "ISBNdefekt" },
ISSN = { "id", "ISSN" },
ISSNformalFalsch = { "id", "ISSNfalsch" },
Umfang = { "print", "Umfang" },
Sprache = { "bas", "Sprache" },
Kommentar = { "bas", "Kommentar" },
Zitat = { "bas", "Zitat" },
Originaltitel = { "orig", "Titel" },
Originalsprache = { "orig", "Sprache" },
Originalort = { "orig", "Ort" },
Originaljahr = { "orig", "Jahr" },
["Übersetzer"] = { "orig", "Translator" },
OrtEA = { "ed1", "Ort" },
JahrEA = { "ed1", "Jahr" },
VerlagEA = { "ed1", "Verlag" },
Online = { "www", "Weblink" },
Abruf = { "www", "Abruf" },
Format = { "www", "Format" },
KBytes = { "www", "KBytes" },
arXiv = { "id", "arXiv" },
bibcode = { "id", "bibcode" },
DOI = { "id", "DOI" },
DNB = { "id", "DNB" },
JSTOR = { "id", "JSTOR" },
LCCN = { "id", "LCCN" },
Lizenznummer = { "id", "Lizenznummer" },
OCLC = { "id", "OCLC" },
PMC = { "id", "PMC" },
PMID = { "id", "PMID" },
URN = { "id", "URN" },
ZDB = { "id", "ZDB" },
ID = { "id", "ID" },
Typ = { "leise", "Typ" },
Vorlage = { "leise", "Vorlage" } }
local Fehler = false
local FunLit = { }
--|Lizenznummer nicht genutzt und nicht länger unterstützt, oder doch?
local function falsch( a )
-- Formatiere Fehler mit class=error unbedingt
-- Parameter:
-- a -- string mit Text
Schrei = string.format( "%s <span class=\"error\">%s</span>",
Schrei, a )
end -- falsch()
local function fault( a )
-- Formatiere Fehler mit class=error einstellungsabhängig
-- Parameter:
-- a -- string mit Text
local r
if type( Zitation ) == "table" then
r = Zitation.fault( a )
else
r = falsch( a )
end
return r
end -- fault()
local function fehler( art, anzeige )
-- Ein Fehler ist aufgetreten
-- Parameter:
-- art -- string mit Schlüsselwort zum Typ
-- anzeige -- string mit Einzelheiten, oder nil
local t
if not Fehler then
Fehler = { Intern = { s = "Interner Fehler",
k = "Intern" },
Modul = { s = "Modul-Seite fehlt",
k = "Intern" },
Vorlage = { s = "Vorlagen-Seite fehlt",
k = "Intern" },
Format = { s = "Parameterformat" },
Konflikt = { s = "Parameterkonflikt",
k = "Parameter" },
Parameter = { s = "Parameterfehler",
k = "Parameter" },
Pflicht = { s = "Pflichtparameter fehlt",
k = "Parameter" },
Wert = { s = "Werte ungültig",
k = "Parameter" },
Doppelt = { s = "Mehrfache Angabe von Parametern",
k = "Parameter" },
ISBNistFormalFalsch = { k = "ISBNistFormalFalsch" },
JahrSeitenzahl = { k = "JahrSeitenzahl" },
Monat = { k = "Monat" },
TitelP = { k = "TitelP" }
}
end
t = Fehler[ art ]
if t then
if anzeige then
local s = mw.text.nowiki( anzeige )
if t.e then
t.e = string.format( "%s; %s", t.e, s )
else
t.e = s
end
end
if t.k then
local wk = Kategorien[ t.k ]
if wk then
wk.e = true
else
Fehler.Intern.e = "Wartungskat " .. wk
Kategorien.Intern.e = true
end
end
else
Fehler.Intern.e = string.format( "fehler(%s) %s",
art, anzeige or "???" )
Kategorien.Intern.e = true
end
end -- fehler()
local function fehlerliste()
-- Auflistung aller Fehlermeldungen und Kategorien
-- Rückgabewert: string mit formatiertem Ergebnis
local r = ""
local s
if Fehler then
local sep = ""
for k, v in pairs( Fehler ) do
if v.e then
r = string.format( "%s%s*** %s: %s",
r, sep, v.s or "", v.e )
sep = " "
end
end -- for k, v
r = "<br />" .. fault( r )
end
for k, v in pairs( Kategorien ) do
if v.e then
if v.s:sub( 1, 1 ) == "/" then
s = Selbst
else
s = ""
end
r = string.format( "%s[[Kategorie:%s/%s%s]]",
r, KategorieBeginn, s, v.s )
end
end -- for k, v
return r
end -- fehlerliste()
-------------------------------------------------------------------------
local Titel = function ( args )
-- OBSOLET nach Bereinigung im ANR; Kat zeitweise ausgesetzt
if args[ "Titel-P" ] and false then
fehler( "TitelP" )
end
end -- Titel()
FunLit.Datum = function ( args )
local r = args.Jahr
if r then
if r:match( "^%d+$" ) then
local DateTime = Zitation.fetch( "DateTime" )
local o = DateTime( r )
if args.Woche and o then
o.week = tonumber( args.Woche )
if tostring( o.week ) ~= args.Woche then
fehler( "Wert", "'Woche'=" .. args.Woche )
r = false
end
elseif args.Monat then
local s
if args.Monat:match( "%l" ) then
local dm = DateTime( args.Monat )
if dm and o and dm.month then
o.month = dm.month
else
fehler( "Wert", "'Monat'=" .. args.Monat )
if args.Nummer then
args.Nummer = string.format( "%s, %s",
args.Nummer,
args.Monat )
else
args.Nummer = args.Monat
end
fehler( "Monat" )
r = false
end
else
s = args.Monat:match( "^0?(1?%d)%.?$" )
if s and o then
o.month = tonumber( s )
end
if o and tostring( o.month ) ~= s then
fehler( "Wert", "'Monat'=" .. args.Monat )
r = false
elseif s ~= args.Monat and
"0" .. s ~= args.Monat then
fehler( "Format", "'Monat'=" .. args.Monat )
end
end
if o and o.month and args.Tag then
s = args.Tag:match( "^0?([123]?%d)%.?$" )
if s then
o.dom = tonumber( s )
end
if tostring( o.dom ) ~= s then
fehler( "Wert", "'Tag'=" .. args.Tag )
r = false
elseif s ~= args.Tag and
"0" .. s ~= args.Tag then
fehler( "Format", "'Tag'=" .. args.Tag )
end
end
elseif args.Tag then
fehler( "Konflikt", "'Tag' ohne 'Monat'" )
r = false
end
if r and o then
r = o
args.Datum = o
end
else
fehler( "Wert", "'Jahr'=" .. args.Jahr )
if not args.Datum then
args.Datum = args.Jahr
if args.Jahr:match( ", S%. ?%d" ) then
fehler( "JahrSeitenzahl" )
end
end
end
elseif args.Monat or args.Woche or args.Tag then
fehler( "Konflikt", "'Jahr' fehlt bei spezifischem Datum" )
else
r = args.Datum
end
return r
end -- FunLit.Datum()
local Band = function ( args )
if args.Reihe and
not args.BandReihe and
not args.Sammelwerk then
args.BandReihe = args.Band
args.Band = nil
end
end -- Band()
local Nummer = function ( args )
if args.Reihe and
not args.NummerReihe and
not args.Sammelwerk then
args.NummerReihe = args.Nummer
args.Nummer = nil
end
end -- Nummer()
FunLit.ISBN = function ( args )
-- OBSOLET nach Bereinigung im ANR
if args.ISBNistFormalFalsch then
local scream = "*** 'ISBNistFormalFalsch' veraltet;" ..
" siehe [[WP:ISBNformalFalsch]]"
falsch( scream )
fehler( "ISBNistFormalFalsch" )
end
end -- FunLit.ISBN()
local format = function ( args )
-- Analysiere Argumente und bilde formatierte Zitation
-- Parameter:
-- args -- table mit Vorlagenparametern
-- Rückgabewert: string mit formatierter Zitation
local pars = Zitation.filter( args, ParValid )
local r, schrott
Titel( pars ) -- OBSOLET
FunLit.Datum( pars )
Band( pars )
Nummer( pars )
FunLit.ISBN( pars ) -- OBSOLET
Zitation.filler( pars, ParMap )
if Zitation.o then
Zitation.fill( "leise", "leiser", true )
Zitation.fill( "leise", "Vorlage", pars.Vorlage or Selbst )
Zitation.o.coins = true
end
r, schrott = Zitation.format()
if schrott then
r = r .. Zitation.fault( schrott )
end
return r
end -- format()
local function f( arglist, frame )
-- Hauptfunktion zur Steuerung des Gesamtablaufs
-- Parameter:
-- arglist -- table, mit Vorlagenparametern
-- frame -- object, oder nil
-- Rückgabewert: string mit formatiertem Gesamtergebnis
-- einschließlich Fehlerliste und Kategorien
local lucky, r = pcall( require, "Modul:Zitation" )
if type( r ) == "table" then
Zitation = r.Zitation()
Zitation.frame = frame
r = format( arglist )
else
fehler( "Modul", r )
end
return r .. fehlerliste() .. Schrei
end -- f()
-- Export
local p = {}
function p.export()
return { f = FunLit,
parMap = ParMap,
parValid = ParValid }
end
function p.test( a )
local lucky, r = pcall( f, a )
return r
end
function p.f( frame )
local lucky, r = pcall( f, frame:getParent().args, frame )
if not lucky then
fehler( "Intern", r )
r = fehlerliste()
end
return r
end
function p.failsafe()
return Serial
end
return p