Jump to content
Wikipedia The Free Encyclopedia

Module:Authority control/documentation/sandbox

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Warning This Lua module is used on approximately 290 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.
Wikipedia authority control
Project page
discussion
help
Template
subpages
sandbox
testcases
doc
Module
subpages
sandbox
testcases
doc
Config
staging
sandbox
doc
Auxiliary
sandbox
Doc module
sandbox
Category
attention

This module implements Template:Pages with authority control identifiers.

The above documentation is transcluded from Module:Authority control/documentation/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.
 require('strict')
 localp={}
 localframe=mw.getCurrentFrame()
 localconfig_file=frame.args.configandframe.args.config~=''and('/'..frame.args.config)or''
 localconfig=mw.loadData('Module:Authority control/config'..config_file)
 localsandbox='/'..config.i18n.sandbox
 localtitle=mw.title.getCurrentTitle()
 localnamespace=title.namespace
 localtestcases=title.subpageText==config.i18n.testcases
 localmakelink=require(config.i18n.ACmodule..(sandboxor'')).makelink
 locallang=mw.getContentLanguage()

 localfunctionneedsAttention(sortkey)
 return'[['..config.i18n.category..':'..config.i18n.attentioncat..'|'..sortkey..title.text..']]'
 end

 localfunctionaddCat(cat,sortkey)
 ifcatandcat~=''and(namespace==0ornamespace==14ortestcases)then
 localcategory,redlinkcat='',''
 iftestcases==falseandmw.title.new(cat,14).exists==falsethen
 redlinkcat=needsAttention('N')
 end
 category='[['..config.i18n.category..':'..cat
 ifsortkeythen
 category=category..'|'..sortkey..title.text
 end
 category=category..']]'..redlinkcat
 returncategory
 else
 return''
 end
 end

 localgetstatement=function(id,propid,qualid)
 localstatement=mw.wikibase.getBestStatements('P'..id,'P'..propid)
 localvalue
 ifstatementandstatement[1]andstatement[1].mainsnak.datavalueandstatement[1].mainsnak.datavalue.value.idthen
 value=statement[1].mainsnak.datavalue.value.id
 localqual
 ifqualidandstatement[1].qualifiers['P'..qualid][1].datavalue.valuethen
 qual=statement[1].qualifiers['P'..qualid][1].datavalue.value
 end
 returnvalue,qual
 end
 end
 localgetname=function(property)
 localname
 for_,propnameqidinipairs(config.property_items)do
 name=getstatement(property,propnameqid)
 ifnamethenbreakend
 end
 ifnamethen
 returnframe:expandTemplate{
 title='Wikidata fallback link',
 args={name}
 }
 else
 return''
 end
 end

 -- Creates a human-readable standalone wikitable version of conf, and tracking categories with page counts, for use in the documentation
 functionp.docConfTable()
 localdoc=''
 localrow=function(conf)
 localexample_qid=getstatement(conf.property,1855)
 localexample=example_qidandframe:expandTemplate{
 title='Flatlist',
 args={tostring(
 mw.html.create('ul')
 :node(makelink(conf,example_qid))
 )}
 }or''
 localcol1=mw.html.create('th')
 :attr('data-sort-value',conf.property)
 :attr('rowspan',conf.remarkand'2'or'1')
 :wikitext(frame:expandTemplate{
 title='Wikidata property link',
 args={conf.property}
 })
 localcol2=mw.html.create('td')
 :wikitext(getname(conf.property))
 localcol3=mw.html.create('td')
 :css('text-align','center')
 :wikitext(config.sections[conf.section].name)
 localcol4=mw.html.create('td')
 :wikitext(example)
 localrow=mw.html.create('tr')
 :node(col1)
 :node(col2)
 :node(col4)
 :node(col4)
 localremark
 ifconf.remarkthen
 localcell=mw.html.create('td')
 :attr('colspan','3')
 :tag('span'):css('font-weight','bold'):wikitext('i️ '):done()
 :wikitext(frame:preprocess{text=conf.remark})
 remark=mw.html.create('tr')
 :addClass('expand-child')
 :node(cell)
 end
 returnrow,remark
 end
 localheader_row=mw.html.create('tr')
 :tag('th'):attr('data-sort-type','number'):wikitext(config.i18n.WDproperty):done()
 :tag('th'):wikitext(lang:ucfirst(config.i18n.identifier)):done()
 :tag('th'):wikitext(config.i18n.Section):done()
 :tag('th'):wikitext(config.i18n.Appears_as):done()
 localdoc=mw.html.create('table'):addClass('wikitable sortable'):node(header_row)
 for_,confinpairs(config.config)do
 localrow,remark=row(conf)
 doc:node(row):node(remark)
 end
 returntostring(doc)
 end

 functionp.whitelisttable()
 localheader=mw.html.create('tr')
 :tag('th'):wikitext(config.i18n.Code):done()
 :tag('th'):wikitext(config.i18n.Topic):done()
 :tag('th'):wikitext(lang:ucfirst(config.i18n.identifiers)):done()
 localTable=mw.html.create('table')
 :addClass('wikitable'):addClass('sortable')
 :node(header)
 forcode,wlistinpairs(config.whitelists)do
 localplist={}
 for_,propertyinpairs(wlist.properties)do
 table.insert(plist,frame:expandTemplate{title='Wikidata property link',args={'P'..property}})
 end
 locallink=wlist.topicandmw.wikibase.getSitelink('Q'..wlist.topic)
 and'[['..mw.wikibase.getSitelink('Q'..wlist.topic)..']]'
 ormw.wikibase.getLabel('Q'..wlist.topic)
 localrow=mw.html.create('tr')
 :tag('th'):wikitext(code):done()
 :tag('td'):wikitext(link):done()
 :tag('td'):wikitext(table.concat(plist,', ')):done()
 Table:node(row)
 end
 returntostring(Table)
 end

 functionp.sectiontable()
 localheader=mw.html.create('tr')
 :tag('th'):wikitext(config.i18n.Section):done()
 :tag('th'):wikitext(config.i18n.Description):done()
 :tag('th'):wikitext(lang:ucfirst(config.i18n.identifiers)):done()
 localTable=mw.html.create('table')
 :addClass('wikitable'):addClass('sortable')
 :node(header)
 localplist={}
 forn,_inipairs(config.sections)do
 plist[n]={}
 end
 for_,idinpairs(config.config)do
 table.insert(plist[id.section],frame:expandTemplate{
 title=config.i18n.linktemplate,
 args={'P'..id.property}
 })
 end
 fornumber,sectioninipairs(config.sections)do
 localrow=mw.html.create('tr')
 :tag('th'):wikitext(number):done()
 :tag('td'):wikitext(section.name):done()
 :tag('td'):wikitext(table.concat(plist[number],', ')):done()
 Table:node(row)
 end
 returntostring(Table)
 end

 functionp.idproposal()
 localproperty=frame.args.propertyor''
 localout='<ul><li>Wikidata property: '..frame:expandTemplate{title='Wikidata property link',args={'P'..property}}..'</li>'
 out=out..'<li>Section: '
 localsection=frame.args.sectionor''
 ifsection~=''then
 out=out..config.sections[section].name..' ('..section..')'
 else
 out=out..'Not specified'
 end
 out=out..'</li><li>Link: '
 locallink=frame.args.linkor''
 iflink==''then
 link=mw.wikibase.getBestStatements('P'..property,'P1630')or''
 link=link[1].mainsnak.datavalue.value
 end
 iflink~=''then
 out=out..'<code>'..link..'</code>'
 else
 out=out..'Not specified'
 end
 out=out..'</li><li>Label: '
 locallabel=frame.args.labelor''
 iflabel~=''then
 out=out..label
 else
 out=out..'Not specified'
 end
 out=out..'</li><li>Example: '
 localexample=mw.wikibase.getBestStatements('P'..property,'P1855')or''
 ifexamplethen
 example=example[1].qualifiers['P'..property][1].datavalue.value
 example=frame:expandTemplate{title='Hlist',args={makelink({[1]='',link=link,label=label},example)}}
 out=out..example
 else
 out=out..'Not available'
 end
 out=out..'</li></ul>'
 returnout
 end

 p.listproperties=function()
 localtab={}
 for_,confinpairs(config.config)do
 table.insert(tab,conf.property)
 end
 returntable.concat(tab,', ')
 end

 returnp

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