Jump to content
Wikipedia The Free Encyclopedia

Module:Asbox stubtree/sandbox

From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Asbox stubtree (diff).
Module documentation[view] [edit] [history] [purge]
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.
Warning This Lua module is used on approximately 41,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 is used by Module:Asbox to create stub hierarchy boxes for stub template documentations. It also implements {{asbox/stubtree }} and served the same function via {{Asbox/templatepage }} prior to being converted to Lua.

Acknowledgements

[edit ]

In addition to the contributors listed in the contribution histories of Template:Asbox stubtree and Module:Asbox stubtree , this module also implements ideas from the deleted Template:Asbox/templatepage, which primary authors are User:MSGJ and User:WOSlinker.

The above documentation is transcluded from Module:Asbox stubtree/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 localp={}

 functionp.exists(pagename)
 returnmw.title.new(pagename,"Template").exists
 end

 functionp.pcase(word)
 returnmw.ustring.upper(mw.ustring.sub(word,1,1))..mw.ustring.sub(word,2)
 end

 functionp._subtree(pagename)
 -- split items on dash into table
 localr=0
 localt={}
 fortokeninmw.ustring.gmatch(pagename,"[^-]+")do
 -- don't add numbered items to list
 iftonumber(mw.ustring.sub(token,1,1))==nilthen
 table.insert(t,token)
 else
 r=1
 end
 end
 table.remove(t,#t)

 localout={"",pagename}
 localtemppage
 localtemppageexists
 localremoveditem1=""
 localremoveditem2=""
 while(#t>1)do
 ifr==1then
 r=0
 else
 -- Remove 1st item from list
 removeditem1=t[1]
 table.remove(t,1)
 end

 temppage=table.concat(t,"-").."-stub"
 temppageexists=p.exists(temppage)
 iftemppageexists==truethen
 table.insert(out,"[[Template:"..temppage.."|"..p.pcase(temppage).."]]")
 else
 -- If template with first item does not exist, try removing last item
 removeditem2=t[#t]
 table.remove(t,#t)
 temppage=removeditem1.."-"..table.concat(t,"-").."-stub"
 if#t==0then
 temppage=removeditem1.."-stub"
 end
 temppageexists=p.exists(temppage)
 iftemppageexists==truethen
 -- if exists then add first item back to list
 table.insert(t,1,removeditem1)
 table.insert(out,"[[Template:"..temppage.."|"..p.pcase(temppage).."]]")
 else
 -- if exists then add last item back to list
 table.insert(t,removeditem2)
 end
 end
 end

 locallist=mw.html.create('ul')
 for_,iteminipairs(out)do
 list:tag('li'):wikitext(item):done()
 end
 list:tag('li'):wikitext('[[Template:Stub|Stub]]'):allDone()

 localfinalresult=mw.html.create('div')
 finalresult:cssText('float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;')
 :tag('span')
 :attr('title','This shows the hierarchy of the stub template in relation to other templates.')
 :cssText('font-size:125%; font-weight:bold;')
 :wikitext('Stub hierarchy')
 :done()
 :addNode(list)
 :done()

 returntostring(finalresult)
 end

 functionp.subtree(frame)
 returnp._subtree(frame.args["pagename"])
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /