-- Module to create sister project link boxlocal getArgs = require('Module:Arguments').getArgslocal commonsLink = require('Module:Commons link')local p =
-- Function to canonicalize string-- search for variants of "yes", and "no", and transform-- them into a standard form (like)-- Argument:-- s --- input string-- Result:-- list of length 2-- x = nil if s is canonicalized, otherwise has trimmed s-- y = canonical form of s (true if "yes" or other, false if "no", nil if blank)local function canonicalize(s) if s
"" then return end lowerS = s:lower -- Check for various forms of "yes" if lowerS
'y' or lowerS
'1' or lowerS
'on' then return end -- Check for various forms of "no" if lowerS
'n' or lowerS
'0' or lowerS
'off'then return end -- Neither yes nor no recognized, leave string trimmed return end
-- Merge two or more canonicalized argument lists-- Arguments:-- argList = list of canonicalized arguments-- noAll = if true, return no when all argList is no.-- otherwise, return blank when all argList is blanklocal function mergeArgs(argList,noAll) local test = nil -- default, return blank if all blank if noAll then test = false -- return no if all no end local allSame = true -- Search through string for first non-no or non-blank for _, arg in ipairs(argList) do if arg[2] then return arg -- found non-no and non-blank, return it end -- test to see if argList is all blank / no allSame = allSame and (arg[2]
-- Function to generate one sister link-- Arguments:-- container = parent HTML object-- args = argument table for function-- args[1] = canonicalized page to fetch-- args.default = link when blank-- args.auto = new auto mode (don't fall back to search)-- args.sitelink = wikidata sitelink (if available)-- args.sisterDbName = DB name of sister site (to get sitelink)-- args.qid = QID of entity (for debugging)-- args.search = fallback string to search for-- args.logo = filename of sister logo (no namespace)-- args.sisterPrefix = wikitext prefix for sister site-- args.information = type of info sister site contains-- args.sisterName = friendly human name of sister sitefunction p._oneSister(container,args) if args[1][2]
nil) then return nil --- either editor specified "no", or "blank" (and default=no), then skip this sister end local sitelink = args.sitelink or (args.sisterDbName and getSitelink(args.sisterDbName,args.qid)) if args.auto and not sitelink and args[1][2]
-- Function to create html containers for sister project link list-- Arguments:-- args = table of arguments-- args.position: if 'left', position links to left-- args.collapsible: if non-empty, make box collapsible. If 'collapse', start box hidden-- args.style: CSS style string appended to end of default CSS-- args.display: boldface name to displaylocal function createContainer(args) -- Outermost div (css from previous version of) local container = mw.html.create('div') container:attr("role","navigation") container:attr("aria-labelledby","sister-projects") container:addClass("metadata") container:addClass("plainlinks") container:addClass("sistersitebox") container:addClass("plainlist") if args.position and args.position:lower
"collapsed" then container:addClass("mw-collapsed") end end container:css("border","1px solid #aaa") container:css("padding",0) container:css("background","#f9f9f9") container:cssText(args.style) -- Div for text header local header = container:tag('div') header:css("clear",args.collapsible and "both") header:css("padding","0.75em 0") header:css("text-align","center") -- pagename in bold as part of header local pagename = header:tag('b') pagename:css("display","block") pagename:wikitext(args.display or args[1]) local headerText = "at Wikipedia's " headerText = headerText..'sister projects' header:wikitext(headerText) -- start the unordered list element here local ul = container:tag('ul') ul:addClass(args.collapsible and "mw-collapsible-content") ul:css("border-top","1px solid #aaa") ul:css("padding","0.75em 0") ul:css("width","217px") ul:css("margin","0 auto") -- pass ul element back to main, so sister links can be added return ulend
function p._main(args) -- Default title/search string is PAGENAME args[1] = args[1] or mw.title.getCurrentTitle.text -- Canonicalize all sister links (handle yes/no/empty) for _, k in pairs do args[k] = canonicalize(args[k]) end -- Canonicalize general parameters for _,k in pairs do args[k] = canonicalize(args[k])[2] end local ul = createContainer(args) -- WIKTIONARY p._oneSister(ul,) -- COMMONS -- use to determine best commons link local cLink = (not args.commonscat) and commonsLink._hasGallery(args.qid) or commonsLink._hasCategory(args.qid) p._oneSister(ul,) -- WIKINEWS p._oneSister(ul,) -- WIKIQUOTE p._oneSister(ul,) -- WIKISOURCE if args.author and args.s[1] then args.s[1] = "Author:"..args.s[1] end p._oneSister(ul,) -- WIKIBOOKS p._oneSister(ul,) -- WIKIVOYAGE p._oneSister(ul,) -- WIKIVERSITY p._oneSister(ul,) -- WIKIDATA p._oneSister(ul,) -- WIKISPECIES p._oneSister(ul,) if args.species[2] and args.species_author[1] then -- If species_author is explicitly defined, and species is used, then make second row p._oneSister(ul,) end -- META p._oneSister(ul,) -- MEDIAWIKI p._oneSister(ul,) return ul:allDoneend
-- Main entry point for generating sister project links boxfunction p.main(frame) local args = getArgs(frame,) return tostring(p._main(args))end
-- Test entry point for generating one sister linkfunction p.oneSister(frame) local args = getArgs(frame,) args[1] = canonicalize(args[1]) args.auto = canonicalize(args.auto)[2] return tostring(p._oneSister(nil,args))end
return p