Jump to content
Wikipedia The Free Encyclopedia

Module:Uses TemplateStyles/sandbox

From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Uses TemplateStyles (diff).
See also the companion subpage for test cases.
Module documentation[view] [edit] [history] [purge]

Implements {{Uses TemplateStyles }}.

A couple test cases

One style page

[edit ]

{{Uses TemplateStyles|Template:Arrowlist/styles.css}}

Multiple style pages

[edit ]

{{Uses TemplateStyles|Template:Arrowlist/styles.css|Template:Routemap/styles.css}}

Sandbox version of style page exists

[edit ]

{{Uses TemplateStyles|Template:Uses TemplateStyles/example.css}}

No style pages specified

[edit ]

{{Uses TemplateStyles}}

Unicode

[edit ]

{{Uses TemplateStyles|Template:§&"woof"\//styles.css}}

The above documentation is transcluded from Module:Uses TemplateStyles/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit) pages.
Add categories to the /doc subpage. Subpages of this module.
 localyesno=require('Module:Yesno')
 localmList=require('Module:List')
 localmTableTools=require('Module:TableTools')
 localmMessageBox=require('Module:Message box')
 localTNT=require('Module:TNT')

 localp={}

 localfunctionformat(msg,...)
 returnTNT.format('I18n/Uses TemplateStyles',msg,...)
 end

 localfunctiongetConfig()
 returnmw.loadData('Module:Uses TemplateStyles/config')
 end

 localfunctionurlEncode(str)
 returnmw.uri.encode(str,"WIKI")
 end

 localfunctionrenderBox(tStyles)
 localboxArgs={
 type='notice',
 small=true,
 image=string.format('[[File:Farm-Fresh css add.svg|32px|alt=%s]]',format('logo-alt'))
 }
 if#tStyles<1then
 boxArgs.text=string.format('<strong class="error">%s</strong>',format('error-emptylist'))
 else
 localcfg=getConfig()
 localtStylesLinks={}
 fori,tsinipairs(tStyles)do
 locallink=string.format('[[:%s]]',ts)
 localsandboxLink=nil
 localeditLink=string.format(
 '[%s edit]',
 "https://en.wikipedia.org/w/index.php?title="..urlEncode(ts).."&action=edit"
 )
 localtsTitle=mw.title.new(ts)
 iftsTitleandcfg['sandbox_title']then
 localtsSandboxTitle=mw.title.new(string.format(
 '%s:%s/%s/%s',tsTitle.nsText,tsTitle.baseText,cfg['sandbox_title'],tsTitle.subpageText))
 iftsSandboxTitleandtsSandboxTitle.existsthen
 sandboxLink=format('sandboxlink',link,':'..tsSandboxTitle.prefixedText).." - "..editLink
 end
 end
 tStylesLinks[i]=sandboxLinkor(link.." ("..editLink..")")
 end
 localtStylesList=mList.makeList('bulleted',tStylesLinks)
 boxArgs.text=format(
 mw.title.getCurrentTitle():inNamespaces(828,829)and'header-module'or'header-template')..
 '\n'..tStylesList
 end
 returnmMessageBox.main('mbox',boxArgs)
 end

 localfunctionrenderTrackingCategories(args,tStyles,titleObj)
 ifyesno(args.nocat)then
 return''
 end

 localcfg=getConfig()
 localcats={}

 -- Error category
 if#tStyles<1andcfg['error_category']then
 cats[#cats+1]=cfg['error_category']
 end

 -- TemplateStyles category
 titleObj=titleObjormw.title.getCurrentTitle()
 if(titleObj.namespace==10ortitleObj.namespace==828)
 andnotcfg['subpage_blacklist'][titleObj.subpageText]
 then
 localcategory=args.categoryorcfg['default_category']
 ifcategorythen
 cats[#cats+1]=category
 end
 ifnotyesno(args.noprotcat)and(cfg['protection_conflict_category']orcfg['padlock_pattern'])then
 localcurrentProt=titleObj.protectionLevels["edit"]andtitleObj.protectionLevels["edit"][1]ornil
 localaddedLevelCat=false
 localaddedPadlockCat=false
 fori,tsinipairs(tStyles)do
 localtsTitleObj=mw.title.new(ts)
 localtsProt=tsTitleObj.protectionLevels["edit"]andtsTitleObj.protectionLevels["edit"][1]ornil
 ifcfg['padlock_pattern']andtsProtandnotaddedPadlockCatthen
 localcontent=tsTitleObj:getContent()
 ifnotcontent:find(cfg['padlock_pattern'])then
 cats[#cats+1]=cfg['missing_padlock_category']
 addedPadlockCat=true
 end
 end
 ifcfg['protection_conflict_category']andcurrentProtandtsProt~=currentProtandnotaddedLevelCatthen
 currentProt=cfg['protection_hierarchy'][currentProt]or0
 tsProt=cfg['protection_hierarchy'][tsProt]or0
 iftsProt<currentProtthen
 addedLevelCat=true
 cats[#cats+1]=cfg['protection_conflict_category']
 end
 end
 end
 end
 end
 fori,catinipairs(cats)do
 cats[i]=string.format('[[Category:%s]]',cat)
 end
 returntable.concat(cats)
 end

 functionp._main(args)
 localcfg=getConfig()
 if#args==0then
 localprefixed=mw.title.getCurrentTitle().prefixedText
 prefixed=prefixed:gsub("/doc","")
 args[1]=prefixed.."/"..cfg["default_subpage_name"]
 end
 localtStyles=mTableTools.compressSparseArray(args)
 localbox=renderBox(tStyles)
 localtrackingCategories=renderTrackingCategories(args,tStyles)
 returnbox..trackingCategories
 end

 functionp.main(frame)
 localorigArgs=frame:getParent().args
 localargs={}
 fork,vinpairs(origArgs)do
 v=v:match('^%s*(.-)%s*$')
 ifv~=''then
 args[k]=v
 end
 end
 returnp._main(args)
 end

 returnp

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