Modul:Spielwiese
Zur Navigation springen
Zur Suche springen
Die Dokumentation für dieses Modul kann unter Modul:Spielwiese/Doku erstellt werden
local p = {}
local function printError(code)
return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
end
local function getChronoLink(pid)
local entity = mw.wikibase.getEntity()
if not entity then
return printError("entity-not-found")
end
-- prefer predecessor/successor
local qid, result
local chrono =
{
P155 = entity:getBestStatements('P155'),
P156 = entity:getBestStatements('P156')
}
if next(chrono["P155"])~=nil or next(chrono["P156"])~=nil then
if next(chrono[pid])~=nil then
qid = chrono[pid][1].mainsnak.datavalue.value.id
end
else
local series = entity:getBestStatements('P179')
if next(series)~=nil and next(series[1].qualifiers[pid])~=nil then
qid = series[1].qualifiers[pid][1].datavalue.value.id
end
end
if qid then
local temp = mw.wikibase.getBestStatements( qid, 'P1476' )
result = mw.wikibase.getLabel(qid)
local sitelink = mw.wikibase.getSitelink(qid)
if next(temp)~=nil then
local title = temp[1].mainsnak.datavalue.value.text
if string.find(result,title,0,true) then
result = title
end
end
if sitelink then
result = '[[' ..sitelink .. '|' .. result .. ']]'
end end
return result
end
function p.getPred(frame)
return getChronoLink('P155')
end
function p.getSucc(frame)
return getChronoLink('P156')
end
function p.description(frame)
local lemma = frame.args[1]
local wikidata_id
if lemma then
wikidata_id = mw.wikibase.getEntityIdForTitle(lemma) or ""
else wikidata_id = mw.wikibase.getEntityIdForCurrentPage() or ""
end
local description = mw.wikibase.getDescription(wikidata_id) or ""
return "Kurzbeschreibung: " .. description .. " ([[D:" .. wikidata_id .. "|Auf Wikidata bearbeiten]])"
end
-- Funktionen von Benutzer Antonsusi
-- Teilen einer Zeichenkette an enthaltenen Zeilenumbrüchen
local function GetLines(str)
local tbl = {};
local text = str;
local teil;
sep = '\n';
if #str == 0 then
return tbl;
end
text = text ..sep
for i = 1,32767 do -- while vermeiden, damit sich das im Testbetrieb nicht aufhängen kann, 32767 Zeilen sollten reichen.
pos = string.find(text,sep) or 0;
teil = string.sub(text,1,pos-1);
if pos < 1 then
break;
end
table.insert (tbl,teil);
text = string.sub(text,pos+1);
end
return tbl;
end
-- GetPage liest den Quelltext einer Seite aus und speichert die Zeilen in einer table.
-- Aufruf durch {{#invoke:Spielwiese|GetPage|<namespace>|<pagename>}}
function p.GetPage(frame)
local namespace = frame.args[1];
local title = frame.args[2];
local Seite = mw.title.makeTitle( namespace, title);
local Content = Seite:getContent()
local Lines = {};
local c = 0;
Text = mw.ustring.sub( Content, 1, 100); -- Begrenzung
Lines = GetLines(Content);
-- hier liegen die Zeilen als table vor. Es folgt testweise eine "Dummy-Ausgabe"
for i = 1,#Lines do
Lines[i] = Lines[i] ..'<br />';
end
local Info = table.concat(Lines)
return Info;
end
function p.stringcompare(frame)
return mw.ustring.len(frame.args[1]) .. '\n' .. string.len(frame.args[1]) .. '\n';
end
--
return p