Moduł:Przypisy
Przejdź do nawigacji
Przejdź do wyszukiwania
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Przypisy/opis
return { ["Przypisy"] = function(frame) --mw.logObject(frame:getParent():getTitle(), "parent:title") local result = {} local category = frame.args["kategoria"] local defaultGroup = frame.args["grupa"] local hasIgnoredFields = {} -- grupa przekazywana w polu o pustej nazwie -- aby docelowo zwolnić wszystkie nazwy na przypisy local group = frame:getParent().args[""] if group and string.match(group, "^=*$") then -- z wyjątkiem błednych wywołań w stylu "==" table.insert(hasIgnoredFields, ""); group = nil end -- alternatywnie do czasu przebotowania z pola o nazwie "grupa" if not group then group = frame:getParent().args["grupa"] if group and (#group == 0) then group = nil end end local function noArgs() for k, v in pairs(frame:getParent().args) do return false end return true end table.insert(result, '<div class="do-not-make-smaller refsection') if group or defaultGroup then local groupClass, _ = (group or defaultGroup) == "uwaga" and "uwagi ll-script ll-script-uwagi" or string.gsub(group or defaultGroup, ' ', '_') table.insert(result, " refsection-") table.insert(result, groupClass) end table.insert(result, '">') -- to jest lista przestarzałych pól w wywołaniach szablonów przypisów, -- które się jeszcze sporadycznie pojawiają w brudnopisach -- TODO docelowo lista będzie całkowicie usunięta local exceptions = { "colwidth", -- kopia z enwiki? do usunięcia "group", -- kopia z enwiki? do usunięcia "grupa", -- to tzeba zamienić na gołe '=wartość' "przypisy", -- a to całkiem usunąć "refs", -- kopia z enwiki? do usunięcia } local ignore = {} for i, v in ipairs(exceptions) do ignore[v] = true end local contents = {} for k, v in pairs(frame:getParent().args) do if (k == "") or ((type(k) == "number") and (k == 1)) then --mw.logObject( {k, v}, "nazwa grupy albo pole {{{1}}} puste lub z przypisami w stylu <ref name=...>") table.insert(contents, v) elseif (type(k) == "string") and not ignore[k] then -- pole o podanej nazwie tłumaczymy na przypis o takiej samej nazwie local ref = frame:extensionTag('ref', v, {name=k, group=group or defaultGroup}) --mw.logObject( {k, v, ref}, "indywidualny przypis") table.insert(contents, ref) else -- pole indeksowane lub mające nazwę wykluczoną z powodów historycznych --mw.logObject( {k, v}, "indeksowane pole z potencjalnymi przypisami w stylu <ref name=...>") table.insert(hasIgnoredFields, k) table.insert(contents, v) end end local references = frame:extensionTag('references', table.concat(contents), {group=group or defaultGroup, responsive="1"}) table.insert(result, references) if #hasIgnoredFields > 0 then table.insert(result, '<span class="problemy">') table.insert(result, mw.text.nowiki("{{")) local title = mw.title.new(frame:getParent():getTitle()) if title.namespace ~= 10 then table.insert(result, title.nsText) table.insert(result, ":") end table.insert(result, title.text) table.insert(result, mw.text.nowiki("}} Nieprawidłowe pola: ")) table.insert(result, mw.text.listToText(hasIgnoredFields)) table.insert(result, ". ") --mw.logObject({hasIgnoredFields, category}, "hasIgnoredFields and category") end table.insert(result, '</div>') if (#hasIgnoredFields > 0) and category then table.insert(result, category) end --mw.logObject(table.concat(result), "result") return table.concat(result) end, }