Jump to content

Module:WikidataCheck

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}functionp.wikidatacheck(frame)localpframe=frame:getParent()localconfig=frame.args-- the arguments passed BY the template, in the wikitext of the template itselflocalargs=pframe.args-- the arguments passed TO the template, in the wikitext that transcludes the templatelocalproperty=config.propertylocalvalue=config.valueor""localcatbase=config.categorylocalnamespaces=config.namespaceslocalnocatsame=config.nocatsameor""localignorecase=config.ignorecaseor""localqid=config.qidor""localonlysourced=(config.onlysourced=='yes')orfalselocalok=false-- one-way flag to check if we're in a good namespacelocalns=mw.title.getCurrentTitle().namespaceforvinmw.text.gsplit(namespaces,",",true)doiftonumber(v)==nsthenok=trueendendifnotokthen-- not in one of the approved namespacesreturn""endlocalentityifqid==""thenentity=mw.wikibase.getEntityObject()elseentity=mw.wikibase.getEntityObject(qid)endifnotentitythen-- no Wikidata itemreturn"[[Category:"..catbase.." not in Wikidata]]"endifvalue==""thenreturnnil-- Using Wikidataendlocalclaims=entity.claimsor{}localhasProp=claims[property]ifnothasPropthen-- no claim of that propertyreturn"[[Category:"..catbase.." not in Wikidata]]"-- bad. Bot needs to add the propertyendifignorecase~=""thenvalue=string.lower(value)endfori,vinipairs(hasProp)do-- Now we try to iterate over all possible values?propValue=(v.mainsnak.datavalueor{}).valueifignorecase~=""thenpropValue=string.lower(propValue)endlocalsourced=false-- check for external refs a la Module:WikidataIB onlysourcedifv.referencesthenforj,vrinipairs(v.references)dolocalref=mw.wikibase.renderSnaks(vr.snaks)ifnotref:find("Wiki")thensourced=truebreakendendendifpropValue==valueand(notonlysourcedorsourced)thenifnocatsame==""thenreturn"[[Category:"..catbase.." same as Wikidata]]"-- yay!elsereturnnil-- if nocatsame, the "same as" category is not addedendendendreturn"[[Category:"..catbase.." different from Wikidata]]"-- needs human review :(endreturnp
close