Jump to content
Wikipedia The Free Encyclopedia

Module:Gadgets

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
[画像:Warning] This Lua module is used in system messages.
Changes to it can cause immediate changes to the Wikipedia 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 can only be edited by administrators because it is transcluded onto one or more cascade-protected pages.

Module to parse gadget definitions from MediaWiki:Gadgets-definition.

Usage

Intended for use from other modules only.

localgadgets=require('Module:Gadgets')
localgadgetRegistry=gadgets.parse()
The above documentation is transcluded from Module:Gadgets/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 localp={}

 p.parse=function()
 localtext=mw.title.new('MediaWiki:Gadgets-definition'):getContent()
 locallines=mw.text.split(text,'\n',false)

 localrepo={}
 for_,lineinipairs(lines)do
 ifline:sub(1,1)=='*'then
 localname,options,pages=p.parse_line(line)
 ifnameand#pages~=0then
 repo[name]={options=options,pages=pages}
 end
 end
 end
 returnrepo
 end

 p.parse_line=function(def)
 localpattern="^%*%s*(.+)%s*(%b[])%s*(.-)$"
 localname,opts,pageList=string.match(def,pattern)

 ifnamethen
 name=mw.text.trim(name)
 end

 -- Process options string into a Lua table
 localoptions={}
 ifoptsthen
 -- Extracting the options without square brackets and trimming spaces
 opts=opts:sub(2,-2):gsub("%s+","")

 forpairinopts:gmatch("%s*([^|]+)%s*|?")do
 localkey,value=pair:match("%s*([^=]+)%s*=%s*([^=|]+)%s*")
 ifkeyandvaluethen
 options[key:match("%s*(.-)%s*$")]=value:match("^%s*(.-)%s*$")
 else
 key=pair:match("%s*(.-)%s*$")
 options[key]=true
 end
 end
 end

 -- Process page list into an array
 localpages={}
 ifpageListthen
 forpageinpageList:gmatch("[^|]+")do
 table.insert(pages,mw.text.trim(page))
 end
 end
 returnname,options,pages
 end

 p.get_type=function(def)
 ifdef.options.type=='general'ordef.options.type=='styles'then
 returndef.options.type
 end
 ifdef.options.dependencies~=nilthen
 return'general'
 end
 for_,pageinipairs(def.pages)do
 ifnotstring.match(page,'%.css$')then
 return'general'
 end
 end
 return'styles'
 end

 p.get_usage=function(name)
 -- escape name for use in pattern
 name=name:gsub("[%-%.%+%[%]%(%)%$%^%%%?%*]","%%%1"):gsub("_"," ")

 -- rely on [[Project:GUS2Wiki]] until [[phab:T354890]] is implemented
 local_,_,count=mw.title.new('Project:GUS2Wiki'):getContent():find('\n'..name..',(%d+)')
 returntonumber(count)or-1
 end

 returnp

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