Jump to content
Wikibooks The Free Textbook Project

Module:Script doc auto

From Wikibooks, open books for an open world
Module documentation[view] [edit] [history] [purge]
[画像:Warning] This Lua module is used in system messages.
Changes to it can cause immediate changes to the Wikibooks user interface.
To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
This module depends on the following other modules:

This module is for use by {{Script doc auto}}.

Usage

{{#invoke:Script doc auto|main}}

No arguments are needed. For testing what the output would be when used on a specific page, you use |page= param.

The above documentation is transcluded from Module:Script doc auto/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 localMessageBox=require('Module:Message box')
 localGadgets=require('Module:Gadgets')
 localArguments=require('Module:Arguments')
 localTableTools=require('Module:TableTools')

 localp={}

 p.main=function(frame)
 localargs=Arguments.getArgs(frame)
 returnp.core(args.pageormw.title.getCurrentTitle().fullText)
 end

 p.core=function(page)
 localtext=''

 localcontent=mw.title.new(page).content
 ifcontentthen
 localresult=content:match("/%* ({{mfd.-}})")
 ifresultthen
 text=text..mw.getCurrentFrame():preprocess(result)
 end
 end

 locallen=page:len()
 iflen<4then
 -- Too short page name, do nothing more
 returntext
 end

 returnp.makeMessage(page)
 end

 localskins=TableTools.listToSet({
 'common','vector-2022','vector','timeless','minerva','monobook','modern','cologneblue'
 })

 p.gadget_text=function(name,repo)
 locallang=mw.getContentLanguage()
 localoptions=repo[name].options
 localdependents={}
 ifoptions.hidden~=nilthen
 -- Find dependents
 forn,cinpairs(repo)do
 localdeps=c.options.dependenciesand
 TableTools.listToSet(mw.text.split(c.options.dependencies,',',false))or{}
 localpeers=c.options.peersand
 TableTools.listToSet(mw.text.split(c.options.peers,',',false))or{}
 ifdeps['ext.gadget.'..name]~=nilorpeers[name]~=nilthen
 table.insert(dependents,'[[Special:Gadgets#gadget-'..n..'|'..n..']]')
 end
 end
 end
 localusage=Gadgets.get_usage(name)
 ifusage==-1then
 usage="an unknown number of"
 else
 usage=lang:formatNum(usage)
 end
 return'This page is loaded as a part of the '..
 '[[Special:Gadgets#gadget-'..name..'|'..name..']] gadget'..
 (options.hidden~=niland', a hidden gadget'..
 (#dependents>0and' used by '..mw.text.listToText(dependents)..'.'or'.')or
 (options.default~=niland', <b>which is enabled by default</b>.'or
 (', used by '..usage..' users. ')))
 end

 p.makeMessage=function(page)
 localpageparts=mw.text.split(page,'.',true)
 localpagetype='.'..pageparts[#pageparts]

 localpagetypes=TableTools.listToSet({
 '.js','.css','.json','.vue'
 })

 if#pageparts<2orpagetypes[pagetype]==nilthen
 return''
 end

 localfunctionlistSisters(title,intro)
 localoutput={intro}
 forsistertypeinpairs(pagetypes)do
 ifsistertype~=pagetypethen
 localsisterpage=mw.title.new(title..sistertype)
 ifsisterpage.existsthen
 table.insert(output,
 'an accompanying '..sistertype..' page at [['..sisterpage.fullText..']]'
 )
 end
 end
 end
 --listToText with Oxford commas
 returnmw.text.listToText(output,', ',(#output>2)and', and 'or' and ')..'.'
 end

 localtext=''
 localbasepage=mw.title.new(page:sub(0,-1*(#pagetype+1)))

 ifbasepage.namespace==2then
 ifskins[basepage.subpageText]~=niland(pagetype=='.js'orpagetype=='.css')then
 -- We are on a user skin file
 localsistertype=(pagetype=='.js')and'.css'or'.js'
 localsisterpage=mw.title.new(basepage.fullText..sistertype)
 text='The accompanying '..sistertype..' page for this skin '..
 (sisterpage.existsand'is'or'can be added')..' at [['..sisterpage.fullText..']].'
 else
 -- We are on some script page, not a user skin file
 ifbasepage.existsthen
 text=listSisters(basepage.fullText,'This user script seems to have a documentation page at [['..basepage.fullText..']]')
 else
 text=listSisters(basepage.fullText)
 text='Documentation for this user script can be added at [['..basepage.fullText..']]'..
 ((#text>1)and'. This user script seems to have 'or'')..
 text
 end
 end
 elseifbasepage.namespace==8then
 ifbasepage.text:find('^Gadget-')~=nilthen
 localgadgetRepo=Gadgets.parse()
 localshortName=basepage.text:gsub('^Gadget%-','')..pagetype
 forname,configinpairs(gadgetRepo)do
 ifTableTools.inArray(config.pages,shortName)then
 text=text..p.gadget_text(name,gadgetRepo)
 end
 end
 iftext~=''then
 localsisterText=listSisters(basepage.fullText)
 text=text..
 ((#sisterText>1)and(' There seems to be '..sisterText)or'')..
 '<br>'
 end
 end
 end

 iftext~=''then
 returnmw.getCurrentFrame():extensionTag{
 name='templatestyles',args={src='Module:Script doc auto/styles.css'}
 }..MessageBox.main('fmbox',{
 class='script-doc-auto-box',
 id='mw-script-doc',
 type='system',
 image='[[File:Template-info.svg|43x40px]]',
 text=text
 })
 end
 return''
 end

 returnp

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