ਮੌਡਿਊਲ:Subject bar
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 moduleLoad the module like this: local subjectBar = require('Module:Subject bar')._main
Then you can use the 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').getArgs
local yesNo = require('Module:Yesno')
-- Determine whether we're being called from a sandbox
local 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 match
local values = {}
for k, v in pairs(args) do --- loop through all arguments
local ord = tonumber(mw.ustring.match(k,pattern)) --- if "foo_?%d+", extract number
if ord then
values[ord] = v
end
end
if args[key] ~= nil then
values[1] = args[key]
end
local compressSparseArray = require('Module:TableTools').compressSparseArray
values = compressSparseArray(values) --- squeeze out gaps/nils in values, keep ordering
return values
end
function p._main(args)
local result = ""
local hasPortal = false
for key, _ in pairs(args) do
if mw.ustring.sub(key,1,6) == 'portal' or tonumber(key) then
hasPortal = true
break
end
end
local hasSister = yesNo(args.auto,true) or yesNo(args.author,true) or yesNo(args.cookbook,true)
for _, sister in ipairs(sisters) do
if hasSister then
break
end
if yesNo(args[sister],true) or yesNo(args[sister..'-search'],true) then
hasSister = true
end
end
if hasPortal then
local portalList = findNumericArgs("portal",args)
for _, positional in ipairs(args) do
table.insert(portalList, positional)
end
local portalBar = require('Module:Portal bar'..sandbox)._main
result = result..portalBar(portalList, {tracking=args.tracking, qid=args.qid})
end
if hasSister then
local sisterArgs = {auto=1, bar=1, trackSingle=not hasPortal}
sisterArgs[1] = args.search
for _, k in ipairs({'author','commonscat','cookbook','display','tracking','qid'}) do
sisterArgs[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)._main
result = result..sisterBar(sisterArgs)
end
return result
end
function 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)
end
return p
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia