Module:Authority control
- Afrikaans
- Alemannisch
- Ænglisc
- Аԥсшәа
- العربية
- Aragonés
- ܐܪܡܝܐ
- অসমীয়া
- Asturianu
- تۆرکجه
- Basa Bali
- বাংলা
- Banjar
- 閩南語 / Bân-lâm-gí
- Беларуская (тарашкевіца)
- भोजपुरी
- Bikol Central
- Български
- Boarisch
- Bosanski
- Català
- Cebuano
- Čeština
- Chavacano de Zamboanga
- Cymraeg
- Dansk
- Ελληνικά
- Español
- Euskara
- Eʋegbe
- فارسی
- Fiji Hindi
- Français
- Gaeilge
- Gàidhlig
- Galego
- گیلکی
- 客家語 / Hak-kâ-ngî
- 한국어
- Hausa
- हिन्दी
- Ilokano
- Bahasa Indonesia
- IsiXhosa
- Italiano
- עברית
- Jawa
- ಕನ್ನಡ
- ქართული
- Kurdî
- ລາວ
- Latviešu
- Lëtzebuergesch
- Ligure
- Magyar
- Madhurâ
- मैथिली
- Македонски
- മലയാളം
- Malti
- Māori
- मराठी
- مصرى
- مازِرونی
- Bahasa Melayu
- Minangkabau
- 閩東語 / Mìng-dĕ̤ng-ngṳ̄
- Mirandés
- Мокшень
- Монгол
- မြန်မာဘာသာ
- Na Vosa Vakaviti
- Nederlands
- नेपाली
- 日本語
- Nordfriisk
- Norsk bokmål
- Norsk nynorsk
- Occitan
- ଓଡ଼ିଆ
- Oʻzbekcha / ўзбекча
- ਪੰਜਾਬੀ
- Pälzisch
- پښتو
- Tok Pisin
- Polski
- Português
- Qaraqalpaqsha
- Română
- Sakizaya
- संस्कृतम्
- Sardu
- Scots
- Seediq
- Shqip
- සිංහල
- Simple English
- سنڌي
- Slovenščina
- Ślůnski
- کوردی
- Српски / srpski
- Srpskohrvatski / српскохрватски
- Suomi
- Svenska
- Tagalog
- தமிழ்
- Tarandíne
- తెలుగు
- ไทย
- ትግርኛ
- Тоҷикӣ
- ತುಳು
- Türkçe
- Українська
- اردو
- Vahcuengh
- Vèneto
- Tiếng Việt
- 粵語
- Zazaki
- 中文
- Betawi
- Batak Mandailing
- Jaku Iban
Appearance
From Wikipedia, the free encyclopedia
Warning This Lua module is used on approximately 2,190,000 pages, or roughly 3% of all pages .
To avoid major disruption and server load, 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. Consider discussing changes on the talk page before implementing them.
To avoid major disruption and server load, 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. Consider discussing changes on the talk page before implementing them.
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Wikipedia authority control |
---|
This module depends on the following other modules:
This module contains the code for the {{Authority control }} template.
Please see Template:Authority control/doc.
The above documentation is transcluded from Module:Authority control/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
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) localtitle=mw.title.getCurrentTitle() localnamespace=title.namespace localtestcases=title.subpageText==config.i18n.testcases localwikilink=function(target,label) returnlabeland'[['..target..'|'..label..']]'or'[['..target..']]' end localneedsAttention=function(sortkey) returnwikilink(config.i18n.category..':'..config.i18n.attentioncat,sortkey..title.text) end localaddCat=function(cat,sortkey) ifcatandcat~=''and(namespace==0ornamespace==14ortestcases)then returnwikilink(config.i18n.category..':'..cat,sortkeyandsortkey..title.text) else return'' end end localtooltip=function(text,label) iflabelandlabel~=''then returnframe:expandTemplate{ title='Tooltip', args={text,label} } else returntext end end local_makelink=function(id,val,additional,qid)--validate values and create a link locallink=mw.html.create('span'):addClass('uid') ifnotadditionalandid.prefixthen--show prefix on primary value link:wikitext(id.prefix..': ') end localvalid_value=false ifid.customlinkthen-- use function to validate and generate link localnewlink=require(config.auxiliary)[id.customlink](val.id,additional) ifnewlinkthen link:wikitext(newlink) valid_value=true end else ifid.patternthen-- check pattern to determine validity valid_value=string.match(val.id,'^'..id.pattern..'$') elseifid.patternsthen-- check multiple patterns to determine validity for_,patterninipairs(id.patterns)do valid_value=val.id:match('^'..pattern..'$') ifvalid_valuethenbreakend end elseifid.validthen-- use function to determine validity valid_value=require(config.auxiliary)[id.valid](val.id) else-- no validation possible valid_value=val.id end ifvalid_valuethen locallabel=id.label ifnotlabeloradditionalthen label=tostring(additional) end localnewlink ifid.linkthen valid_value=valid_value:gsub('%%','%%%%') localtarget=mw.ustring.gsub(id.link,'%1ドル',valid_value):gsub(' ','%%20') newlink='['..target..' '..label..']' else newlink=valid_value end link:wikitext(tooltip(newlink,val.name)) end end ifvalid_valuethen localcat=id.categoryandstring.format(config.i18n.cat,id.category) link:wikitext(addCat(cat)) else localwdlink=qidandwikilink(':wikidata:'..qid..'#P'..id.property)or'' localname=mw.wikibase.getLabel('P'..id.property)or'' localtooltip=string.format( config.i18n.idnotvalid, name, val.id ) localcat=id.categoryandstring.format( config.i18n.cat, config.i18n.faulty..' '..id.category ) link:wikitext(wikilink('File:'..config.i18n.warningicon..'|20px|frameless|link='..wdlink,tooltip..'.')) :wikitext(addCat(cat)) :wikitext(addCat(config.i18n.allfaultycat,name)) end returnlink end local_makelinks=function(id,qid) --[[==================================]] --[[ Make links ]] --[[==================================]] localgetquals=function(statement,qualid) ifstatement.qualifiersandstatement.qualifiers['P'..qualid]then returnmw.wikibase.renderSnak(statement.qualifiers['P'..qualid][1]) end end localids={} ifqidthen for_,statementinipairs(mw.wikibase.getBestStatements(qid,'P'..id.property))do ifstatement.mainsnak.datavaluethen localval=statement.mainsnak.datavalue.value ifvalthen localnamedas=getquals(statement,1810)orgetquals(statement,742)or'' table.insert(ids,{id=val,name=namedas}) endendendend locallinks ifids[1]then links=mw.html.create('li'):node(_makelink(id,ids[1],false,qid)) ifids[2]then localsublinks=mw.html.create('ul') forn=2,#idsdo sublinks:tag('li'):node(_makelink(id,ids[n],n,qid)):done() end links:node(sublinks) end end returnlinks end p.authorityControl=function(frame) --[[==================================]] --[[ Main ]] --[[==================================]] localresolveQID=function(qid) ifqidthen qid='Q'..mw.ustring.gsub(qid,'^[Qq]','') ifmw.wikibase.isValidEntityId(qid)andmw.wikibase.entityExists(qid)then localsitelink=mw.wikibase.getSitelink(qid) ifsitelinkthen returnmw.wikibase.getEntityIdForTitle(sitelink)ormw.wikibase.getEntity(qid).id end returnmw.wikibase.getEntity(qid).id endendend localconf=config.config localparentArgs=frame:getParent().args localauxCats='' localrct=false-- boolean to track if there are any links to be returned localqid,topic ifnamespace==0then qid=mw.wikibase.getEntityIdForCurrentPage() end ifqidthen-- article is connected to a Wikidata item ifparentArgs.qidandresolveQID(parentArgs.qid)~=qidthen-- non-matching qid parameter auxCats=auxCats..needsAttention('D') end else-- page is not connected to any Wikidata item qid=resolveQID(parentArgs.qid)-- check qid parameter if no wikidata item is connected ifqidthen-- qid parameter is valid, set topic to display topic=mw.wikibase.getLabel(qid) iftopicthen ifmw.ustring.lower(title.subpageText)==mw.ustring.lower(topic)then-- suppress topic display if subpagename equals topic up to case change topic=nil end iftopicandmw.wikibase.getSitelink(qid)then-- make wikilink to article topic=wikilink(mw.wikibase.getSitelink(qid),topic) end else auxCats=auxCats..needsAttention('L') end elseifparentArgs.qidandparentArgs.qid~=''then-- invalid qid has been supplied, add to tracking cat auxCats=auxCats..needsAttention('Q') end end localqids={}-- setup any additional QIDs ifparentArgs.additional=='auto'then ifqidthen-- check P527 for parts to add additional qids localcheckparts=function(property) localparts=mw.wikibase.getBestStatements(qid,property) ifpartsthen for_,partinipairs(parts)do ifpart.mainsnak.datavalueandpart.mainsnak.datavalue.value.idthen localresolvedqid=resolveQID(part.mainsnak.datavalue.value.id) ifresolvedqidthen table.insert(qids,resolvedqid) endendendendend for_,partinipairs(config.auto_additional)do checkparts('P'..part) end end elseifparentArgs.additionalandparentArgs.additional~=''then for_,vinipairs(mw.text.split(parentArgs.additional,'%s*,%s*'))do v=resolveQID(v) ifvthen ifv==qidthen-- duplicate of qid parameter auxCats=auxCats..needsAttention('R') end table.insert(qids,v) else-- invalid QID specified auxCats=auxCats..needsAttention('A') end end end localnumsections,sections=0,{} for_,_inipairs(config.sections)do-- count number of regular sections numsections=numsections+1 end for_=1,#qids+numsectionsdo table.insert(sections,{}) end -- check which identifiers to show/suppress in template localshow,show_all_unsuppressed={},true localstripP=function(pid)--strip P from property number ifpid:match('^[Pp]%d+$')then pid=mw.ustring.gsub(pid,'[Pp]','') end pid=tonumber(pid) ifpidandmw.wikibase.entityExists('P'..pid)then returnpid end end localaddshowlist=function(list) iflistandlist~=''then for_,vinipairs(mw.text.split(string.lower(list),'%s*,%s*'))do ifv~=''then-- ignore blank parameters ifconfig.whitelists[v]then-- e.g. show=arts to use whitelist for_,winipairs(config.whitelists[v].properties)do show[w]=true end else v=stripP(v) ifvthen-- e.g. show=P214 to show one particular property show[v]=true else-- unrecognised property or whitelist auxCats=auxCats..needsAttention('W') end end end end show_all_unsuppressed=false end end addshowlist(frame.args.show)-- check show parameter on wrapper template addshowlist(parentArgs.show)-- check show parameter on article addshowlist(parentArgs.country)-- check country parameter on article ifparentArgs.suppressthen localsuppresslist=mw.text.split(parentArgs.suppress,'%s*,%s*')-- split parameter by comma for_,vinipairs(suppresslist)do ifv~=''then-- ignore blank parameters v=stripP(v) ifvthen show[v]=false auxCats=auxCats..wikilink(config.i18n.category..':'..config.i18n.suppressedcat) else auxCats=auxCats..needsAttention('P') end end end end localmakeSections=function(qid,addit) for_,idinipairs(conf)do ifid.suppressedbypropertythen for_,propertyinipairs(id.suppressedbyproperty)do ifshow[property]=='used'then-- property is in use show[id.property]=false-- suppressed by another property endendend ifshow[id.property]==nilthen show[id.property]=show_all_unsuppressed end ifshow[id.property]then locallinks=_makelinks(id,qid) iflinksthen table.insert( sections[additorid.section], links ) show[id.property]='used' rct=true end end end end localpencil=function(qid) ifqidthen returnrequire('Module:EditAtWikidata')._showMessage{ pid='identifiers', qid=qid } else return'' end end makeSections(qid,false) forc=1,#qidsdo makeSections(qids[c],numsections+c) end --configure Navbox localoutString='' ifrctthen-- there is at least one link to display localNavbox=require('Module:Navbox') localsect,lastsect=0,0 localnavboxArgs={ name='Authority control', navboxclass='authority-control', bodyclass='hlist', state=parentArgs.stateorconfig.i18n.autocollapse, navbar='off' } forc=1,numsections+#qidsdo if#sections[c]>0then-- section is non-empty sect=sect+1 lastsect=c localsectname ifc<=numsectionsthen-- regular section sectname=config.sections[c].name else-- section from additional qid localqid=qids[c-numsections] locallabel,sitelink=mw.wikibase.getLabel(qid),mw.wikibase.getSitelink(qid) iflabelthen ifsitelinkthen localtarget=mw.title.new(sitelink) iftarget==titleor(target.isRedirectandtarget.redirectTarget==title)then-- do not link sectname=label else-- make wikilink to article sectname=wikilink(sitelink,label) end else sectname=label end else auxCats=auxCats..needsAttention('L') sectname=qid end sectname=sectname..pencil(qid) end navboxArgs['group'..c]=sectname locallist=mw.html.create('ul') for_,linkinipairs(sections[c])do list:node(link) end navboxArgs['list'..c]=tostring(list) end end iftopicthen-- display in expanded form with topic navboxArgs.title=config.i18n.aclink..' – '..topic..pencil(qid) elseifsect==1then-- special display when only one section iflastsect<=numsectionsthen ifconfig.sections[lastsect].hidelabelwhenalonethen-- no special label when only general or other IDs are present navboxArgs['group'..lastsect]=config.i18n.aclink..pencil(qid) else-- other regular section navboxArgs['group'..lastsect]=config.i18n.aclink..': '..navboxArgs['group'..lastsect]..pencil(qid) end else-- section from additional qid navboxArgs['group'..lastsect]=config.i18n.aclink..': '..navboxArgs['group'..lastsect] end else-- add title to navbox navboxArgs.title=config.i18n.aclink..pencil(qid) end outString=Navbox._navbox(navboxArgs) end ifparentArgs.state andparentArgs.state~='' andparentArgs.state~=config.i18n.collapsed andparentArgs.state~=config.i18n.expanded andparentArgs.state~=config.i18n.autocollapsethen--invalid state parameter auxCats=auxCats..needsAttention('S') end iftestcasesthen auxCats=mw.ustring.gsub(auxCats,'(%[%[)('..config.i18n.category..')','%1:%2')--for easier checking end --out outString=outString..auxCats ifnamespace~=0then outString=mw.ustring.gsub(outString,'(%[%[)('..config.i18n.category..':'..config.i18n.Articles..')([^%|%]]+)%|?[^%|%]]*(%]%])','%1:%2%3%4') outString=mw.ustring.gsub(outString,'(%[%[)('..config.i18n.category..':'..config.i18n.All_articles..')([^%|%]]+)%|?[^%|%]]*(%]%])','%1:%2%3%4') end localcheck=require('Module:Check for unknown parameters')._check localsortkey ifnamespace==0then sortkey='*'..title.text else sortkey=title.fullText end outString=outString..check({ ['unknown']=wikilink(config.i18n.category..':'..config.i18n.pageswithparams,sortkey), ['preview']=config.i18n.previewwarning,'show','country','suppress','additional','qid','state' },parentArgs) returnoutString end p.makelink=function(id,qid) return_makelinks(id,qid) end returnp