Module:Subject bar
Appearance
From Wikipedia, the free encyclopedia
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 20,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
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:
localsubjectBar=require('Module:Subject bar')._main
Then you can use the subjectBar function like this:
localmyBar=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.
The above documentation is transcluded from Module:Subject bar/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
require('strict') localgetArgs=require('Module:Arguments').getArgs localyesNo=require('Module:Yesno') -- Determine whether we're being called from a sandbox localisSandbox=mw.getCurrentFrame():getTitle():find('sandbox',1,true) localsandbox=isSandboxand'/sandbox'or'' localp={} localsisters={'commons','species','voy','n','wikt','b','q','s','v','iw','iw1','iw2','d','f'} localfunctionfindNumericArgs(key,args) localpattern="^"..key.."_?(%d+)$"-- pattern to match localvalues={} fork,vinpairs(args)do--- loop through all arguments localord=tonumber(mw.ustring.match(k,pattern))--- if "foo_?%d+", extract number ifordthen values[ord]=v end end ifargs[key]~=nilthen values[1]=args[key] end localcompressSparseArray=require('Module:TableTools').compressSparseArray values=compressSparseArray(values)--- squeeze out gaps/nils in values, keep ordering returnvalues end functionp._main(args) localresult="" localhasPortal=false forkey,_inpairs(args)do ifmw.ustring.sub(key,1,6)=='portal'ortonumber(key)then hasPortal=true break end end localhasSister=yesNo(args.auto,true)oryesNo(args.author,true)oryesNo(args.cookbook,true) for_,sisterinipairs(sisters)do ifhasSisterthen break end ifyesNo(args[sister],true)oryesNo(args[sister..'-search'],true)then hasSister=true end end ifhasPortalthen localportalList=findNumericArgs("portal",args) for_,positionalinipairs(args)do table.insert(portalList,positional) end localportalBar=require('Module:Portal bar'..sandbox)._main result=result..portalBar(portalList,{tracking=args.tracking,qid=args.qid}) end ifhasSisterthen localsisterArgs={auto=1,bar=1,trackSingle=nothasPortal} sisterArgs[1]=args.search for_,kinipairs({'author','commonscat','cookbook','display','tracking','qid'})do sisterArgs[k]=args[k] end for_,tinipairs(sisters)do sisterArgs[t]=args[t..'-search']orargs[t] end localsisterBar=require('Module:Sister project links'..sandbox)._main result=result..sisterBar(sisterArgs) end returnresult end functionp.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. localargs=getArgs(frame) returnp._main(args) end returnp