Μετάβαση στο περιεχόμενο

Module:WikidataOld

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια
--script that retrieves basic data stored in Wikidata, for the datamodel, see https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lualocalp={}locallinguistic=require('Module:Linguistic')--local formatDate = require('Module:Complex date') only loaded when needed to save memory in large pages like Wikidata:List of properties/alllocalfb=require('Module:Fallback')locali18nmessages=mw.loadData('Module:i18n/wikidata')-- Wiki-specific parameterslocaldefaultlang=mw.getCurrentFrame():preprocess("{{int:lang}}")localdefaultlink='wikidata'localfunctioni18n(str,lang)localmessage=i18nmessages[str]iftype(message)=='string'thenreturnmessageendreturnfb._langSwitch(message,langordefaultlang)endlocalfunctionformatError(key,text)returnerror(i18n(key)..(textor''))endlocalfunctionaddTrackingCat(prop,cat)ifnotpropandnotcatthenreturnerror("no property provided")endifnotcatthencat=i18nmessages.trackingcat..'/'..string.upper(prop)endreturn'[[Category:'..cat..']]'endlocalfunctionremoveBlanks(args)fori,jinpairs(args)do-- does not work ??if(j=='')or(j=='-')thenargs[i]=nilendendreturnargsendlocalfunctionformatTheUnknown()-- voir si on peut accorder/adapter l'usage de "inconnu"returni18n('somevalue')endlocalfunctionisSpecial(snak)returnsnak.snaktype~='value'endlocalfunctionsameValue(snak,target)returnnotisSpecial(snak)andp.getRawvalue(snak)==targetendlocalfunctionshowLang(statement,str)-- TODO (not yet in proper format)--adds a lang indication at the start of the string, based on data in statementlocalmainsnak=statement.mainsnakifisSpecial(mainsnak)thenreturnstrendlocallanglist={}ifmainsnak.datavalue.type=='monolingualtext'thenlanglist={mainsnak.datavalue.value.language}elseifstatement.qualifiersandstatement.qualifiers.P407thenlocalconvertlangcode=mw.loadData('Module:Dictionary/lang codes')fori,jinpairs(statement.qualifiers.P407)doifnotisSpecial(j)thenlocalval=convertlangcode[j.datavalue.value['numeric-id']]table.insert(langlist,val)endendendif#langlist==0thenreturnstrelsereturn'('..table.concat(langlist)..')'..strendendfunctionp.getEntity(val)iftype(val)=='table'thenreturnvalendreturnmw.wikibase.getEntityObject(val)end-- DATE FUNCTIONSlocalfunctionsplitTimestamp(timestamp,calendar)localpattern="(%W)(%d+)%-(%d+)%-(%d+)"localera,year,month,day=timestamp:match(pattern)ifcalendar=='julian'then--todo year, month, day = formatdate.gregorianToJulian( era .. year, month, day )endreturn{day=day,month=month,year=year,era=era,timestamp=timestamp,type='dateobject'}endlocalfunctionrangeObject(begin,ending)localtimestampifbeginthentimestamp=begin.timestampelseifendingthentimestamp=ending.timestampendreturn{begin=begin,ending=ending,timestamp=timestamp,type='rangeobject'}endlocalfunctiondateObject(orig,params)-- transforme un snak en un nouvel objet utilisable par Module:Date complexeifnotparamsthenparams={}endlocalnewobj=splitTimestamp(orig.time,orig.calendar)-- initalise l'object en mettant la valeur des datesnewobj.precision=params.precisionororig.precisionnewobj.type='dateobject'returnnewobjendlocalfunctionformatDatepoint(obj,params)-- TO IMPROVEifnotobjthenreturnnilendlocalera=obj.era=='-'and'bc'or''localformatDate=require('Module:Complex date')locallang=params.langordefaultlanglocalprecision=math.min(obj.precision,params.precisionor15)-- if we don't want to show the value to its full detailifprecision>=11thenreturnformatDate.complex_date{args={date1=obj.year..'-'..obj.month..'-'..obj.day,lang=lang,era1=era}}elseifprecision==10thenreturnformatDate.complex_date{args={date1=obj.year..'-'..obj.month,lang=lang,era1=era}}elseifprecision==9thenreturnformatDate.complex_date{args={date1=tostring(obj.year),lang=lang,era1=era}}elseifprecision==8thenreturnformatDate.complex_date{args={date1=string.sub(tostring(obj.year),1,3)..'0',lang=lang,precision='decade',era1=era}}elseifprecision==7thenreturnformatDate.complex_date{args={date1=tostring(obj.year/100),lang=lang,precision='century',era1=era}}endreturnnilendlocalfunctionformatDaterange(obj,params)--TODOlocalbegin=formatDatepoint(obj.begin,params)or''localending=formatDatepoint(obj.ending,params)or''returnbegin..'-'..endingendlocalfunctionobjectToText(obj,params)ifobj.type=='dateobject'thenreturnformatDatepoint(obj,params)elseifobj.type=='rangeobject'thenreturnformatDaterange(obj,params)endreturnnilendlocalfunctiontableToText(values,params)-- takes a list of already formatted values and make them a textifnotvaluesthenreturnnilendreturnlinguistic.conj(values,params.langordefaultlang,params.conjtype)--linguistic.conj( values, params.lang, params.conjtype )endfunctionp.getDate(obj)--[[returns an object containing a timestamp for easy sorting, and other data possible types of object: dateobject {timestamp = string, year = number, month = number, day = number, calendar = string} rangeobject {timestamp = string, begin = dateobject, ending = dateobject}]]--ifnotobjthenreturnnilendiftype(obj)=='string'thenobj=p.getEntity(obj)end-- if obj is a statement with date, get itifobj.mainsnakandnotisSpecial(obj.mainsnak)andobj.mainsnak.datatype=='time'thenreturndateObject(obj.mainsnak.datavalue.value)end-- else preload relevant datalocalqualifs=obj.qualifiers-- when obj is a statement, look in qualifierslocalclaims=obj.claims-- when obj is an item, look in claimslocalpointprop={'P585','P571'}-- dates corresponding to a punctual factlocalbeginprop={'P580','P569'}-- start date, birth date == start of a date rangelocalendingprop={'P582','P570'}localfunctiongetval(prop)localvalifclaimsandclaims[prop]andnotisSpecial(claims[prop][1].mainsnak)thenval=claims[prop][1].mainsnak.datavalue.valueelseifqualifsandqualifs[prop]andnotisSpecial(qualifs[prop][1])thenval=qualifs[prop][1].datavalue.valueendifvalthenreturndateObject(val)endreturnnilendfori,propinpairs(pointprop)dolocalval=getval(prop)ifvalthenreturnvalendend--if no date has not been found, look for startdate or enddatelocalbegin,endingfori,propinpairs(beginprop)dobegin=getval(prop)ifbeginthenbreakendendfori,propinpairs(endingprop)doending=getval(prop)ifendingthenbreakendendifbeginorendingthenreturnrangeObject(begin,ending)endreturnnilendfunctionp.getFormattedDate(statement,params)localdatetable=p.getDate(statement)ifnotdatetablethenreturnnilendreturnobjectToText(datetable,params)endlocalfunctionhasTargetValue(claim,target)iftarget==nilthenreturntrueendreturnsameValue(claim.mainsnak,target)endlocalfunctionhasRank(claim,target)iftarget=='valid'thenreturnhasRank(claim,'preferred')orhasRank(claim,'normal')elsereturnclaim.rank==targetendendlocalfunctionbestRanked(claims)ifnotclaimsthenreturnnilendlocalpreferred,normal={},{}fori,jinpairs(claims)doifj.rank=='preferred'thentable.insert(preferred,j)elseifj.rank=='normal'thentable.insert(normal,j)endendif#preferred>0thenreturnpreferredelsereturnnormalendendlocalfunctionhasQualifier(claim,qualifier,qualifiervalues)ifnotqualifierthen-- si aucun qualificatif est demandé, ça passereturntrueendqualifier=string.upper(qualifier)ifnotclaim.qualifiersornotclaim.qualifiers[qualifier]thenreturnfalseendiftype(qualifiervalues)=='string'thenqualifiervalues=mw.text.split(qualifiervalues,',')endif(notqualifiervalues)or(qualifiervalues=={})thenreturntrue-- si aucune valeur spécifique n'est exigéeendfori,jinpairs(claim.qualifiers[qualifier])dofork,linpairs(qualifiervalues)doifp.getRawvalue(j)==lthenreturntrueendendendreturnfalseendlocalfunctionhasSource(statement,source,sourceproperty)ifnotstatement.referencesthenreturnfalseendsourceproperty=string.upper(sourcepropertyor'P248')localsourcevalue=string.upper(sourceor'')fori,refinpairs(statement.references)doforprop,contentinpairs(ref.snaks)doifprop==sourcepropertythenifsourcevalue==''thenreturntrueelseforj,kinpairs(content)doifp.getRawvalue(k)==sourcethenreturntrueendendendendendendreturnfalseendlocalfunctionhasDate(statement)ifnotstatement.qualifiersthenreturnfalseendlocaldateprops={'P580','P585','P582'}fori,propinpairs(dateprops)doifstatement.qualifiers[prop]thenreturntrueendendreturnfalseendlocalfunctionisInLanguage(snak,lang)-- ne fonctionne que pour les monolingualtext / étendre aux autres types en utilisant les qualifiers ?returnnotisSpecial(snak)andsnak.datavalue.type=='monolingualtext'andsnak.datavalue.value.language==langendlocalfunctionnumval(claims,numval)-- retourn les numval premières valeurs de la table claimslocalnumval=tonumber(numval)or0-- raise a error if numval is not a positive integer ?if#claims<=numvalthenreturnclaimsendlocalnewclaims={}while#newclaims<numvaldotable.insert(newclaims,claims[#newclaims+1])endreturnnewclaimsendfunctionp.comparedate(a,b)-- returns true if a is earlier than B or if a has a date but not bifaandbthenreturna.timestamp<b.timestampelseifathenreturntrueendreturnfalseendfunctionp.chronosort(objs,inverted)table.sort(objs,function(a,b)localtimeA=p.getDate(a)localtimeB=p.getDate(b)ifinvertedthenreturnp.comparedate(timeB,timeA)elsereturnp.comparedate(timeA,timeB)endend)returnobjsendfunctionp.sortclaims(claims,sorttype)iftype(sorttype)=='function'thentable.sort(claims,sorttype)elseifsorttype=='chronological'thenreturnp.chronosort(claims)elseifsorttype=='inverted'thenreturnp.chronosort(claims,true)endreturnclaimsendfunctionp.getRawvalue(snak)returnp.getDatavalue(snak,{displayformat='raw'})endfunctionp.showentity(entity,lang)ifnotentitythenreturnnilendiftype(entity)=='string'thenentity=p.getEntity(entity)endifnotentityornotentity.typethenreturnformatError('entity-not-found')endlocallabel=p._getLabel(entity,lang)localid=entity.idlocallink=idifentity.type=='property'thenlink='Property:'..linkendreturn'[['..link..'|'..label..']] <small>('..id..')</small>'endlocalfunctionwikipediaLink(entity,lang)locallink=entity:getSitelink(lang..'wiki')iflinkthenreturn':'..lang..':'..linkendreturnnilendlocalfunctiongetLink(entity,typelink,lang)ifnottypelinkortypelink=='-'thenreturnnilendifnotlangthenlang=defaultlangendiftypelink=='wikidata'thenifentity.type=='property'thenreturn'd:P:'..entity.idelsereturn'd:'..entity.idendelseiftypelink=='wikipedia'thenreturnwikipediaLink(entity,lang)elseiftypelink=='anywikipedia'thenlocalfallbacklist=fb.fblist(lang)fori,lginpairs(fallbacklist)dolink=wikipediaLink(entity,lg)iflinkthenreturnlinkendendendreturnnilendlocalfunctionformattedLabel(label,entity,args)ifnotargsthenargs={}endlocallink=getLink(entity,args.link,args.lang)ifnotlinkthenlink=getLink(entity,defaultlink,args.lang)endifnotlinkthenreturnlabelelsereturn'[['..link..'|'..label..']]'endendfunctionp.getDatavalue(snak,params)ifisSpecial(snak)thenreturnnilendifnotparamsthenparams={}endlocaldisplayformat=params.displayformatlocaldatatype=snak.datavalue.typelocalvalue=snak.datavalue.valueifdatatype=='wikibase-entityid'theniftype(displayformat)=='function'thenreturndisplayformat(snak,params)endlocalprefix='Q'ifsnak.datavalue.value["entity-type"]=='property'thenprefix='P'endlocalid=prefix..tostring(value['numeric-id'])ifdisplayformat=='raw'thenreturnidelseifdisplayformat=='wikidatastyle'thenreturnp.showentity(id,params.lang)elsereturnp.formatEntity(id,params)endelseifdatatype=='string'thenlocalshowntext=params.showntextifdisplayformat=='weblink'thenifshowntextthenreturn'['..value..' '..showntext..']'elsereturnvalueendendifsnak.datatype=='math'anddisplayformat~='raw'thenvalue=mw.getCurrentFrame():extensionTag('math',value)endifparams.urlpatternthenvalue='['..mw.ustring.gsub(mw.ustring.gsub(params.urlpattern,'$1',value),' ','%%20')..' '..(showntextorvalue)..']'endreturnvalueelseifdatatype=='time'then-- format example: +00000001809-02-12T00:00:00Zifdisplayformat=='raw'thenreturnvalue.timeelsereturnobjectToText(dateObject(value),params)endelseifdatatype=='globecoordinate'then-- retourne une table avec clés latitude, longitude, précision et globe à formater par un autre module (à changer ?)ifdisplayformat=='latitude'thenreturnvalue.latitudeelseifdisplayformat=='longitude'thenreturnvalue.longitudeelseifdisplayformat=='qualifier'thenlocalcoord=require'Module:Coordinates'value.globe=require('Module:Wikidata/Globes')[value.globe]value.precision=nilreturncoord._coord(value)elsevalue.globe=require('Module:Wikidata/Globes')[value.globe]-- transforme l'ID du globe en nom anglais utilisable par geohackreturnvalue-- note : les coordonnées Wikidata peuvent être utilisée depuis Module:Coordinates. Faut-il aussi autoriser à appeler Module:Coordiantes ici ?endelseifdatatype=='quantity'then-- todo : gérer les paramètre précisionifdisplayformat=='raw'thenreturntonumber(value.amount)elselocalformatNum=require'Module:Formatnum'localnumber=formatNum.formatNum(value.amount)localunit=mw.ustring.match(value.unit,'(Q%d+)')ifunitthenlocalsymbol=p._formatStatements{entity=unit,property='P558',qualifier='P282',qualifiervalues={'Q8229'}}ifsymbolandsymbol~=''thennumber=number..'&nbsp;'..formattedLabel(symbol,p.getEntity(unit),{link='wikipedia'})elsenumber=number..'&nbsp;'..p.formatEntity(unit,params)endendreturnnumberendelseifdatatype=='monolingualtext'thenreturn'<span lang="'..value.language..'">'..value.text..'</span>'elsereturnformatError('unknown-datavalue-type',datatype)endendlocalfunctiongetMultipleClaims(args)localnewargs=argslocalclaims={}fori,jinpairs(args.property)donewargs.property=jlocalnewclaims=p.getClaims(args)ifnewclaimsthenfork,linpairs(newclaims)dotable.insert(claims,l)endendendreturnclaimsendfunctionp.getClaims(args)-- returns a table of the claims matching some conditions given in argsargs=removeBlanks(args)ifnotargs.propertythenreturnformatError('property-param-not-provided')endiftype(args.property)=='table'thenreturngetMultipleClaims(args)end--Get entityifargs.itemthen-- synonymsargs.entity=args.itemendlocalentity=args.entityiftype(entity)~='table'thenentity=p.getEntity(entity)endlocalproperty=string.upper(args.property)ifnotentityornotentity.claimsornotentity.claims[property]thenreturnnilendifentity.claimsandentity.claims.P21andentity.claims.P21[1]andentity.claims.P21[1].mainsnakandentity.claims.P21[1].mainsnak.datatype=='wikibase-item'and(entity.claims.P21[1].mainsnak.datavalue.value["numeric-id"]==6581072orentity.claims.P21[1].mainsnak.datavalue.value["numeric-id"]==1052281)thenargs.female=trueendifnotargs.rankthenargs.rank='best'endlocalclaims={}-- ~= '' lorsque le paramètre est écrit mais laissé blanc dans une fonction framefori,statementinpairs(entity.claims[property])doif(notargs.excludespecialornot(isSpecial(statement.mainsnak)))and(notargs.targetvalueorhasTargetValue(statement,args.targetvalue))and(notargs.qualifierorhasQualifier(statement,args.qualifier,args.qualifiervaluesorargs.qualifiervalue))and(notargs.withsourceorargs.withsource=='-'orhasSource(statement,args.withsource,args.sourceproperty))and(notargs.isinlanguageorisInLanguage(statement.mainsnak,args.isinlanguage))and(args.rank=='best'-- rank == best est traité à a finorhasRank(statement,args.rank))thentable.insert(claims,statement)endendif#claims==0thenreturnnilendifargs.rank=='best'thenclaims=bestRanked(claims)endifargs.sorttypethenclaims=p.sortclaims(claims,args.sorttype)endifargs.numvalthenreturnnumval(claims,args.numval)endreturnclaimsendfunctionp.formatClaimList(claims,args)ifnotclaimsthenreturnnilendfori,jinpairs(claims)doclaims[i]=p.formatStatement(j,args)endreturnclaimsendfunctionp.stringTable(args)-- like getClaims, but get a list of string rather than a list of snaks, for easier manipulationlocalclaims=p.getClaims(args)returnp.formatClaimList(claims,args)endlocalfunctiongetQualifiers(statement,qualifs,params)ifnotstatement.qualifiersthenreturnnilendlocalvals={}fori,jinpairs(qualifs)doj=string.upper(j)ifstatement.qualifiers[j]thenlocalinserted=falseifstatement.qualifiers[j][1].datatype=='monolingualtext'thenlocalin_preferred_langfor_,languageinpairs(fb.fblist(params.langordefaultlang))dofor_,snakinpairs(statement.qualifiers[j])doifisInLanguage(snak,language)thenin_preferred_lang=snakbreakendendifin_preferred_langthenbreakendendifin_preferred_langthentable.insert(vals,in_preferred_lang)inserted=trueendendifnotinsertedthenfor_,snakinpairs(statement.qualifiers[j])dotable.insert(vals,snak)endendendendif#vals==0thenreturnnilendreturnvalsendfunctionp.getFormattedQualifiers(statement,qualifs,params)ifnotparamsthenparams={}endlocalqualiftable=getQualifiers(statement,qualifs,params)ifnotqualiftablethenreturnnilendfori,jinpairs(qualiftable)dolocalparams=paramsifj.datatype=='globe-coordinate'thenparams.displayformat='qualifier'endqualiftable[i]=p.formatSnak(j,params)endreturnlinguistic.conj(qualiftable,params.langordefaultlang,params.qualifconjtypeor'')endfunctionp.formatStatement(statement,args)ifnotstatement.typeorstatement.type~='statement'thenreturnformatError('unknown-claim-type',statement.type)endifnotargsthenargs={}endlocallang=args.langordefaultlanglocalstr=p.formatSnak(statement.mainsnak,args)iftostring(args.showlang)=='true'thenstr=showLang(statement,str)endlocalqualifs=args.showqualifiersifqualifstheniftype(qualifs)=='string'thenqualifs=mw.text.split(qualifs,',')endlocalfoundvalues=p.getFormattedQualifiers(statement,qualifs,args)iffoundvaluesthenifargs.delimiterthenstr=str..args.delimiter..foundvalueselsestr=str..linguistic.inparentheses(foundvalues,lang)endendendifargs.showdatethen-- when "showdate and p.chronosort are both set, date retrieval is performed twicelocaltimedata=p.getDate(statement)iftimedatathenlocalformatteddate=objectToText(timedata,args)formatteddate=linguistic.inparentheses(formatteddate,lang)str=str..'<small>'..formatteddate..'</small>'endendifargs.showsourceandstatement.referencesthenlocalcite=require'Module:Wikidata/citeold'str=str..cite.formatReferences(statement.references,{})endreturnstrendfunctionp.formatSnak(snak,params)--local params = params or {} pour faciliter l'appel depuis d'autres modulesifsnak.snaktype=='value'thenreturnp.getDatavalue(snak,params)elseifsnak.snaktype=='somevalue'thenreturnformatTheUnknown()elseifsnak.snaktype=='novalue'thenreturni18n('novalue')--todoelsereturnformatError('unknown-snak-type',snak.snaktype)endendlocalfunctiondefaultLabel(entity,lang,displayformat)-- label when no label is availableifentityanddisplayformat=='id'thenreturnentity.idendreturni18n('no-label',lang)endfunctionp._getLabel(entity,lang,default)ifnotentitythenreturnnilendiftype(entity)~='table'thenentity=p.getEntity(entity)endifentityandentity.labelsthenfori,lginpairs(fb.fblist(langordefaultlang))doifentity.labels[lg]thenreturnentity.labels[lg].valueendendendreturndefaultLabel(entity,lang,default)endfunctionp._getDescription(entity,lang)ifnotentitythenreturni18n('no description')endiftype(entity)~='table'thenentity=p.getEntity(entity)endlocaldescriptions=entity.descriptionsifnotdescriptionsthenreturni18n('no description')endifdescriptions[lang]thenreturndescriptions[lang].valueendlocallanglist=fb.fblist(langordefaultlang)-- list of fallback languages if no label in the desired languagefori,lginpairs(langlist)doifdescriptions[lg]thenreturndescriptions[lg].valueendendreturni18n('no description')endfunctionp.getmainid(claim)ifclaimandnotisSpecial(claim.mainsnak)thenreturn'Q'..claim.mainsnak.datavalue.value['numeric-id']endreturnnilendfunctionp.formatEntity(entity,args)ifnotentitythenreturnnilendifnotargsthenargs={}endiftype(entity)=='string'thenentity=p.getEntity(entity)endlocalfemalelabel=nilifargs.femaleandentity.claimsandentity.claims.P2521thenfor_,statementinpairs(entity.claims.P2521)doif(isInLanguage(statement.mainsnak,args.langordefaultlang))thenfemalelabel=statement.mainsnak.datavalue.value.textbreakendendendlocallabelif(femalelabel)thenlabel=femalelabelelselabel=p._getLabel(entity,args.lang)endifnotlabelthenlabel=entity.idendreturnformattedLabel(label,entity,args)endfunctionp.getLabel(frame)-- simple for simple templates like {{Q|}}}localargs=frame.argslocalentity=args.entitylocallang=args.langiflang==''thenlang=defaultlangendifstring.sub(entity,1,10)=='Property:P'thenentity=string.sub(entity,10)elseif(string.sub(entity,1,1)~='P'andstring.sub(entity,1,1)~='Q')or(nottonumber(string.sub(entity,2)))thenreturni18n('invalid-id')endifnotargs.linkorargs.link==''then-- by default: no linkargs.link='-'endifargs.link=='-'thenreturnp._getLabel(entity,lang)ori18n('invalid-id')elsereturnp.formatEntity(entity,args)endendfunctionp._formatStatements(args)--Format statements and concat them cleanlyifargs.value=='-'thenreturnnilend--If a value is already set, use itifargs.valueandargs.value~=''thenreturnargs.valueendlocalvaluetable=p.stringTable(args)returntableToText(valuetable,args)endfunctionp.showQualifier(args)localqualifs=args.qualifiersorargs.qualifieriftype(qualifs)=='string'thenqualifs=mw.text.split(qualifs,',')endifnotqualifsthenreturnformatError('property-param-not-provided')endlocalclaims=p.getClaims(args)ifnotclaimsthenreturnnilendlocalstr=''fori,jinpairs(claims)dolocalnew=p.getFormattedQualifiers(j,qualifs,args)or''str=str..newendreturnstrendfunctionp._formatAndCat(args)localval=p._formatStatements(args)ifvalthenreturnval..addTrackingCat(args.property)endreturnnilendfunctionp.getTheDate(args)localclaims=p.getClaims(args)ifnotclaimsthenreturnnilendlocalformattedvalues={}fori,jinpairs(claims)dotable.insert(formattedvalues,p.getFormattedDate(j))endlocalval=linguistic.conj(formattedvalues)ifvalandargs.addcat==truethenreturnval..addTrackingCat(args.property)elsereturnvalendend---FONCTIONS depuis le FRAMEfunctionp.getaDate(frame)returnp.getTheDate(frame.args)endfunctionp.getQualifier(frame)returnp.showQualifier(frame.args)endfunctionp.getDescription(frame)-- simple for simple templates like {{Q|}}}localentity=frame.args.entitylocallang=frame.args.langreturnp._getDescription(entity,lang)ori18n('invalid-id')endfunctionp.formatStatements(args)returnp._formatStatements(args)endfunctionp.formatStatementsE(frame)localargs={}ifframe==mw.getCurrentFrame()thenargs=frame:getParent().args-- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)fork,vinpairs(frame.args)doargs[k]=vendelseargs=frameendreturnp._formatStatements(args)endfunctionp.formatAndCat(frame)localargs={}ifframe==mw.getCurrentFrame()thenargs=frame:getParent().args-- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)fork,vinpairs(frame.args)doargs[k]=vendelseargs=frameendreturnp._formatAndCat(args)endfunctionp.getEntityFromId(id)returnp.getEntity(id)end-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidatafunctionp.pageId(frame)localentity=mw.wikibase.getEntityObject()ifnotentitythenreturnnilelsereturnentity.idendend-- This is used to get a value, or a comma separated list of them if multiple values existp.getValue=function(frame)localpropertyID=mw.text.trim(frame.args[1]or"")localinput_parm=mw.text.trim(frame.args[2]or"")ifinput_parm=="FETCH_WIKIDATA"thenlocalentity=mw.wikibase.getEntityObject()localclaimsifentityandentity.claimsthenclaims=entity.claims[propertyID]endifclaimsthen-- if wiki-linked value output as link if possibleif(claims[1]andclaims[1].mainsnak.snaktype=="value"andclaims[1].mainsnak.datavalue.type=="wikibase-entityid")thenlocalout={}fork,vinpairs(claims)dolocalsitelink=mw.wikibase.sitelink("Q"..v.mainsnak.datavalue.value["numeric-id"])locallabel=mw.wikibase.label("Q"..v.mainsnak.datavalue.value["numeric-id"])iflabel==nilthenlabel="Q"..v.mainsnak.datavalue.value["numeric-id"]endifsitelinkthenout[#out+1]="[["..sitelink.."|"..label.."]]"elseout[#out+1]="[[:d:Q"..v.mainsnak.datavalue.value["numeric-id"].."|"..label.."]]<abbr title='"..i18n["errors"]["local-article-not-found"].."'>[*]</abbr>"endendreturntable.concat(out,", ")else-- just return best valuesreturnentity:formatPropertyValues(propertyID).valueendelsereturn""endelsereturninput_parmendendreturnp
close