Module:Sandbox/trappist the monk/cite wikisource explained

require ('strict');

local excluded_parameters_t =

----------------------------< L I N K _ M A K E >------------------------------------------------------------

local function link_make (language, link, chapter, anchor, label, noicon) local link_markup_t = ; table.insert (link_markup_t, (noicon and ''); -- pipe to separate link from label table.insert (link_markup_t, label); -- add the label table.insert (link_markup_t, ']]'); -- close the link markup return table.concat (link_markup_t); -- make a big string and doneend

----------------------------< M A I N >----------------------------------------------------------------------

local function main (frame) local args_t = require ('Module:Arguments').getArgs (frame); if not (args_t.title or args_t.plaintitle or args_t['script-title'] or args_t[1]) then return '

{{cite wikisource}}: |title=, |plaintitle=, |script-title=, or required (help)'; end if args_t[1] then args_t.title = args_t[1]; args_t[1] = nil; end if args_t[2] then args_t.author = args_t[2]; args_t[2] = nil; end if args_t[3] then args_t.language = args_t[3]; args_t.wslanguage = args_t[3]; args_t[3] = nil; end local cite_params_t = ; -- this will hold the parameters passed to local prescript = ; -- empty string for concatenation if args_t.firsticon or args_t.iconfirst then prescript = ' '; end if args_t.prescript or args_t.vb then prescript = prescript .. 'This article incorporates text from a publication now in the public domain: '; end

local _debug = args_t._debug; local anchor = args_t.anchor; local chapter = args_t.chapter or args_t.contribution; local label = args_t.title or args_t[1]; local language = args_t.wslanguage or args_t[3]; local link = args_t.wslink or args_t.title or args_t[1]; -- different for chapter local link_chapter = args_t.wslink or args_t.title or args_t.plaintitle or args_t[1]; -- different for chapter local noicon = args_t.noicon; local plainchapter = args_t.plainchapter; local plaintitle = args_t.plaintitle; local scan = args_t.scan; local wsat = args_t.wsat; local wsat_label = args_t.at or args_t.wsat; local wspage = args_t.wspage; local wspage_label = args_t.page or args_t.wspage; local wspages = args_t.wspages; local wspages_label = args_t.pages or args_t.wspages; for _, param in ipairs (excluded_parameters_t) do args_t[param] = nil; -- unset because no longer needed end if plaintitle then cite_params_t.title = plaintitle; elseif link then -- create |title= parameter only when appropriate cite_params_t.title = link_make (language, link, nil, anchor, label, noicon); args_t.title = nil; -- unset because no longer needed end -- insource locator parameters override cs1|2 locator parameters cite_params_t.at = (wsat and link_make (language, link, chapter, wsat, wsat_label, noicon)) or args_t.at; args_t.at = nil; -- unset because no longer needed cite_params_t.page = (wspage and link_make (language, link, chapter, wspage, wspage_label, noicon)) or args_t.page; args_t.page = nil; -- unset because no longer needed cite_params_t.pages = (wspages and link_make (language, link, chapter, wspages, wspages_label, noicon)) or args_t.pages; args_t.pages = nil; -- unset because no longer needed

if chapter or plainchapter then -- create |chapter= parameter only when appropriate cite_params_t.chapter = plainchapter or link_make (language, link_chapter, chapter, anchor, chapter, noicon); args_t.chapter = nil; -- unset because no longer needed end cite_params_t.via = (args_t.nolink and 'Wikisource') or 'Wikisource'; args_t.via = nil; -- unset because ignored cite_params_t.mode = args_t.mode or 'cs1'; args_t.mode = nil; -- unset because no longer needed

cite_params_t.language = language or args_t.language or args_t.lang; args_t.language = nil; -- unset because no longer needed args_t.lang = nil; -- unset because no longer needed if args_t['script-title'] then -- create |script-title= parameter only when appropriate TODO: |script-chapter=? local script_title = args_t['script-title']; args_t['script-title'] = nil; -- unset because no longer needed local script_lang, script_title = script_title:match ('^(%a%a%a?:)(.+)'); -- split into required language prefix and non-Latn-script text cite_params_t['script-title'] = table.concat ; end

for param, value in pairs (args_t) do -- if has any other parameters, copy them to cite_params_t[param] = value; end if scan then -- build scan link if necessary scan = table.concat end

if _debug then -- show the resultant cs1|2 as wikitext as a sequence local template_t = ; -- we will assemble the template here for param, value in pairs (cite_params_t) do -- for each parameter name and assigned value table.insert (template_t, table.concat); -- make a single string so that we can sort end table.sort (template_t); -- ascending sort

table.insert (template_t, 1, ')); end

local output = ; -- init with prescript table.insert (output, frame:expandTemplate); -- TODO: make this smart enough to call either of citation or citation/new based on template title (2 places) table.insert (output, scan or ); return table.concat (output); -- make a big damn string and doneend

----------------------------< E X P O R T S >----------------------------------------------------------------

return

See main article: = main,.