Module:Authority control/documentation
Appearance
![]() | 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 |
---|
This module implements Template:Pages with authority control identifiers.
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.sandboxlocaltitle=mw.title.getCurrentTitle()localnamespace=title.namespacelocaltestcases=title.subpageText==config.i18n.testcaseslocalmakelink=require(config.i18n.ACmodule..(sandboxor'')).makelinklocallang=mw.getContentLanguage()localfunctionneedsAttention(sortkey)return'[['..config.i18n.category..':'..config.i18n.attentioncat..'|'..sortkey..title.text..']]'endlocalfunctionaddCat(cat,sortkey)ifcatandcat~=''and(namespace==0ornamespace==14ortestcases)thenlocalcategory,redlinkcat='',''iftestcases==falseandmw.title.new(cat,14).exists==falsethenredlinkcat=needsAttention('N')endcategory='[['..config.i18n.category..':'..catifsortkeythencategory=category..'|'..sortkey..title.textendcategory=category..']]'..redlinkcatreturncategoryelsereturn''endendlocalgetstatement=function(id,propid,qualid)localstatement=mw.wikibase.getBestStatements('P'..id,'P'..propid)localvalueifstatementandstatement[1]andstatement[1].mainsnak.datavalue.value.idthenvalue=statement[1].mainsnak.datavalue.value.idlocalqualifqualidandstatement[1].qualifiers['P'..qualid][1].datavalue.valuethenqual=statement[1].qualifiers['P'..qualid][1].datavalue.valueendreturnvalue,qualendendlocalgetname=function(property)localnamefor_,propnameqidinipairs(config.property_items)doname=getstatement(property,propnameqid)ifnamethenbreakendendifnamethenreturnframe:expandTemplate{title='Wikidata fallback link',args={name}}elsereturn''endend-- Creates a human-readable standalone wikitable version of conf, and tracking categories with page counts, for use in the documentationfunctionp.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)ifconf.remarkthencol1:attr('rowspan','2')endcol1:wikitext(frame:expandTemplate{title='Wikidata property link',args={conf.property}})localrow=mw.html.create('tr'):node(col1):tag('td'):wikitext(getname(conf.property)):done():tag('td'):css('text-align','center'):wikitext(config.sections[conf.section].name):done():tag('td'):wikitext(example):allDone()localremarkifconf.remarkthenremark=mw.html.create('tr'):addClass('expand-child'):tag('td'):attr('colspan','3'):tag('span'):css('font-weight','bold'):wikitext('ℹ️ '):done():wikitext(frame:preprocess{text=conf.remark}):allDone()endreturnrow,remarkendlocalheader_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)dolocalrow,remark=row(conf)doc:node(row):node(remark)endreturntostring(doc)endfunctionp.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)dolocalplist={}for_,propertyinpairs(wlist.properties)dotable.insert(plist,frame:expandTemplate{title='Wikidata property link',args={'P'..property}})endlocalrow=mw.html.create('tr'):tag('th'):wikitext(code):done():tag('td'):wikitext('[['..mw.wikibase.getSitelink('Q'..wlist.topic)..']]'):done():tag('td'):wikitext(table.concat(plist,', ')):done()Table:node(row)endreturntostring(Table)endfunctionp.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)doplist[n]={}endfor_,idinpairs(config.config)dotable.insert(plist[id.section],frame:expandTemplate{title=config.i18n.linktemplate,args={'P'..id.property}})endfornumber,sectioninipairs(config.sections)dolocalrow=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)endreturntostring(Table)endfunctionp.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~=''thenout=out..config.sections[section].name..' ('..section..')'elseout=out..'Not specified'endout=out..'</li><li>Link: 'locallink=frame.args.linkor''iflink==''thenlink=mw.wikibase.getBestStatements('P'..property,'P1630')or''link=link[1].mainsnak.datavalue.valueendiflink~=''thenout=out..'<code>'..link..'</code>'elseout=out..'Not specified'endout=out..'</li><li>Label: 'locallabel=frame.args.labelor''iflabel~=''thenout=out..labelelseout=out..'Not specified'endout=out..'</li><li>Example: 'localexample=mw.wikibase.getBestStatements('P'..property,'P1855')or''ifexamplethenexample=example[1].qualifiers['P'..property][1].datavalue.valueexample=frame:expandTemplate{title='Hlist',args={makelink({[1]='',link=link,label=label},example)}}out=out..exampleelseout=out..'Not available'endout=out..'</li></ul>'returnoutendreturnp