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
K (Schützte „Modul:Vorlage:Literatur“: per Anfrage: https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=156076713&oldid=156073630 ([Bearbeiten=Nur Sichter] (unbeschränkt) [Verschieben=Nur Administ…) |
(2017-04-21) |
||
Zeile 1: | Zeile 1: | ||
− | local Serial = " | + | local Serial = "2017-04-21" |
--[=[ | --[=[ | ||
Unterstützung für {{Literatur}} | Unterstützung für {{Literatur}} | ||
Zeile 7: | Zeile 7: | ||
-- Global | -- Global | ||
local Zitation | local Zitation | ||
− | |||
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" }, | |
− | + | MonatTag = { s = "/Parameter Monat, Tag" }, | |
− | + | Temp1 = { s = "/Temp1" }, | |
− | + | Temp2 = { s = "/Temp2" }, | |
− | + | Temp3 = { s = "/Temp3" }, | |
− | + | Temp4 = { s = "/Temp4" }, | |
− | + | TitelP = { s = "/Parameter Titel-P" } | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local Fehler = false | local Fehler = false | ||
− | local | + | local Schrei |
− | + | local Export = { } | |
− | |||
Zeile 167: | Zeile 35: | ||
end | end | ||
end -- falsch() | end -- falsch() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Zeile 256: | Zeile 77: | ||
Doppelt = { s = "Mehrfache Angabe von Parametern", | Doppelt = { s = "Mehrfache Angabe von Parametern", | ||
k = "Parameter" }, | k = "Parameter" }, | ||
− | + | MonatTag = { k = "MonatTag" }, | |
− | MonatTag | + | Temp1 = { k = "Temp1" }, |
− | + | Temp2 = { k = "Temp2" }, | |
− | Temp1 | + | Temp3 = { k = "Temp3" }, |
− | Temp2 | + | Temp4 = { k = "Temp4" }, |
− | Temp3 | + | TitelP = { k = "TitelP" } |
− | Temp4 | ||
− | TitelP | ||
} | } | ||
end | end | ||
Zeile 303: | Zeile 122: | ||
for k, v in pairs( Fehler ) do | for k, v in pairs( Fehler ) do | ||
if v.e then | if v.e then | ||
− | + | Schrei = string.format( "%s%s*** %s: %s", | |
− | + | Schrei or "", | |
− | sep = " " | + | sep, |
+ | v.s or "", | ||
+ | v.e ) | ||
+ | sep = " " | ||
end | end | ||
end -- for k, v | end -- for k, v | ||
− | |||
end | end | ||
for k, v in pairs( Kategorien ) do | for k, v in pairs( Kategorien ) do | ||
Zeile 323: | Zeile 144: | ||
return r | return r | ||
end -- fehlerliste() | end -- fehlerliste() | ||
+ | |||
+ | |||
+ | |||
+ | local folder = function () | ||
+ | -- Parameter-Konfiguration laden | ||
+ | local s = string.format( "Module:%s/params", Selbst ) | ||
+ | local lucky, params = pcall( mw.loadData, s ) | ||
+ | if type( params ) == "table" then | ||
+ | Export.params = Export.flat( params ) | ||
+ | else | ||
+ | error( string.format( "[[%s]] fehlt", s ) ) | ||
+ | end | ||
+ | end -- folder() | ||
Zeile 330: | Zeile 164: | ||
− | + | Export.flat = function ( adapt ) | |
− | -- | + | -- Deep copy |
− | if | + | -- Parameter: |
− | + | -- adapt -- something | |
+ | -- returns atom value, or deep copy of a table with no metatable | ||
+ | local r | ||
+ | if type( adapt ) == "table" then | ||
+ | r = { } | ||
+ | for k, v in pairs( adapt ) do | ||
+ | r[ k ] = Export.flat( v ) | ||
+ | end -- for k, v | ||
+ | else | ||
+ | r = adapt | ||
end | end | ||
− | end -- | + | return r |
+ | end -- Export.flat() | ||
− | + | -- local Titel = function ( args ) | |
+ | -- -- OBSOLET nach Bereinigung im ANR | ||
+ | -- if args[ "Titel-P" ] then | ||
+ | -- fehler( "TitelP" ) | ||
+ | -- end | ||
+ | -- end -- Titel() | ||
+ | |||
+ | |||
+ | |||
+ | Export.Datum = function ( args ) | ||
local r = args.Jahr | local r = args.Jahr | ||
local shit | local shit | ||
Zeile 378: | Zeile 231: | ||
end | end | ||
if o and tostring( o.month ) ~= s then | if o and tostring( o.month ) ~= s then | ||
− | fehler( " | + | fehler( "MonatTag", "'Monat'=" .. args.Monat ) |
r = false | r = false | ||
elseif s ~= args.Monat and | elseif s ~= args.Monat and | ||
"0" .. s ~= args.Monat then | "0" .. s ~= args.Monat then | ||
− | fehler( " | + | fehler( "MonatTag", "'Monat'=" .. args.Monat ) |
end | end | ||
end | end | ||
Zeile 391: | Zeile 244: | ||
end | end | ||
if tostring( o.dom ) ~= s then | if tostring( o.dom ) ~= s then | ||
− | + | shit = "'Tag'=" .. args.Tag | |
r = false | r = false | ||
elseif s ~= args.Tag and | elseif s ~= args.Tag and | ||
"0" .. s ~= args.Tag then | "0" .. s ~= args.Tag then | ||
− | fehler( " | + | fehler( "MonatTag", "'Tag'=" .. args.Tag ) |
end | end | ||
end | end | ||
Zeile 401: | Zeile 254: | ||
shit = "'Tag' ohne 'Monat'" | shit = "'Tag' ohne 'Monat'" | ||
r = false | r = false | ||
− | |||
− | |||
end | end | ||
if r and o then | if r and o then | ||
Zeile 417: | Zeile 268: | ||
args.Kommentar = string.format( "o. J. %s%s", | args.Kommentar = string.format( "o. J. %s%s", | ||
args.Jahr, args.Kommentar ) | args.Jahr, args.Kommentar ) | ||
− | + | fehler( "Wert", "'Datum'=o.J." ) | |
− | fehler( " | ||
else | else | ||
if args.Datum then | if args.Datum then | ||
Zeile 436: | Zeile 286: | ||
end | end | ||
return r | return r | ||
− | end -- | + | end -- Export.Datum() |
Zeile 447: | Zeile 297: | ||
args.BandReihe = args.Band | args.BandReihe = args.Band | ||
args.Band = nil | args.Band = nil | ||
+ | fehler( "Temp4" ) | ||
end | end | ||
end -- Band() | end -- Band() | ||
Zeile 459: | Zeile 310: | ||
args.NummerReihe = args.Nummer | args.NummerReihe = args.Nummer | ||
args.Nummer = nil | args.Nummer = nil | ||
+ | fehler( "Temp4" ) | ||
end | end | ||
end -- Nummer() | end -- Nummer() | ||
+ | |||
+ | |||
+ | |||
+ | local Herausgeber = function ( args ) | ||
+ | -- OBSOLET nach Bereinigung im ANR | ||
+ | if args.Hrsg and not args.Sammelwerk and not args.HrsgReihe then | ||
+ | if args.Reihe then | ||
+ | args.HrsgReihe = args.Hrsg | ||
+ | args.Hrsg = nil | ||
+ | fehler( "Temp4" ) | ||
+ | else | ||
+ | fehler( "Temp3" ) | ||
+ | end | ||
+ | end | ||
+ | end -- Herausgeber() | ||
Zeile 475: | Zeile 342: | ||
end | end | ||
end -- Sprache() | end -- Sprache() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Zeile 514: | Zeile 350: | ||
-- args -- table mit Vorlagenparametern | -- args -- table mit Vorlagenparametern | ||
-- Rückgabewert: string mit formatierter Zitation | -- Rückgabewert: string mit formatierter Zitation | ||
− | local pars = Zitation.filter( args, | + | local lucky, pars, r, schrott |
− | + | pars = Zitation.filter( args, Export.params.valid ) | |
− | + | -- Titel( pars ) -- OBSOLET | |
− | + | Export.Datum( pars ) | |
Band( pars ) | Band( pars ) | ||
Nummer( pars ) | Nummer( pars ) | ||
Sprache( pars ) | Sprache( pars ) | ||
− | + | Zitation.filler( pars, Export.params.map ) | |
− | |||
− | Zitation.filler( pars, | ||
if Zitation.o then | if Zitation.o then | ||
Zitation.fill( "leise", "leiser", true ) | Zitation.fill( "leise", "leiser", true ) | ||
Zeile 531: | Zeile 365: | ||
r, schrott = Zitation.format() | r, schrott = Zitation.format() | ||
if schrott then | if schrott then | ||
− | + | Schrei = Schrei or "" | |
+ | Schrei = Schrei .. Zitation.fault( schrott ) | ||
end | end | ||
return r | return r | ||
Zeile 549: | Zeile 384: | ||
Zitation = r.Zitation() | Zitation = r.Zitation() | ||
Zitation.frame = frame | Zitation.frame = frame | ||
− | r | + | folder() |
+ | r = format( arglist ) | ||
else | else | ||
fehler( "Modul", r ) | fehler( "Modul", r ) | ||
end | end | ||
− | return r .. fehlerliste() .. | + | return r .. fehlerliste() .. Zitation.failure( Schrei ) |
end -- f() | end -- f() | ||
Zeile 562: | Zeile 398: | ||
function p.export() | function p.export() | ||
− | return | + | folder() |
− | + | return Export | |
− | |||
end | end | ||
Version vom 1. Mai 2017, 21:42 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 = "2017-04-21"
--[=[
Unterstützung für {{Literatur}}
]=]
-- Global
local Zitation
local Selbst = "Vorlage:Literatur"
local KategorieBeginn = "Wikipedia:Vorlagenfehler"
local Kategorien =
{ Intern = { s = "/Interner Fehler" },
Parameter = { s = "/Parameterfehler" },
MonatTag = { s = "/Parameter Monat, Tag" },
Temp1 = { s = "/Temp1" },
Temp2 = { s = "/Temp2" },
Temp3 = { s = "/Temp3" },
Temp4 = { s = "/Temp4" },
TitelP = { s = "/Parameter Titel-P" }
}
local Fehler = false
local Schrei
local Export = { }
local function falsch( a )
-- Zeige Fehler mit class=error unbedingt
-- Parameter:
-- a -- string mit Text
if Schrei then
Schrei = string.format( "%s<br>%s", Schrei, a )
else
Schrei = a
end
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" },
MonatTag = { k = "MonatTag" },
Temp1 = { k = "Temp1" },
Temp2 = { k = "Temp2" },
Temp3 = { k = "Temp3" },
Temp4 = { k = "Temp4" },
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
Schrei = string.format( "%s%s*** %s: %s",
Schrei or "",
sep,
v.s or "",
v.e )
sep = " "
end
end -- for k, v
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 folder = function ()
-- Parameter-Konfiguration laden
local s = string.format( "Module:%s/params", Selbst )
local lucky, params = pcall( mw.loadData, s )
if type( params ) == "table" then
Export.params = Export.flat( params )
else
error( string.format( "[[%s]] fehlt", s ) )
end
end -- folder()
-------------------------------------------------------------------------
Export.flat = function ( adapt )
-- Deep copy
-- Parameter:
-- adapt -- something
-- returns atom value, or deep copy of a table with no metatable
local r
if type( adapt ) == "table" then
r = { }
for k, v in pairs( adapt ) do
r[ k ] = Export.flat( v )
end -- for k, v
else
r = adapt
end
return r
end -- Export.flat()
-- local Titel = function ( args )
-- -- OBSOLET nach Bereinigung im ANR
-- if args[ "Titel-P" ] then
-- fehler( "TitelP" )
-- end
-- end -- Titel()
Export.Datum = function ( args )
local r = args.Jahr
local shit
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
shit = "'Monat'=" .. args.Monat
if args.Nummer then
args.Nummer = string.format( "%s, %s",
args.Nummer,
args.Monat )
else
args.Nummer = args.Monat
end
if not args.Datum then
args.Datum = r
end
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( "MonatTag", "'Monat'=" .. args.Monat )
r = false
elseif s ~= args.Monat and
"0" .. s ~= args.Monat then
fehler( "MonatTag", "'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
shit = "'Tag'=" .. args.Tag
r = false
elseif s ~= args.Tag and
"0" .. s ~= args.Tag then
fehler( "MonatTag", "'Tag'=" .. args.Tag )
end
end
elseif args.Tag then
shit = "'Tag' ohne 'Monat'"
r = false
end
if r and o then
r = o
args.Datum = o
end
elseif r:match( "^%[%d%d%d%d%]$" ) then
args.Datum = r:match( "^%[(%d+)%]$" )
if args.Kommentar then
args.Kommentar = ", " .. args.Kommentar
else
args.Kommentar = ""
end
args.Kommentar = string.format( "o. J. %s%s",
args.Jahr, args.Kommentar )
fehler( "Wert", "'Datum'=o.J." )
else
if args.Datum then
fehler( "Wert", "'Jahr'=" .. args.Jahr )
else
args.Datum = args.Jahr
end
end
elseif args.Monat or args.Woche or args.Tag then
fehler( "Konflikt", "'Jahr' fehlt bei spezifischem Datum" )
else
r = args.Datum
end
if shit then
fehler( "MonatTag" )
falsch( shit )
end
return r
end -- Export.Datum()
local Band = function ( args )
-- OBSOLET nach Bereinigung im ANR
if args.Reihe and
not args.BandReihe and
not args.Sammelwerk then
args.BandReihe = args.Band
args.Band = nil
fehler( "Temp4" )
end
end -- Band()
local Nummer = function ( args )
-- OBSOLET nach Bereinigung im ANR
if args.Reihe and
not args.NummerReihe and
not args.Sammelwerk then
args.NummerReihe = args.Nummer
args.Nummer = nil
fehler( "Temp4" )
end
end -- Nummer()
local Herausgeber = function ( args )
-- OBSOLET nach Bereinigung im ANR
if args.Hrsg and not args.Sammelwerk and not args.HrsgReihe then
if args.Reihe then
args.HrsgReihe = args.Hrsg
args.Hrsg = nil
fehler( "Temp4" )
else
fehler( "Temp3" )
end
end
end -- Herausgeber()
local Sprache = function ( args )
-- OBSOLET nach Bereinigung im ANR
if args.Originalsprache and
not args.Originaltitel and
not args["Übersetzer"] and
not args.Sprache then
args.Sprache = args.Originalsprache
args.Originalsprache = nil
fehler( "Temp1" )
end
end -- Sprache()
local format = function ( args )
-- Analysiere Argumente und bilde formatierte Zitation
-- Parameter:
-- args -- table mit Vorlagenparametern
-- Rückgabewert: string mit formatierter Zitation
local lucky, pars, r, schrott
pars = Zitation.filter( args, Export.params.valid )
-- Titel( pars ) -- OBSOLET
Export.Datum( pars )
Band( pars )
Nummer( pars )
Sprache( pars )
Zitation.filler( pars, Export.params.map )
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
Schrei = Schrei or ""
Schrei = Schrei .. 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
folder()
r = format( arglist )
else
fehler( "Modul", r )
end
return r .. fehlerliste() .. Zitation.failure( Schrei )
end -- f()
-- Export
local p = {}
function p.export()
folder()
return Export
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