Module documentation
This module implements the {{Subject bar}} template. Please don't use this module from an article or from another wiki page. You should use the {{Subject bar}} template instead. To use the module from another Lua module, read on.
For test cases, see {{Subject bar/testcases}}.
Use from another Lua module
Load the module like this:
local subjectBar = require('Module:Subject bar')._main
Then you can use the subjectBar
function like this:
local myBar = subjectBar{ portal = 'Portal 1', portal2 = 'Portal 2', -- ... commons = true, commons-search = 'Commons search string', wikt = true, wikt-search = 'Wiktionary search string' -- ...}
Please see Template:Subject bar/doc for a full list of possible parameters.
require('strict')local getArgs = require('Module:Arguments').getArgslocal yesNo = require('Module:Yesno')-- Determine whether we're being called from a sandboxlocal isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true)local sandbox = isSandbox and '/sandbox' or ''local p = {}local sisters = {'commons','species','voy','n','wikt','b','q','s','v','iw','iw1','iw2','d'}local function findNumericArgs(key, args)local pattern = "^"..key.."_?(%d+)$" -- pattern to matchlocal values = {}for k, v in pairs(args) do --- loop through all argumentslocal ord = tonumber(mw.ustring.match(k,pattern)) --- if "foo_?%d+", extract numberif ord thenvalues[ord] = vendendif args[key] ~= nil thenvalues[1] = args[key]endlocal compressSparseArray = require('Module:TableTools').compressSparseArrayvalues = compressSparseArray(values) --- squeeze out gaps/nils in values, keep orderingreturn valuesendfunction p._main(args)local result = ""local hasPortal = falsefor key, _ in pairs(args) doif mw.ustring.sub(key,1,6) == 'portal' or tonumber(key) thenhasPortal = truebreakendendlocal hasSister = yesNo(args.auto,true) or yesNo(args.author,true) or yesNo(args.cookbook,true)for _, sister in ipairs(sisters) doif hasSister thenbreakendif yesNo(args[sister],true) or yesNo(args[sister..'-search'],true) thenhasSister = trueendendif hasPortal thenlocal portalList = findNumericArgs("portal",args)for _, positional in ipairs(args) dotable.insert(portalList, positional)endlocal portalBar = require('Module:Portal bar'..sandbox)._mainresult = result..portalBar(portalList, {tracking=args.tracking, qid=args.qid})endif hasSister thenlocal sisterArgs = {auto=1, bar=1, trackSingle=not hasPortal}sisterArgs[1] = args.searchfor _, k in ipairs({'author','commonscat','cookbook','display','tracking','qid'}) dosisterArgs[k] = args[k]end for _, t in ipairs(sisters) do sisterArgs[t] = args[t..'-search'] or args[t] end local sisterBar = require('Module:Sister project links'..sandbox)._mainresult = result..sisterBar(sisterArgs)endreturn resultendfunction p.main(frame) -- If called via #invoke, use the args passed into the invoking template, -- or the args passed to #invoke if any exist. Otherwise assume args are -- being passed directly in from the debug console or from another Lua module. local args = getArgs(frame) return p._main(args)endreturn p
🔥 Top keywords: Main PageSpecial:SearchPage 3Wikipedia:Featured picturesHouse of the DragonUEFA Euro 2024Bryson DeChambeauJuneteenthInside Out 2Eid al-AdhaCleopatraDeaths in 2024Merrily We Roll Along (musical)Jonathan GroffJude Bellingham.xxx77th Tony AwardsBridgertonGary PlauchéKylian MbappéDaniel RadcliffeUEFA European Championship2024 ICC Men's T20 World CupUnit 731The Boys (TV series)Rory McIlroyN'Golo KantéUEFA Euro 2020YouTubeRomelu LukakuOpinion polling for the 2024 United Kingdom general electionThe Boys season 4Romania national football teamNicola CoughlanStereophonic (play)Gene WilderErin DarkeAntoine GriezmannProject 2025