Moduuli:Sisarprojektit
[ muokkaa ]
Moduuli tulostaa sisarprojektilistan ja sitä käytetään artikkeleissa mallineen {{sisarprojektit}} avulla. Mikäli parametrien arvona on "-", kyseistä kohtaa ei tulosteta.
{{Sisarprojektit|wikidata=Q33 |commons = Turku |wikinews = Suomi |wikiquote = - |wikispecies = Kissa |meta = Main_page |mediawiki = Main_page |wikiversity = Wikiopistossa |wikisource = Wikiaineistossa |wikibooks = Wikikirjastossa |wikivoyage = :de:Finland |wiktionary = Suo |wiki = Wikipediassa }} |
local sisterprojects = {}
-- Example usage:
-- {{#invoke:Sisarprojektit|get|wikidata=Q33|wikinews=Suomi|Wikivoyage=en:Finland}}
-- Render Wikidata and rkylinks
function render_row(project, page,imagecss, labelcss)
local ret="";
projectnames={
commons = 'Commonsissa',
wikinews = 'Wikiuutisissa',
wikiquote = 'Wikisitaateissa',
wikispecies = 'Wikilajeissa',
meta = 'Metassa',
mediawiki = 'Mediawiki.org:ssa',
wikiversity = 'Wikiopistossa',
wikisource = 'Wikiaineistossa',
wikibooks = 'Wikikirjastossa',
wikivoyage = 'Wikimatkoissa',
wiktionary = 'Wikisanakirjassa',
wikidata = 'Wikidatassa',
wiki = 'Wikipediassa'
}
pagenames={
commons = 'Kuvia',
wikinews = 'Uutisia',
wikiquote = 'Sitaattikokoelmia',
wikispecies = 'Laji',
meta = 'Keskustelu',
mediawiki = 'Ohjeita',
wikiversity = 'Oppimisympäristö',
wikisource = 'Lähdetekstejä',
wikibooks = 'Oppikirjoja',
wikivoyage = 'Paikka',
wiktionary = 'Määritelmiä',
wikidata = 'Kohde',
wiki = 'Wikipediassa'
}
imagenames={
commons = '[[File:Commons-logo.svg|27x27px|middle|link=|alt=]]',
wikinews = '[[File:Wikinews-logo.svg|27x27px|middle|link=|alt=]]',
wikiquote = '[[File:Wikiquote-logo.svg|27x27px|middle|link=|alt=]]',
wikispecies = '[[File:Wikispecies-logo.svg|27x27px|middle|link=|alt=]]',
meta = '[[File:Wikimedia Community Logo.svg|27x27px|middle|link=|alt=]]',
mediawiki = '[[File:MediaWiki-logo.svg|27x27px|middle|link=|alt=]]',
wikiversity = '[[File:Wikiversity-logo-Snorky.svg|27x27px|middle|link=|alt=]]',
wikisource = '[[File:Wikisource-logo.svg|27x27px|middle|link=|alt=]]',
wikibooks = '[[File:Wikibooks-logo.svg|27x27px|middle|link=|alt=]]',
wikivoyage = '[[File:Wikivoyage-Logo-v3-icon.svg|27x27px|middle|link=|alt=]]',
wiktionary = '[[File:Wiktionary-logo-v2.svg|27x27px|middle|link=|alt=]]',
wikidata = '[[File:Wikidata-logo.svg|27x27px|middle|link=|alt=]]',
wiki = 'Wikipediassa'
}
if projectnames[project] and pagenames[project] and imagenames[project] then
local image="<span style='".. imagecss .."'>".. imagenames[project] .."</span>";
local label="<span style='".. labelcss .."'>[[" .. page .."|" .. pagenames[project] .."]] " .. projectnames[project] .."</span>";
ret="<li>".. image .. label .."</li>"
else
return "[[Luokka:Viallinen sisarprojektimalline]]"
end
return ret
end
-- Function tries to get items P373 value from wikidata
-- If P373 doesn't exist then it loops through properties
-- and tries to get their P373 values.
function sisterprojects.get(frame)
local id= frame.args['wikidata']
local targetlangs={"fi", "en", "sv"}
local targetprojects={
commons=false,
wikinews=true,
wikiquote=true,
wikispecies=false,
meta=false,
-- mediawiki=false,
wikiversity=true,
wikisource=true,
wikibooks=true,
wikivoyage=true,
wiktionary=true,
-- wikidata=false,
-- wiki=true
}
local shortnames={
wikinews="n",
wikiquote="q",
wikiversity="v",
wikisource="s",
wikibooks="b",
wikivoyage="voy",
wiktionary="wikt",
wikispecies="species",
meta="m",
mediawiki="mw",
}
-- CSS rules
local listcss="border-top:1px solid #aaa; padding-top: 0.75em;";
local labelcss="display: inline-block; margin-left: 4px; width: 182px; vertical-align: middle;";
local imagecss="display: inline-block; width: 31px; line-height: 31px; vertical-align: middle; text-align: center;";
-- Output
local foundprojects={};
local out="";
-- Get wikidata item
if id == nil or id == "" then
entity = mw.wikibase.getEntityObject()
else
entity = mw.wikibase.getEntityObject(id);
end
-- Check if there is any sitelinks
if not entity or not entity.sitelinks then
return nil
end
-- Find suitable sitelinks
for project,multilang in pairs(targetprojects) do
if multilang then
for m, lang in pairs(targetlangs) do
local key=lang .. project;
if entity.sitelinks[key] then
foundprojects[project]=":" .. project ..":" .. lang ..":".. entity.sitelinks[key]["title"]
break;
end
end
else
local key= project;
if key=="commons" then
key="commonswiki";
end
if entity.sitelinks[key] then
foundprojects[project]=":" .. project ..":".. entity.sitelinks[key]["title"]
end
end
end
if foundprojects["commons"] == nil then
-- Check commonscat
if entity.claims then
if entity.claims["P373"] then
for i, j in pairs(entity.claims["P373"]) do
foundprojects["commons"]=":commons:category:" .. j["mainsnak"]["datavalue"]["value"]
break;
end
end
end
end
-- Commons cat template parameter handler
if frame.args["commonscat"] and frame.args["commonscat"] ~= "" then
foundprojects["commons"]=":commons:category:" .. frame.args[project];
end
-- Render sitelinks
for project,multilang in pairs(targetprojects) do
-- Local overrides
if frame.args[project] then
if frame.args[project] ~= "" then
if frame.args[project] == "-" then
foundprojects[project]="-"
elseif multilang == true then
foundprojects[project]=":fi:" ..shortnames[project] ..":" .. frame.args[project];
else
foundprojects[project]=":" ..project ..":" .. frame.args[project];
end
end
end
-- Render if not locally disabled
if foundprojects[project] and foundprojects[project] ~="-" then
out=out .. render_row(project, foundprojects[project], imagecss, labelcss)
end
end
-- wrap to ul -tag if we got something
if out ~= "" then
out = "<ul style='".. listcss .."'>" .. out .."</ul>";
end
return out
end
return sisterprojects