Modul:SisterProjectLink

Tento modul se používá pro vytváření odkazů na sesterské projekty. Jak přesně funguje, se můžete ptát třeba jeho tvůrce Danny B.


-- @brief--  Backend for sister projects linking templates.-- -- @author--  [[meta:User:Danny B.]]local _module = {}----------------------------------------local Error = require( "Module:Error" )local WikimediaProjects = require( "Module:WikimediaProjects" )function inTable ( val, tbl )for _, value in pairs( tbl ) doif ( value == val ) thenreturn trueendendreturn falseendlocal Params = {["autor"] = { textPrefix = "Autor ", linkPrefix = "Autor:" },["článek"] = { textPrefix = "Encyklopedický článek " },["dílo"] = { textPrefix = "Dílo " },["edice"] = { textPrefix = "Edice ", linkPrefix = "Edice:" },["galerie"] = { textPrefix = "Galerie " },["heslo"] = { textPrefix = "Slovníkové heslo " },["kategorie"] = { textPrefix = "Kategorie ", linkPrefix = "Category:" },["kniha"] = { textPrefix = "Kniha " },["kurs"] = { textPrefix = "Výukový kurs " },["osoba"] = { textPrefix = "Osoba " },["portál"] = { textPrefix = "Portál ", linkPrefix = "Portál:" },["průvodce"] = { textPrefix = "Průvodce " },["příloha"] = { textPrefix = "Příloha ", linkPrefix = "Příloha:" },["rozcestník"] = { textPrefix = "Rozcestník " },["taxon"] = { textPrefix = "Taxon " },["téma"] = { textPrefix = "Téma " },["úložiště"] = { textPrefix = "Úložiště vzdělávacích materiálů " },["zpráva"] = { textPrefix = "Zpráva " }}local ParamLists = {["commons"] = { "galerie", "kategorie" },["wikibooks"] = { "kategorie", "kniha" },["wikinews"] = { "kategorie", "zpráva" },["wikipedia"] = { "článek", "kategorie", "portál", "rozcestník" },["wikiquote"] = { "dílo", "kategorie", "osoba", "téma" },["wikisource"] = { "autor", "dílo", "kategorie", "rozcestník", "edice" },["wikispecies"] = { "kategorie", "taxon" },["wikiversity"] = { "kategorie", "kurs", "úložiště" },["wikivoyage"] = { "kategorie", "průvodce" },["wiktionary"] = { "heslo", "kategorie", "příloha" }}function _module.print( frame )local output = ""local parentFrame = frame:getParent()local moduleArgs = frame.argslocal templateArgs = {}local project = mw.text.trim( moduleArgs["1"] or "" )-- TODO: tohle je dost ošklivý side-effectif project == "wikiquote" thenParams["dílo"].linkPrefix = "Dílo:"elseParams["dílo"].linkPrefix = nilendif project == "" thenerror( "Missing 1. parameter (project name)" )elseif not WikimediaProjects[project] thenerror( "Unknown value „" .. project .. "“ of 1. parameter (project name)" )elselocal template = mw.text.trim( moduleArgs["2"] or "" )local errorData = { template = template == "" and WikimediaProjects[project].i18n.cs.name or template }local targetTypelocal targetlocal paramCount = 0local paramList = table.concat( ParamLists[project], "“, „" )for param, value in pairs( parentFrame.args ) doparamCount = paramCount + 1templateArgs[param] = mw.text.trim( value or "" )endif paramCount == 0 thenerrorData.text = "Chybí některý z parametrů „" .. paramList .. "“."errorData.category = "Přidat chybějící parametr"output = output .. Error.getText( errorData )elseif paramCount > 1 thenerrorData.text = "Příliš mnoho parametrů."errorData.category = "Upravit počet parametrů"output = output .. Error.getText( errorData )elsetargetType, target = next( templateArgs )if targetType == 1 thenerrorData.text = "Nespecifikovaný typ odkazu. Použijte některý z parametrů „" .. paramList .. "“."errorData.category = "Specifikovat cíl odkazu"output = output .. Error.getText( errorData )elseif not inTable( targetType, ParamLists[project] ) thenerrorData.text = "Neznámý parametr „" .. targetType .. "“ (možné parametry: „" .. paramList .. "“)."errorData.category = "Opravit parametr"output = output .. Error.getText( errorData )endendif output == "" thenoutput = output .. "<span class=\"sisterproject sisterproject-" .. project .."\">"output = output .. "<span class=\"sisterproject_image\">[[Soubor:" .. WikimediaProjects[project].common.logo .. "|16x16px|alt=|link=]]</span> "output = output .. "<span class=\"sisterproject_text\">"output = Params[targetType].textPrefix and output .. "<span class=\"sisterproject_text_prefix\">" .. Params[targetType].textPrefix .. "</span>" or outputoutput = output .. "<span class=\"sisterproject_text_target\">[[" .. WikimediaProjects[project].common.iwPrefix .. ":" .. ( Params[targetType].linkPrefix or "" ) .. target .. "|" .. target .. "]]</span>"output = output .. "<span class=\"sisterproject_text_suffix\">" .. ( Params[targetType].textSuffix or "" ) .. " " .. WikimediaProjects[project].i18n.cs.where .. "</span>"output = output .. "</span>"output = output .. "</span>"endendoutput = frame:preprocess( output )return outputend----------------------------------------return _module