Module:Wikidata2
لاسوند لپاره ددې موډيول کېدای سی په Module:Wikidata2/لاسوند کي وي
-- local fallback = {'en', 'nb', 'da', 'nn', 'de', 'fr', 'es', 'ps', 'pt'}local formatera = require('Module:Math')local i18n = {["errors"] = {["property-param-not-provided"] = "د ځانګړي الې پارامیټر نسو تر لاسه .",["entity-not-found"] = "Entity not found.",["unknown-claim-type"] = "Unknown claim type.",["unknown-snak-type"] = "Unknown snak type.",["unknown-datatype"] = "Unknown datatype.",["unknown-entity-type"] = "Unknown entity type.",["unknown-value-module"] = "You must set both value-module and value-function parameters.",["unknown-claim-module"] = "You must set both claim-module and claim-function parameters.",["unknown-property-module"] = "You must set both property-module and property-function parameters.",["property-module-not-found"] = "The module pointed by property-module not found.",["property-function-not-found"] = "The function pointed by property-function not found.",["value-module-not-found"] = "The module pointed by value-module not found.",["value-function-not-found"] = "The function pointed by value-function not found.",["claim-module-not-found"] = "The module pointed by claim-module not found.",["claim-function-not-found"] = "The function pointed by claim-function not found." },["nopashtolabel"] = "وېشنيزه:په ويکيډاټا کې غير پښتو نښانونه",["warnDump"] = "[[Category:Called function 'Dump' from module Wikidata]]",["somevalue"] = "", --''غير محدد''["novalue"] ="",--قيمة مجهولة["cateref"] ="[[وېشنيزه:مخونه د ويکيډاټا د سرچينو سره]]"}local sortingproperties = {'P585','P571','P580','P569','P582','P570','P1082'}function catewikidatainfo(options)local prop = options.propertylocal catewikidatainfo = ' [[وېشنيزه:د ويکيډاټا توکو کارونکي مخونه|'.. (prop or 'wikidata')..']]'if (not options.nolink or options.nolink == '') then return catewikidatainfo else return ''endend--auktoritetsdatafunction formatcharacters(label, options)local formatcharacters = options.formatcharacters--if options.FormatfirstCharacter and options.num == 1 then --formatcharacters = options.FormatfirstCharacter --endif options.illwd2y and options.illwd2y ~= '' thenString2 = mw.ustring.gsub( label , '–', '-' )ca = mw.ustring.match( String2 , "%d%d%d%d%-%d%d%d%d", 1 ) or mw.ustring.match( String2 , "%d%d%-%d%d%d%d", 1 )ca = ca or mw.ustring.match( String2 , "%d%d%d%d", 1 ) or mw.ustring.match( String2 , "%d%d%d%d%-%d%d", 1 )ca = ca or mw.ustring.match( String2 , "%d%d%d%d", 1 ) or Stringreturn caendif not formatcharacters or formatcharacters == '' thenreturn labelendif formatcharacters == 'lcfirst' thenreturn mw.getCurrentFrame():preprocess("{{lcfirst: " .. label .. " }}")elseif formatcharacters == 'ucfirst' thenreturn mw.language.getContentLanguage():ucfirst( label )elseif formatcharacters == 'lc' thenreturn mw.getCurrentFrame():preprocess("{{lc: " .. label .. " }}")elseif formatcharacters == 'uc' thenreturn mw.getCurrentFrame():preprocess("{{uc: " .. label .. " }}")endreturn labelendfunction getqualifierbysortingproperty(claim, sortingproperty)for k, v in pairs(sortingproperty) doif claim.qualifiers and claim.qualifiers[v] and claim.qualifiers[v][1].snaktype == 'value' thenreturn claim.qualifiers[v][1].datavalue.value.time endendreturn nilendfunction getDate(claim, options)local sortingproperty = sortingpropertiesif type(options.sortingproperty) == 'table' thensortingproperty = options.sortingpropertyelseif type(options.sortingproperty) == 'string' thensortingproperty = {options.sortingproperty}endreturn getqualifierbysortingproperty(claim, sortingproperty) endfunction get_entityId(options)local id = options.entityIdif not id or id == "" thenif options.page and options.page ~= "" thenid = mw.wikibase.getEntityIdForTitle( options.page )endend--mw.log("id :" .. id)return id or ""endfunction getDatePus(claim, options)local sortingproperty = options.sortingproperty or 'P569'if claim.mainsnak.snaktype == 'value' thenlocal item = claim.mainsnak.datavalue.value['numeric-id']if claim.mainsnak.datavalue.value['entity-type'] == 'item' thenitem = 'Q' .. itemelseif claim.mainsnak.datavalue.value['entity-type'] == 'property' then item = 'P' .. itemendreturn formatStatements({property = sortingproperty, entityId = item, enbarten = 'true', sortbytime = 'chronological', noref = 'true'})endendfunction descriptionIn(langcode , id) -- returns item description for a given languagelocal lan = langcode or 'ps'if not mw.wikibase then return nil endlocal description, lange = mw.wikibase.getDescriptionWithLang( id )if lange == lanthenreturn descriptionelsereturn nil--return strend--[[local entity = mw.wikibase.getEntityObject(id)if entityand entity.descriptions and entity.descriptions[''..lan..'']and entity.descriptions[''..lan..''].value thenlocal lang = entity.descriptions[''..lan..'']if lang['language'] == lan thenreturn entity.descriptions[''..lan..''].valueelse return nil endend]]endfunction labelIn(langcode,id) -- returns item label for a given languageif not mw.wikibase then return nil endlocal lan = langcode or 'ps'local label, lange = mw.wikibase.getLabelWithLang( id )if lange == lanthenreturn labelelsereturn nil--return strend--[[local entity = mw.wikibase.getEntityObject(id)if entityand entity.labels and entity.labels[''..lan..'']and entity.labels[''..lan..''].value thenlocal lang = entity.labels[''..lan..'']if lang['language'] == lan thenreturn entity.labels[''..lan..''].valueelse return nil endend]]endfunction get_snak_id(snak)if snak and snak.type and snak.type == "statement" and snak.mainsnak and snak.mainsnak.snaktype and snak.mainsnak.snaktype == "value" and snak.mainsnak.datavalue and snak.mainsnak.datavalue.typeand snak.mainsnak.datavalue.type == "wikibase-entityid" and snak.mainsnak.datavalue.value and snak.mainsnak.datavalue.value.id then--ID = 'Q' .. snak.datavalue.value['numeric-id']ID = snak.mainsnak.datavalue.value.id return IDendendfunction comparedates(a, b) -- returns true if a is earlier than B or if a has a date but not bif a and b thenreturn a > belseif a thenreturn trueendendfunction preferqualifier(claims, options)mw.log("preferqualifier: " .. options.preferqualifier)local claims2 = {}for i, statement in pairs( claims ) do -- if statement.qualifiers and statement.qualifiers[options.preferqualifier:upper()] thenif options.preferqualifiervalue and options.preferqualifiervalue ~= '' thenlocal active = falsefor k, t in pairs(mw.text.split(options.preferqualifiervalue,',')) do--mw.log( "t " .. t )--kaso = formatStatements({property=options.preferqualifier:upper(), raw = 'true', formatting = 'raw'}, statement.qualifiers)kaso = formatStatements({property=options.preferqualifier:upper(), formatting = 'raw'}, statement.qualifiers)value = kaso--for j, value in pairs( kaso ) do--mw.log( "value " .. value )if value == t and not active then--if value == t and not active thentable.insert( claims2, statement)active = trueend--endendelsetable.insert( claims2, statement)endendendreturn claims2endfunction sortbyqualifier(claims, options)table.sort(claims, function(a,b)local timeA = getDate(a, options)local timeB = getDate(b, options)if options.sortbytime == 'inverted' thenreturn comparedates(timeB, timeA)elsereturn comparedates(timeA, timeB)endend)return claimsendfunction sortbypus(claims, options)table.sort(claims, function(a,b)local timeA = getDatePus(a, options)local timeB = getDatePus(b, options)if options.sortbyarbitrary == 'inverted' thenreturn comparedates(timeB, timeA)elsereturn comparedates(timeA, timeB)endend)return claimsendfunction Labelfunction( entityId, label ,labeloption , options) -- label with no pswiki sitelinkif options.illwd2nowd and options.illwd2nowd ~= '' then noWD='' else noWD='y' endlocal jlabel = label --formatcharacters(label, options) -- The labellocal ps = labelIn('ps',entityId ) -- The pashto labellocal pslabel = ps --formatcharacters(ps, options) if labeloption and labeloption ~= '' thenjlabel = labeloption elseif options.illwd2 and options.illwd2 ~= '' thenif pslabel and pslabel ~= '' thenjlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {pslabel, id=entityId, y = (options.illwd2y or '') } }else jlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {id=entityId, target='en', y = (options.illwd2y or '') } }endelseif options.enlabelcate and options.enlabelcate ~= '' thenif not pslabel or pslabel == '' thenjlabel = label --formatcharacters(label, options) if jlabel and jlabel ~= '' then jlabel = jlabel ..' [['.. i18n.nopashtolabel ..'|'.. entityId ..']]'end endelse--if options.justpashto and options.justpashto ~= '' thenif pslabel and pslabel ~= ''then jlabel = pslabelelse jlabel = nilendendif jlabel and jlabel ~= ''thenreturn jlabel.. catewikidatainfo(options)endendfunction getEntityFromId( id ) if not mw.wikibase then return nil endif id and id ~= "" thenreturn mw.wikibase.getEntityObject( id )elsereturn mw.wikibase.getEntityObject() endend function getEntityIdFromValue( value ) if value['entity-type'] == 'item' then return 'Q' .. value['numeric-id'] elseif value['entity-type'] == 'property' then return 'P' .. value['numeric-id'] else return formatError( 'unknown-entity-type' ) endend function formatError( key ) return i18n.errors[key]endfunction formatOneStatement( statement ,ref , options)local vava = nillocal stat = formatStatement( statement, options )if stat thenlocal s = stat.valuelocal d = stat.datumlocal tf = stat.tifrlocal awardqual = stat.fotolocal pr = stat.pr--local utgivort = stat.utgivortlocal ro = stat.rolocal qp1a = stat.qp1alocal onlyqualifier = stat.onlyqualifierlocal qp1 = stat.qp1local qp2 = stat.qp2local qp3 = stat.qp3local qp4 = stat.qp4local qp5 = stat.qp5local amatch =stat.amatchlocal reff =stat.refflocal goal =stat.goallocal start2 = stat.start1local finish2 = stat.finish1local before2 = stat.before1local after2 = stat.after1local constituency2 = stat.constituency1local series2 = stat.series1local electedin2 = stat.electedin1local P1001 = stat.pp1001local P108 = stat.pp108local P642 = stat.pp642if s == '' then s = nil endif s thenif reff and options.reff and options.reff ~= '' thens= s .. reffendif options.template and options.template ~= '' thens = mw.getCurrentFrame():expandTemplate{ title = options.template , args ={stat.QQ1,s,stat.QQ2,stat.QQ3,stat.QQ4,stat.QQ5,stat.QQ6,stat.QQ7,stat.QQ8,stat.QQ9,stat.QQ10} }endif options.football and options.football ~= '' thens =mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args = {(start2 or ''),(finish2 or '') ,s,amatch,goal } }endif options.office and options.office ~= '' thens = mw.getCurrentFrame():expandTemplate{ title = "معلومات صاحب منصب/منصب ويكي بيانات/نواة", args = {office = s, termstart = start2, termend = finish2, constituency = constituency2, predecessor = before2, successor = after2, series= series2,of=P642,electedin=electedin2,jurisdiction=P1001,employer=P108,entityId=options.entityId} } endfunction qoo(Prefix,qualpref,p,Suffix)if p and p ~='' then return mw.text.tag('small', {}, (Prefix or ' (').. (qualpref or '') .. p .. (Suffix or ')')) endendQPrefix = options.qualifierprefixQSuffix = options.qualifiersuffixif qp1 and qp1 ~='' and options.qual1 and options.qual1 and qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= ''thens = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix)elseif qp1 and qp1 ~='' and options.qual1 and options.qual1 ~= '' thens = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix)elseif qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= '' thens = s .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix)endif qp2 and qp2 ~='' and options.qual2 and options.qual2 ~= '' then s = s .. qoo(QPrefix, options.qual2pref, qp2, QSuffix) endif qp3 and qp3 ~='' and options.qual3 and options.qual3 ~= '' then s = s .. qoo(QPrefix, options.qual3pref, qp3, QSuffix) endif qp4 and qp4 ~='' and options.qual4 and options.qual4 ~= '' then s = s .. qoo(QPrefix, options.qual4pref, qp4, QSuffix) endif qp5 and qp5 ~='' and options.qual5 and options.qual5 ~= '' then s = s .. qoo(QPrefix, options.qual5pref, qp5, QSuffix) endif options.justthisqual and options.justthisqual ~= '' then if onlyqualifier then s = onlyqualifier else s = nil end end -- We need only the qualifier if ro and ro ~='' and options.withro and options.withro ~= '' then s = s .. qoo(QPrefix, '' , ro, QSuffix) endif d and d ~='' and options.withdate and options.withdate ~= '' thenif options.withdate == 'y' then s = s .. qoo(QPrefix, 'کال ' , d, QSuffix)elseif options.withdate == 'before' then s = '*' .. d ..':' .. s..'\n'else s = s .. qoo(QPrefix, '' , d, QSuffix)endendif awardqual and options.awardqua and options.awardqua ~= '' then s = s .. qoo(QPrefix, '' , awardqual, QSuffix) endif tf and options.bothdates and options.bothdates ~= '' thenif options.bothdates == 'line' then s = s .. mw.text.tag('br') .. qoo(QPrefix, '' , tf, QSuffix)elseif options.bothdates == 'before' then s = qoo(QPrefix, '' , tf, QSuffix) .. selse s = s .. qoo(QPrefix, '' , tf, QSuffix)endend--if utgivort and options.withutgivort and options.withutgivort ~= '' then--if options.withutgivort == 'قوسين' then s = s .. ' ' .. qoo(QPrefix, '' , utgivort, QSuffix)--else s = s .. ' ' .. utgivort--end--endif pr and pr ~= '' and options.getsimpleproperty and options.getsimpleproperty ~= '' thenif options.getsimpleproperty == 'f?dd' then s = s .. ' ' .. qoo(QPrefix, 'f. ' , pr, QSuffix)elseif options.getsimpleproperty == 'parentes' then s = s .. ' ' .. qoo(QPrefix, '' , pr, QSuffix)elseif options.getsimpleproperty == 'avn?gon' then s = s .. ' ' .. mw.text.tag('span', {}, ' av ' .. pr .. '')endendif type(ref) == 'table' or (options.noref and options.noref ~='') or (options.justthisqual and options.justthisqual ~='') then--table.insert( formattedStatements, s )vava = s elselocal t = formatReferences( statement, options )stat.ref = tif options.justref and options.justref ~= '' thenvava = telseif options.onlyvaluewithref and options.onlyvaluewithref ~= '' thenif t and t ~= "" thenvava = s .. t endelse vava = s .. t endendend--table.insert(statementsraw, stat)endreturn { v = vava , raw = stat}endfunction formatStatements( options, ref ) local formattedStatements = {} local claims = {} if not options.property then return formatError( 'property-param-not-provided' ) end if type(ref) == 'table' then -- f?r de fall d?r funktionen anropas och alla claims redan finns i en tabellclaims = ref[options.property] or {}else --Get entity local entity = nil if options.entity and type( options.entity ) == "table" then entity = options.entity else --entity = getEntityFromId( options.entityId ) id = get_entityId( options ) entity = getEntityFromId( id ) end if not entity then return '' end --TODO error? if not entity.claims or not entity.claims[options.property:upper()] then return '' --TODO error? end --Format statement and concat them cleanlyif options.rank == 'best' or not options.rank then claims = entity:getBestStatements( options.property:upper() )elseif options.rank == 'valid' thenfor i, statement in pairs( entity.claims[options.property:upper()] ) do if statement.rank == 'preferred' or statement.rank == 'normal' then table.insert( claims, statement ) endendelseif options.rank == 'all' thenfor i, statement in pairs( entity.claims[options.property:upper()] ) dotable.insert( claims, statement )endelsefor i, statement in pairs( entity.claims[options.property:upper()] ) doif statement.rank == options.rank thentable.insert( claims, statement )endendend--======================================================if options.avoidqualifier then -- to avoid value with a given qualifierlocal claims2 = {}for i, statement in pairs( claims ) doif not statement.qualifiers or not statement.qualifiers[options.avoidqualifier:upper()] thentable.insert( claims2, statement)endendclaims = claims2end--======================================================if options.preferqualifier and options.preferqualifier ~= '' thenclaims = preferqualifier(claims, options)end--======================================================--om det finns vissa statements som har en qualifier som s?ger "spr?k = svenska", ta bara med dessa--alternativt om det finns statements som har en qualifier som s?ger "skriptsystem == latinska alfabetet"if not options.langpref or options.langpref == '' thenlocal claims2 = {}for i, statement in pairs( claims ) doif statement.qualifiers and statement.qualifiers.P407 thenfor k, v in pairs( statement.qualifiers.P407 ) doif v.snaktype == 'value' and v.datavalue.value['numeric-id'] == 1617 then -- Q58680 = 'پښتو'table.insert( claims2, statement )endendelseif statement.qualifiers and statement.qualifiers.P282 thenfor k, v in pairs( statement.qualifiers.P282 ) doif v.snaktype == 'value' and v.datavalue.value['numeric-id'] == 209468 then -- Q209468 = 'پښتو ټکي ټايپ کړې'table.insert( claims2, statement )endendendendif #claims2 > 0 thenclaims = claims2endendif options.sortbytime == 'chronological' or options.sortbytime == 'inverted' thenclaims = sortbyqualifier(claims, options)elseif options.sortbyarbitrary == 'chronological' or options.sortbyarbitrary == 'inverted' thenclaims = sortbypus(claims, options)endendif options.enbarten and options.enbarten ~= '' and #claims > 1 thenclaims = {claims[1]}endlocal statementsraw = {}if claims then--==========================================if options['property-module'] or options['property-function'] thenif not options['property-module'] or not options['property-function'] thenreturn formatError( 'unknown-property-module' )endlocal formatter = require ('Module:' .. options['property-module'])if not formatter thenreturn formatError( 'property-module-not-found' )endlocal fun = formatter[options['property-function']]if not fun thenreturn formatError( 'property-function-not-found' )endmw.log("work with property-module: " .. options['property-module'] .. "|" .. options['property-function'])return fun( claims, options )else --==========================================for i, statement in pairs( claims ) dooptions.num = ilocal va = formatOneStatement( statement,ref, options )if va.v thentable.insert( formattedStatements, va.v )endtable.insert( statementsraw, va.raw )endendendlocal Separator = options.separator-- or ""local Conjunction = options.conjunction-- or ""if Conjunction and Conjunction == "br" then Conjunction = "\n" endif Separator and Separator == "br" then Separator = "\n" Conjunction = "\n" endlocal tot = mw.text.listToText( formattedStatements, Separator, Conjunction )if tot == '' then tot = nil endif options.raw and options.raw ~= '' thenreturn statementsrawendreturn totendfunction formatReferences( statement, options )local reference = {}if statement.references thenlocal cite = require('Module:Cite')for i, ref in pairs(statement.references) dolocal items = {}if ref.snaks thens = cite.citeitem2(ref , options )--s = cite.citeitem( items , ref.snaks , ref.hash , options )endtable.insert(reference, s)endendlocal final = table.concat(reference)if final and final ~= '' thenfinal = final .. i18n.caterefendreturn finalendfunction formatqualifiers( statement,s, options )function qua(p,enbarten,modifytime)if p and p ~='' then return (formatStatements({property =p,enlabelcate = 't', enbarten = (enbarten or ''),modifytime = (modifytime or 'longdate'), noref = 'true'}, statement.qualifiers) or '') endendif options.template and options.template ~= '' thens.QQ1 = qua(options.Q1)s.QQ2 = qua(options.Q2)s.QQ3 = qua(options.Q3)s.QQ4 = qua(options.Q4)s.QQ5 = qua(options.Q5)s.QQ6 = qua(options.Q6)s.QQ7 = qua(options.Q7)s.QQ8 = qua(options.Q8)s.QQ9 = qua(options.Q10)s.QQ10 = qua(options.Q10)endif statement.qualifiers.P1350 or statement.qualifiers.P1351 thens.amatch = qua("P1350",'true')s.goal = qua("P1351",'true')endif statement.qualifiers.P580 or statement.qualifiers.P582 or statement.qualifiers.P1365 or statement.qualifiers.P1366 thens.start1 = qua("P580",'true')s.finish1 = qua("P582",'true')s.before1 = qua("P1365",'true')s.after1 = qua("P1366",'true')s.constituency1 = qua("P768")s.series1 = qua("P1545")s.electedin1 = qua("P2715",'')s.pp1001 = qua("P1001")s.pp108 = qua("P108")s.pp642 = qua("P642")endif statement.qualifiers.P585 thens.datum = qua("P585",'true',options.modifyqualifiertime)end local qwe = options.qwerif statement.qualifiers.qwe thens.ro = qua(qwe,'true')endif statement.qualifiers.P574 thens.dateoftaxpub = qua("P574",'true',options.modifyqualifiertime)endif statement.qualifiers.P405 thenlocal author = {}for i, j in pairs(statement.qualifiers.P405) doif j.snaktype == 'value' thenlocal item = 'Q' .. j.datavalue.value['numeric-id']local authorname = formatStatements({property = "P428", entityId = item, noref = 'true', enbarten = 'true'})if author and authorname ~= '' thentable.insert(author, formatEntityId(item, {label = authorname }).value)elsetable.insert(author, formatEntityId(item, {}).value)endendends.auktor = mw.text.listToText(author, ', ', ' & ')endif statement.qualifiers.P580 or statement.qualifiers.P582 thenlocal f = qua("P580",'true',options.modifyqualifiertime)local t = qua("P582",'true',options.modifyqualifiertime)s.tifr = f .. '–' .. tendif statement.qualifiers.P585 or statement.qualifiers.P1346 thenlocal fo = qua("P585",'true',options.modifyqualifiertime)local to = qua('P1346','true')s.foto = fo .. ' ' .. mw.text.tag('span', {}, ' ' .. to .. '')endfunction quaaal(opti,options)if opti and opti ~='' and statement.qualifiers[opti] thenreturn (formatStatements({property = opti, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction,size =options.size,image =options.image, modifytime = options.modifyqualifiertime,enlabelcate = 't',langpref = options.langpref,showlang = options.showlang}, statement.qualifiers) or '')endend--if statement.qualifiers.P291 then -- خاصية بلد النشر--s.utgivort = quaaal('P291',options)--endif statement.qualifiers.P2096 thens.bildtext = formatStatements({property = "P2096", noref = 'true', langpref = (options.langpref or 'ps')}, statement.qualifiers)endif options.justthisqual and options.justthisqual ~= '' and statement.qualifiers[options.justthisqual] thens.onlyqualifier = quaaal(options.justthisqual,options)endif options.qual1 and options.qual1 ~= '' and statement.qualifiers[options.qual1] then s.qp1 = quaaal(options.qual1,options) endif options.qual1a and options.qual1a ~= '' and statement.qualifiers[options.qual1a] then s.qp1a = quaaal(options.qual1a,options) endif options.qual2 and options.qual2 ~= '' and statement.qualifiers[options.qual2] then s.qp2 = quaaal(options.qual2,options) endif options.qual3 and options.qual3 ~= '' and statement.qualifiers[options.qual3] then s.qp3 = quaaal(options.qual3,options) endif options.qual4 and options.qual4 ~= '' and statement.qualifiers[options.qual4] then s.qp4 = quaaal(options.qual4,options) endif options.qual5 and options.qual5 ~= '' and statement.qualifiers[options.qual5] then s.qp5 = quaaal(options.qual5,options) endendfunction formatStatement( statement, options ) if options['claim-module'] or options['claim-function'] thenif not options['claim-module'] or not options['claim-function'] then return {value = formatError( 'unknown-claim-module' )} end local formatter = require ('Module:' .. options['claim-module']) if not formatter then return {value = formatError( 'claim-module-not-found' )} end local fun = formatter[options['claim-function']] if not fun then return {value = formatError( 'claim-function-not-found' )} end return {value = fun( statement, options )} elseif statement.type == 'statement' then local s = formatSnak( statement.mainsnak, options ) if s and s ~= '' thenif statement.references thenif options.reff and options.reff ~= '' thens.reff = formatReferences( statement, options )end endif statement.qualifiers thenqualu = formatqualifiers( statement,s, options )if qualu and qualu ~= '' then table.insert(qualu) endendendreturn selseif not statement.type thenreturn formatSnak( statement, options ) endreturn {value = formatError( 'unknown-claim-type' )}end function formatSnak( snak, options ) if snak.snaktype == 'somevalue' then if options.somevalue then if options.somevalue == '' then return nil else return {value = options.somevalue} end end return {value = i18n['somevalue']} elseif snak.snaktype == 'novalue' then if options.novalue then if options.novalue == '' then return nil else return {value = options.novalue} end end return {value = i18n['novalue']} elseif snak.snaktype == 'value' then local s = formatDatavalue( snak.datavalue, snak.datatype, options ) if s and s.value and options.prefix and options.prefix ~= '' then s.value = options.prefix .. s.value end if s and s.value and options.suffix and options.suffix ~= '' then s.value = s.value .. options.suffix end if s and s.item and options.getsimpleproperty and options.getsimpleproperty ~= '' and options.getproperty and options.getproperty ~= '' then local pr = formatStatements({property = options.getproperty, entityId = s.item, enbarten = options.getenbarten, noref = 'true', modifytime = options.getmodifytime, raw = options.getraw}) if pr then s.pr = pr end end return s else return {value = formatError( 'unknown-snak-type' )} endend --[[ datatype wikibase-item ]]function formatwikibaseitem( datavalue, datatype, options ) if options.formatting and options.formatting ~= '' thenif options.formatting == 'raw' then return {value = getEntityIdFromValue( datavalue.value )}elseif options.formatting == 'fu' then return {value = mw.getCurrentFrame():expandTemplate{ title = "Cycling race/stageclassification1", args = {getEntityIdFromValue( datavalue.value )}} }elseif options.formatting == 'sitelink' then -- for Wikidata property giving Wikimedia listreturn {value = formatsitelink(datavalue.value.id , options ) }elsereturn {value = formatFromPattern( formatcharacters(datavalue.value, options), options )}endelseif options.property1 and options.property1 ~= '' thenfor i, statement in pairs( datavalue ) do local entit = getEntityIdFromValue( datavalue.value ) local caca = formatStatements( {property =options.property1, entityId = entit, noref =options.noref ,rank=options.rank,pattern =options.property1pattern,formatting=options.property1formatting,size =options.size,image =options.image,noref='true',enbarten ='true' }) local asdf = formatEntityId( entit , options ).value if asdf and asdf ~= '' thenif caca and caca ~= '' then local cooooca = (options.property1pref or '') ..''.. caca ..''.. (options.property1suff or '')if options.property1after and options.property1after ~= "" thenreturn {value = asdf .. cooooca } elsereturn {value = cooooca .. ' '.. asdf } endelsereturn {value = asdf }endend end elseif options.propertyimage and options.propertyimage ~= '' thenfor i, statement in pairs( datavalue ) do local entit = getEntityIdFromValue( datavalue.value ) local caca = formatStatements( {property =options.propertyimage , entityId = entit, noref =options.noref ,rank=options.rank,pattern =options.pattern,formatting =options.propertyimageformatting ,size =options.size,image =options.image,noref='true',enbarten ='true' }) local asdf = formatEntityId( entit , options ).value if caca and caca ~= '' then return {value = caca } else end end elseif options.property2 and options.property2 ~= '' thenfor i, statement in pairs( datavalue ) do local entit = getEntityIdFromValue( datavalue.value ) local caca = formatStatements( {property =options.property2, entityId = entit, noref =options.noref ,rank=options.rank,pattern =options.property2pattern,size =options.size,image =options.image,propertyimage =options.property3,enbarten ='true' }) local asdf = formatEntityId( entit , options ).value if asdf and asdf ~= '' then if caca and caca ~= '' then return {value = caca .. ' '.. asdf } else return {value = asdf } endend end elsereturn {value = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).value, item = getEntityIdFromValue( datavalue.value )} end end --[[ datatype wikibase-property ]]function formatwikibaseproperty( datavalue, datatype, options )if options.formatting and options.formatting ~= '' thenif options.formatting == 'raw' then tid = getEntityIdFromValue( datavalue.value )elseendelse tid = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).valueendreturn {value = tid}end --[[ tabulps-data ]]function formattabulpsdata( datavalue, datatype, options )data= '[[commons:' .. datavalue.value .. '|' .. datavalue.value .. ']]'return {value = data}end --[[ geo-shape ]]function formatgeoshape( datavalue, datatype, options )shape = '[[commons:' .. datavalue.value .. '|' .. datavalue.value .. ']]'return {value = shape}end --[[ commonsMedia ]]function formatcommonsMedia( datavalue, datatype, options ) if options.image and options.image ~= '' then -- return real imagetid = '[[file:' .. datavalue.value .. '|'.. (options.size or '60')..'px|'..'border'..']]' elsetid = formatcharacters(datavalue.value, options) endreturn {value = tid}end --[[ datatype math ]]function formatmath( datavalue, datatype, options ) --return{value = mw.text.tag('math', {}, ''.. datavalue.value..'') } -- that doesn't work well return{value =mw.getCurrentFrame():callParserFunction( '#tag:math', ''.. datavalue.value..'' ) }end --[[ datatype string - external-id ]] function formatstring( datavalue, datatype, options )--old value: auktoritetsdata , auktoritetsdata2 , auktoritetsdata3if options.pattern and options.pattern ~= '' thenpar = options.patternif par == "autourl" or par == "autourl2" or par == "autourl3" or par == "autourl4"then tid = formatcharacters(datavalue.value, options)else tid = formatFromPattern( formatcharacters(datavalue.value, options), options )endelse tid = formatcharacters(datavalue.value, options)endreturn {value = tid}endfunction formatexternalid( datavalue, datatype, options )if options.pattern and options.pattern ~= '' thenpar = options.patternlocal patter = formatStatements( {property = "P1630", entityId = options.property, enbarten = 'true', noref = 'true',rank='all' }) -- get formatter URL--mw.log( options.property .. ':' .. patter )local pp = formatFromPattern( datavalue.value, {pattern = patter} )local plabel = pp if mw.wikibasethen plabel = mw.wikibase.label( options.property ) or pp end ppp = mw.ustring.gsub( pp, ' ', '_' )if patter and patter ~= '' then -- if P1630 are thereif par == "autourl" then -- like http://example.com/$1.html tid = pppelseif par == "autourl2" then -- like [http://example.com/$1.html $1] tid = '[' .. ppp .. ' ' .. datavalue.value .. ']' elseif par == "autourl3" then -- like [http://example.com/$1.html http://example.com/$1.html] tid = '[' .. ppp .. ' ' .. ppp .. ']' elseif par == "autourl4" then tid = '[' .. ppp .. ' ' .. plabel .. ']' elsetid = formatFromPattern( formatcharacters(datavalue.value, options), options )endelse -- P1630 are not thereif par == "autourl" or par == "autourl2" or par == "autourl3" or par == "autourl4"thentid = formatcharacters(datavalue.value, options) --just return valueelsetid = formatFromPattern( formatcharacters(datavalue.value, options), options )endendelse tid = formatcharacters(datavalue.value, options) --just return valueendreturn {value = tid}end --[[ datatype time ]]function formattime( datavalue, datatype, options ) local ModuleTime = require 'Module:wikidata2/time' local timen = datavalue.value local modifytime = (options.modifytime or '') local tid = ModuleTime.getdate( timen , options) -- local tid = mw.getCurrentFrame():preprocess(mall) if options.modifytime and options.modifytime ~= '' thenif options.modifytime == 'q' thenlocal mall = datavalue.value.timetid = mw.getCurrentFrame():preprocess(mall)elseif options.modifytime == 'precision' thenlocal mall = datavalue.value.precisiontid = mw.getCurrentFrame():preprocess(mall)endendreturn {value = tid}end--[[ datatype globe-coordinate ]] function formatcoordinate( datavalue, datatype, options ) --local GlobeCoordinate = require 'Module:GlobeCoordinate' --return {value = GlobeCoordinate.newFromWikidataValue( datavalue.value ):toHtml()}local coord = datavalue.value local globe = datavalue.value.globe--local globe = globe:match('Q%d+')globe2 = require('Module:Wikidata2/Globes')[globe]if options.formatting and options.formatting ~= '' thenif options.formatting == 'latitude' then pro =coord.latitude elseif options.formatting == 'longitude' then pro =coord.longitude elseif options.formatting == 'dimension' then pro =coord.dimension elseif options.formatting == 'precision' then pro =coord.precision elseif options.formatting == 'globe' then pro = globe:match('Q%d+') elseif options.formatting == 'globe2' then pro = globe2 --elseif options.formatting == 'coord' then--return {value = }elseendelsepro =mw.getCurrentFrame():preprocess('{{ {{{|safesubst:}}}#invoke:Coordinates|coord'.. '|'.. coord.latitude.. '|'.. coord.longitude.. '|display=inline'.. '|globe:'.. globe2 ..'_type:landmark'.. '|format='..(options.formatcoord or '')..'}}')..catewikidatainfo(options) endreturn {value = pro }end --[[ datatype quantity ]] function formatquantity( datavalue, datatype, options )local amount, unit, cat = datavalue.value.amount, datavalue.value.unit, nilif unit thenunit = unit:match('Q%d+')endlocal formatera = require('Module:Math')local number = formatera.newFromWikidataValue(datavalue.value)amount = mw.ustring.gsub( amount , '+', '' )local unitraw = unitif unit then-- يتحقق اذا كان هناك اي اختصار لوحدة القياسlocal lab = options.label or formatStatements({property = 'P498', entityId = unit, enbarten = 'true', noref = 'true'}) or formatStatements({property = 'P558', entityId = unit, enbarten = 'true', langpref = options.langpref, noref = 'true'})if lab and ( not options.nounitshort or options.nounitshort == '' ) thenlocal s = formatEntityId( unit, {label = lab ,enlabelcate ='t' , nolink = (options.nounitlink or options.nolink) })unit = s.valuecat = s.catelse -- om det inte finns en f?rkortninglocal s = formatEntityId( unit, {nolink = options.nounitlink ,enlabelcate ='t'})unit = s.valuecat = s.catendendlocal Value = amount .. ' ' .. (unit or '')if options.nounit and options.nounit ~= "" thenValue = amountendreturn {value = Value, amount = amount, unit = unit, unitraw = unitraw, cat = cat}end --[[ datatype url ]] function formaturl( datavalue, datatype, options )local label = options.label or options.urllabel va = mw.ustring.gsub( datavalue.value, ' ', '_' )if not label and options.property =='P856' then label = 'د تاييدولو سرچينه' endif label and label ~= '' thenpro = '[' .. va .. ' ' .. label .. ']' else--if property =='P856' then pro = formatFromPattern( formatcharacters(va, options), {pattern = '[$1 د تاييدولو سرچينه]'} )--elsepro = va--endendreturn {value = pro }end --[[ datatype monolingualtext ]] function formatmonolingualtext( datavalue, datatype, options ) local Moduletext = require 'Module:wikidata2/monolingualtext' local tid = Moduletext._main( datavalue, datatype, options )return {value = tid}endfunction formatDatavalue( datavalue, datatype, options ) --Use the customize handler if provided if options['value-module'] or options['value-function'] then if not options['value-module'] or not options['value-function'] then return {value = formatError( 'unknown-value-module' )} end local formatter = require ('Module:' .. options['value-module']) if not formatter then return {value = formatError( 'value-module-not-found' )} end local fun = formatter[options['value-function']] if not fun then return {value = formatError( 'value-function-not-found' )} end return {value = fun( datavalue, datatype, options )} end --Default formatters if datatype == 'wikibase-item' then return formatwikibaseitem( datavalue, datatype, options ) elseif datatype == 'wikibase-property' then return formatwikibaseproperty( datavalue, datatype, options) elseif datatype == 'commonsMedia' then return formatcommonsMedia( datavalue, datatype, options) elseif datatype == 'math' then return formatmath( datavalue, datatype, options ) elseif datatype == 'time' then return formattime( datavalue, datatype, options ) elseif datatype == 'external-id' then return formatexternalid( datavalue, datatype, options ) elseif datatype == 'string' then return formatstring( datavalue, datatype, options ) elseif datatype == 'globe-coordinate' then return formatcoordinate( datavalue, datatype, options ) elseif datatype == 'quantity' then return formatquantity( datavalue, datatype, options ) elseif datatype == 'url' then return formaturl( datavalue, datatype, options ) elseif datatype == 'monolingualtext' then return formatmonolingualtext( datavalue, datatype, options ) elseif datatype == 'geo-shape' then return formatgeoshape( datavalue, datatype, options ) elseif datatype == 'tabulps-data' then return formattabulpsdata( datavalue, datatype, options ) else return {value = formatError( 'unknown-datatype' )} endendfunction formatEntityId( entityId, options )local label = options.label or mw.wikibase.label( entityId )if label == '' thenlabel = mw.wikibase.label( entityId ) or nilend local link = mw.wikibase.sitelink( entityId ) if link and (not options.nolink or options.nolink == '') then if label and label ~= '' then return {value = '[[:' .. link .. '|' .. formatcharacters(label, options) .. ']]'.. catewikidatainfo(options), label = label } else return {value = '[[:' .. link .. '|' .. formatcharacters(link, options) .. ']]'.. catewikidatainfo(options), label = link } end else if label and label ~= '' then local label3 = Labelfunction( entityId, label,options.label, options) return {value = label3 , label = label} else return '' end return '' --{value = entityId, cat = 'som har labels med Qid', label = entityId} endend --[[ function to get any link from any sister project ]] function sitelink_g( id , wikisite )if not mw.wikibase then return '' endlocal site = wikisite or 'pswiki'local link = mw.wikibase.sitelink( id , site ) or ""--mw.log("mw.wikibase.sitelink,site: " .. site.. ",link:" .. link )return linkendfunction sitelink( id , wikisite )local site = wikisite or 'pswiki' if not mw.wikibase then return '' endlocal entity = mw.wikibase.getEntityObject(id)if entityand entity.sitelinks and entity.sitelinks[''..site..'']and entity.sitelinks[''..site..''].site and entity.sitelinks[''..site..''].title thenif entity.sitelinks[''..site..''].site == site thenreturn entity.sitelinks[''..site..''].titleelse return ''endendend --[[ function to get only the value with link ]] function formatsitelink( entityId, options ) local link = sitelink( entityId ) if link and link ~= '' thenif not options.nolink or options.nolink == '' then --return '[[' .. formatcharacters(link, options) .. ']]'.. catewikidatainfo(options) return '[[' .. link .. ']]'.. catewikidatainfo(options) else return link -- formatcharacters(link, options)end else return '' endend --[[ function to replace $1 with string ]] function formatFromPattern( str, options )--if options.pattern and options.pattern ~='' then--mw.log( str .. ':' .. options.pattern )return mw.ustring.gsub( options.pattern, '$1', str ) --الحصول على اول نتيجة للدالة--else return str--endend function addTrackingCategory(prop,options)local cat = require('Module:Wikidata/تتبع').makecategory1local category = cat(options)if prop and prop ~= '' thenif category and category ~= '' thenreturn prop .. ' ' .. categoryelse return prop .. ' ' endendend-- Function to check whether a certain item is a parent of a given item.-- If pExitItem is reached without finding the searched parent item, the search stops.-- A parent is connected via P31 or P279.-- Attention: very intensive function, use carefully!function isParent(property, pItem, pParent, pExitItem, pMaxDepth, pDepth)if not pDepth then pDepth = 0 end if not mw.wikibase then return false endlocal entity = mw.wikibase.getEntity(pItem)if not entity then return false endlocal claims31local claims279if entity.claims then if property and property ~= '' thenclaims31 = entity.claims[mw.wikibase.resolvePropertyId(property)] elseclaims31 = entity.claims[mw.wikibase.resolvePropertyId('P31')] claims279 = entity.claims[mw.wikibase.resolvePropertyId('P279')] endelsereturn falseendfunction getSnakValue(snak)if snak.snaktype == "value" thenif snak.datavalue.type == "wikibase-entityid" then data = snak.datavalue.value['numeric-id']return dataendendendif not claims31 and not claims279 then return false endlocal parentIds = {}if claims31 and #claims31 > 0 thenfor i, v in ipairs(claims31) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) endendif claims279 and #claims279 > 0 thenfor i, v in ipairs(claims279) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) endend-- check if searched parent or exit item is reached or do recursive callif not parentIds[1] or #parentIds == 0 then return false endlocal itemString = ""local result = nilfor i, v in ipairs(parentIds) doif not v then return false enditemString = "Q" .. vif itemString == pParent then -- successful!return trueelseif itemString == pExitItem then --or itemString == "Q35120" -- exit if either "exit item" or node item (Q35120) is reachedreturn falseelseif pDepth+1 < pMaxDepth thenresult = isParent(property, itemString, pParent, pExitItem, pMaxDepth, pDepth+1)else return false endif result == true then return result endendenddo return false endendfunction isSubclass(options)if not options.parent then return false endlocal maxDepthmaxDepth = tonumber(options.maxDepth) or 10if not type(maxDepth) == "number" then maxDepth = 5 endproperty = options.propertylocal resultresult = isParent(property, options.id, options.parent , options.exitItem, maxDepth)if options.returnInt thenif result == true then return 1 else return nil endelsereturn resultendendlocal p = {} function p.formatEntityId( entityId, options )return formatEntityId( entityId, (options or {}) )end --[[ function to add tracking category ]] --[[ The main function ]] function p.formatStatements( frame, key ) local args = frame.args --If a value if already set, use it if args.value and args.value ~= '' then return args.value end local prop = formatStatements( frame.args, key )if prop and prop ~= '' then if args.mainprefix and args.mainprefix ~= '' then -- mainprefix prop = args.mainprefix .. prop end if args.mainsuffix and args.mainsuffix ~= '' then -- mainsuffix prop = prop .. args.mainsuffix endif args.addTrackingCat and args.addTrackingCat ~= '' then -- add tracking catprop = addTrackingCategory(prop,frame.args)endif args.mainsuffixAfterIcon and args.mainsuffixAfterIcon ~= '' then -- another suffix but after wikidata iconprop = prop .. args.mainsuffixAfterIcon endelse if args.NoPropValue and args.NoPropValue ~= '' then -- value if no local value and no wikidata value prop = args.NoPropValue endend return propendfunction p.formatStatementsFromLua( options, key ) -- main function but to use from lua module --If a value if already set, use it if options.value and options.value ~= '' then return options.value end local s = formatStatements( options, key ) if s == '' then s = nil endif options.addTrackingCat and options.addTrackingCat ~= '' then -- add tracking cats= addTrackingCategory(s,options)end return sendfunction p.isSubclass(frame)return isSubclass(frame.args)end-- Return the site link for a given data item and a given site (the current site by default) function p.getSiteLink( frame )local site = frame.args[2] or frame.args.sitelocal id = frame.args[1] or frame.args.idif not id or id == "" thenif frame.args.page and frame.args.page ~= "" thenid = mw.wikibase.getEntityIdForTitle( frame.args.page )endend local link = sitelink( id , site ) if link and link ~= '' then return linkendendfunction p.getSiteLink1(frame)local project = frame.args[1] local id = frame.args[2]local link =sitelink( id , project )var = linkreturn varend-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidatafunction p.pageId(frame)local entity = mw.wikibase.getEntityObject()if not entity then return nil else return entity.id endendfunction p.descriptionIn(frame)local langcode = frame.args[1]local id = frame.args[2] -- "id" must be nil, as access to other Wikidata objects is disabled in Mediawiki configurationreturn descriptionIn( langcode ,id )endfunction p.labelIn(frame)local langcode = frame.args[1]local id = frame.args[2] -- "id" must be nil, as access to other Wikidata objects is disabled in Mediawiki configurationreturn labelIn( langcode ,id )endfunction p.ViewSomething(frame) -- from en:Module:Wikidatalocal f = (frame.args[1] or frame.args.id) and frame or frame:getParent() if f.args.id and f.args.id ~='' then aa = f.args.id endlocal data = mw.wikibase.getEntityObject(aa)if not data thenreturn nilendlocal i = 1while true dolocal index = f.args[i]if not index thenif type(data) == "table" thenreturn mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY)elsereturn tostring(data)endenddata = data[index] or data[tonumber(index)]if not data thenreturnendi = i + 1endendfunction p.Dump(frame)local f = (frame.args[1] or frame.args.id) and frame or frame:getParent() if f.args.id and f.args.id ~='' then aa = f.args.id endlocal data = mw.wikibase.getEntityObject(aa)if not data thenreturn i18n.warnDumpendlocal i = 1while true dolocal index = f.args[i]if not index thenreturn frame:extensionTag("source", mw.dumpObject(data),{ lang= 'lua'}).. i18n.warnDumpenddata = data[index] or data[tonumber(index)]if not data thenreturn i18n.warnDumpendi = i + 1endendfunction p.EntityIdForTitle(frame)local title = frame.args[1]local str = mw.wikibase.getEntityIdForTitle( title )--mw.log(str)return strendreturn p
🔥 Top keywords: لومړی مخدويمه نړېواله جګړهځانگړی:پلټنهويکيپېډيا:د پوهنغونډ په اړهمایک پمپیود اختر لمونځلوی اخترويکيپېډيا:General disclaimerافغانستانويکيپېډياويکيپېډيا:تازه پېښېلارښود:منځپانګهکارن:Af420دوتنه:View to Afghanistan from Tajikistan (30075495368).jpgويکيپېډيا:په اړه۲پښتودوتنه:The Coca-Cola Company logo.svgد ښځې تناسلي آلهويکيپېډيا:له موږ سره اړيکهسردار محمد يوسف خانمېډياويکياوږدمهاله اورګاسمدقربانی احکام او مسائلپلوتونيمکویډ–19اپارتايدوېشنيزه:ویکیپیډیاځانگړی:اوسني بدلونونهويکيپېډيا:جرګهکوچنی اخترويکيپېډيا:د ټولنې تانبهوېشنيزه:1956 زېږېدنېتانبه:مېنځپانگه/تانبېالهام (حدس)ویکیپیډیا:د کارن-نوم بدلولمولانا بجلی ګهرمشاهدهعلي محمد مخلص