الفرق بين المراجعتين لصفحة: «وحدة:Wikidata2»
تم حذف المحتوى تمت إضافة المحتوى
Mr. Ibrahem (نقاش | مساهمات) لا ملخص تعديل |
Mr. Ibrahem (نقاش | مساهمات) لا ملخص تعديل |
||
سطر 1: | سطر 1: | ||
-- Den ordning fallback language hämtas, om svensk label saknas. Engelska först, därefter bokmål, danska, etc... |
|||
-- local fallback = {'en', 'nb', 'da', 'nn', 'de', 'fr', 'es', 'it', 'pt'} |
-- local fallback = {'en', 'nb', 'da', 'nn', 'de', 'fr', 'es', 'it', 'pt'} |
||
local formatera = require('وحدة:Math') |
local formatera = require('وحدة:Math') |
||
local i18n = { |
local i18n = { |
||
["errors"] = { |
|||
["property-param-not-provided"] = "Property parameter 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." |
|||
}, |
}, |
||
["noarabiclabel"] = "تصنيف:صفحات_ويكي_بيانات_بحاجة_لتسمية_عربية", |
|||
["somevalue"] = "", --''غير محدد'' |
|||
["warnDump"] = "[[Category:Called function 'Dump' from module Wikidata]]", |
|||
["novalue"] =''--قيمة مجهولة |
|||
["somevalue"] = "", --''غير محدد'' |
|||
["novalue"] ="",--قيمة مجهولة |
|||
["cateref"] ="[[تصنيف:صفحات بها مراجع ويكي بيانات]]" |
|||
} |
} |
||
local sortingproperties = {'P585','P571','P580','P569','P582','P570'} |
local sortingproperties = {'P585','P571','P580','P569','P582','P570'} |
||
local cateref = ' [[تصنيف:صفحات بها مراجع ويكي بيانات]]' |
|||
function catewikidatainfo(options) |
function catewikidatainfo(options) |
||
local prop = options.property |
local prop = options.property |
||
local catewikidatainfo = ' [[تصنيف:صفحات بها بيانات ويكي بيانات|'.. (prop or 'wikidata')..']]' |
local catewikidatainfo = ' [[تصنيف:صفحات بها بيانات ويكي بيانات|'.. (prop or 'wikidata')..']]' |
||
if (not options.nolink or options.nolink == '') |
|||
return catewikidatainfo |
|||
then return catewikidatainfo else return '' |
|||
end |
|||
end |
end |
||
--auktoritetsdata |
|||
function |
function formatcharacters(label, options) |
||
local |
local formatcharacters = options.formatcharacters |
||
if options. |
--if options.FormatfirstCharacter and options.num == 1 then |
||
--formatcharacters = options.FormatfirstCharacter |
|||
--end |
|||
if options.illwd2y and options.illwd2y ~= '' then |
|||
String2 = 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 String |
|||
return ca |
|||
end |
end |
||
if not |
if not formatcharacters or formatcharacters == '' then |
||
return label |
return label |
||
end |
end |
||
if |
if formatcharacters == 'lcfirst' then |
||
return mw.getCurrentFrame():preprocess("{{lcfirst: " .. label .. " }}") |
return mw.getCurrentFrame():preprocess("{{lcfirst: " .. label .. " }}") |
||
elseif |
elseif formatcharacters == 'ucfirst' then |
||
return mw.language.getContentLanguage():ucfirst( label ) |
return mw.language.getContentLanguage():ucfirst( label ) |
||
elseif |
elseif formatcharacters == 'lc' then |
||
return mw.getCurrentFrame():preprocess("{{lc: " .. label .. " }}") |
return mw.getCurrentFrame():preprocess("{{lc: " .. label .. " }}") |
||
elseif |
elseif formatcharacters == 'uc' then |
||
return mw.getCurrentFrame():preprocess("{{uc: " .. label .. " }}") |
return mw.getCurrentFrame():preprocess("{{uc: " .. label .. " }}") |
||
end |
end |
||
return label |
return label |
||
end |
end |
||
function getqualifierbysortingproperty(claim, sortingproperty) |
function getqualifierbysortingproperty(claim, sortingproperty) |
||
for k, v in pairs(sortingproperty) do |
for k, v in pairs(sortingproperty) do |
||
سطر 63: | سطر 79: | ||
end |
end |
||
return getqualifierbysortingproperty(claim, sortingproperty) |
return getqualifierbysortingproperty(claim, sortingproperty) |
||
end |
|||
function get_entityId(options) |
|||
local id = options.entityId |
|||
if not id or id == "" then |
|||
if options.page and options.page ~= "" then |
|||
id = mw.wikibase.getEntityIdForTitle( options.page ) |
|||
end |
|||
end |
|||
--mw.log("id :" .. id) |
|||
return id or "" |
|||
end |
end |
||
سطر 74: | سطر 101: | ||
item = 'P' .. item |
item = 'P' .. item |
||
end |
end |
||
return formatStatements({property = sortingproperty, entityId = item, enbarten = ' |
return formatStatements({property = sortingproperty, entityId = item, enbarten = 'true', sortbytime = 'chronological', noref = 'true'}) |
||
end |
end |
||
end |
end |
||
function descriptionIn(langcode , id) -- returns item description for a given language |
|||
function comparedates(a, b) |
|||
local lan = langcode or 'ar' |
|||
if not mw.wikibase then return nil end |
|||
local description, lange = mw.wikibase.getDescriptionWithLang( id ) |
|||
if lange == lan |
|||
then |
|||
return description |
|||
else |
|||
return nil |
|||
--return str |
|||
end |
|||
--[[local entity = mw.wikibase.getEntityObject(id) |
|||
if entity |
|||
and entity.descriptions |
|||
and entity.descriptions[''..lan..''] |
|||
and entity.descriptions[''..lan..''].value |
|||
then |
|||
local lang = entity.descriptions[''..lan..''] |
|||
if lang['language'] == lan then |
|||
return entity.descriptions[''..lan..''].value |
|||
else return nil end |
|||
end |
|||
]] |
|||
end |
|||
function labelIn(langcode,id) -- returns item label for a given language |
|||
if not mw.wikibase then return nil end |
|||
local lan = langcode or 'ar' |
|||
local label, lange = mw.wikibase.getLabelWithLang( id ) |
|||
if lange == lan |
|||
then |
|||
return label |
|||
else |
|||
return nil |
|||
--return str |
|||
end |
|||
--[[local entity = mw.wikibase.getEntityObject(id) |
|||
if entity |
|||
and entity.labels |
|||
and entity.labels[''..lan..''] |
|||
and entity.labels[''..lan..''].value |
|||
then |
|||
local lang = entity.labels[''..lan..''] |
|||
if lang['language'] == lan then |
|||
return entity.labels[''..lan..''].value |
|||
else return nil end |
|||
end |
|||
]] |
|||
end |
|||
function comparedates(a, b) -- returns true if a is earlier than B or if a has a date but not b |
|||
if a and b then |
if a and b then |
||
return a > b |
return a > b |
||
سطر 85: | سطر 162: | ||
end |
end |
||
end |
end |
||
function preferqualifier(claims, options) |
|||
local claims2 = {} |
|||
for i, statement in pairs( claims ) do -- |
|||
if statement.qualifiers and statement.qualifiers[options.preferqualifier:upper()] then |
|||
if options.preferqualifiervalue and options.preferqualifiervalue ~= '' then |
|||
local active = false |
|||
for k, t in pairs(mw.text.split(options.preferqualifiervalue,',')) do |
|||
for j, value in pairs(formatStatements({property=options.preferqualifier:upper(), raw = 'true', formatting = 'raw'}, statement.qualifiers)) do |
|||
if value.item == t and not active then |
|||
--if value == t and not active then |
|||
table.insert( claims2, statement) |
|||
active = true |
|||
end |
|||
end |
|||
end |
|||
else |
|||
table.insert( claims2, statement) |
|||
end |
|||
end |
|||
end |
|||
return claims2 |
|||
end |
|||
function sortbyqualifier(claims, options) |
function sortbyqualifier(claims, options) |
||
table.sort(claims, function(a,b) |
table.sort(claims, function(a,b) |
||
local timeA = getDate(a, options) |
local timeA = getDate(a, options) |
||
سطر 102: | سطر 199: | ||
function sortbyarb(claims, options) |
function sortbyarb(claims, options) |
||
table.sort(claims, function(a,b) |
table.sort(claims, function(a,b) |
||
local timeA = getDateArb(a, options) |
local timeA = getDateArb(a, options) |
||
سطر 116: | سطر 212: | ||
end |
end |
||
function Labelfunction( entityId, label ,labeloption , options) -- label with no arwiki sitelink |
|||
function getLabelFromFallBack( id ) |
|||
if options.illwd2nowd and options.illwd2nowd ~= '' then noWD='' else noWD='y' end |
|||
local entity = getEntityFromId( id ) |
|||
local jlabel = label --formatcharacters(label, options) -- The label |
|||
if not entity.labels then |
|||
local ar = labelIn('ar',entityId ) -- The arabic label |
|||
return {value = '[[d:' .. id .. '|' .. id .. ']][[تصنيف:صفحات_على_ويكي_بيانات_دون_تسمية_عربية]]', language = ''} |
|||
local arlabel = ar --formatcharacters(ar, options) |
|||
end |
|||
if labeloption and labeloption ~= '' then |
|||
for k, v in pairs(fallback) do |
|||
jlabel = labeloption |
|||
if entity.labels[v] then |
|||
elseif options.illwd2 and options.illwd2 ~= '' then |
|||
return {value = entity.labels[v].value, language = entity.labels[v].language} |
|||
if arlabel and arlabel ~= '' then |
|||
jlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {arlabel, id=entityId, y = (options.illwd2y or '') } } |
|||
else |
|||
jlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {id=entityId, target='en', y = (options.illwd2y or '') } } |
|||
end |
end |
||
elseif options.enlabelcate and options.enlabelcate ~= '' then |
|||
if not arlabel or arlabel == '' then |
|||
jlabel = label --formatcharacters(label, options) |
|||
if jlabel and jlabel ~= '' then |
|||
jlabel = jlabel ..' [['.. i18n.noarabiclabel ..'|'.. entityId ..']]' |
|||
end end |
|||
else--if options.justarabic and options.justarabic ~= '' then |
|||
if arlabel and arlabel ~= '' |
|||
then jlabel = arlabel |
|||
else jlabel = nil |
|||
end |
|||
end |
end |
||
if jlabel and jlabel ~= '' |
|||
-- Om inget fallback-språk finns av de i variabeln ovan, så används det först definierade i objektet |
|||
then |
|||
return jlabel.. catewikidatainfo(options) |
|||
for v, k in pairs(entity.labels) do |
|||
return {value = k.value, language = k.language} |
|||
end |
|||
end |
end |
||
return {value = '-', language = ''} |
|||
end |
end |
||
function getEntityFromId( id ) |
function getEntityFromId( id ) |
||
if not mw.wikibase then return nil end |
|||
if id then |
|||
if id and id ~= "" then |
|||
return mw.wikibase.getEntityObject( id ) |
return mw.wikibase.getEntityObject( id ) |
||
else |
else |
||
سطر 156: | سطر 266: | ||
return i18n.errors[key] |
return i18n.errors[key] |
||
end |
end |
||
function formatOneStatement( statement ,ref , options) |
|||
local vava = nil |
|||
local stat = formatStatement( statement, options ) |
|||
if stat then |
|||
local s = stat.value |
|||
local d = stat.datum |
|||
local tf = stat.tifr |
|||
local awardqual = stat.foto |
|||
local pr = stat.pr |
|||
--local utgivort = stat.utgivort |
|||
local ro = stat.ro |
|||
local qp1a = stat.qp1a |
|||
local onlyqualifier = stat.onlyqualifier |
|||
local qp1 = stat.qp1 |
|||
local qp2 = stat.qp2 |
|||
local qp3 = stat.qp3 |
|||
local qp4 = stat.qp4 |
|||
local qp5 = stat.qp5 |
|||
local amatch =stat.amatch |
|||
local reff =stat.reff |
|||
local goal =stat.goal |
|||
local start2 = stat.start1 |
|||
local finish2 = stat.finish1 |
|||
local before2 = stat.before1 |
|||
local after2 = stat.after1 |
|||
local constituency2 = stat.constituency1 |
|||
local series2 = stat.series1 |
|||
local electedin2 = stat.electedin1 |
|||
local P1001 = stat.pp1001 |
|||
local P108 = stat.pp108 |
|||
local P642 = stat.pp642 |
|||
if s == '' then s = nil end |
|||
if s then |
|||
if reff and options.reff and options.reff ~= '' then |
|||
s= s .. reff |
|||
end |
|||
if options.template and options.template ~= '' then |
|||
s = 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} } |
|||
end |
|||
if options.football and options.football ~= '' then |
|||
s =mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args = {(start2 or ''),(finish2 or '') ,s,amatch,goal } } |
|||
end |
|||
if options.office and options.office ~= '' then |
|||
s = 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 |
|||
} } |
|||
end |
|||
function qoo(Prefix,qualpref,p,Suffix) |
|||
if p and p ~='' then |
|||
return mw.text.tag('small', {}, (Prefix or ' (').. (qualpref or '') .. p .. (Suffix or ')')) end |
|||
end |
|||
QPrefix = options.qualifierprefix |
|||
QSuffix = options.qualifiersuffix |
|||
if qp1 and qp1 ~='' and options.qual1 and options.qual1 and qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= '' |
|||
then |
|||
s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix) |
|||
elseif qp1 and qp1 ~='' and options.qual1 and options.qual1 ~= '' then |
|||
s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) |
|||
elseif qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= '' then |
|||
s = s .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix) |
|||
end |
|||
if qp2 and qp2 ~='' and options.qual2 and options.qual2 ~= '' then s = s .. qoo(QPrefix, options.qual2pref, qp2, QSuffix) end |
|||
if qp3 and qp3 ~='' and options.qual3 and options.qual3 ~= '' then s = s .. qoo(QPrefix, options.qual3pref, qp3, QSuffix) end |
|||
if qp4 and qp4 ~='' and options.qual4 and options.qual4 ~= '' then s = s .. qoo(QPrefix, options.qual4pref, qp4, QSuffix) end |
|||
if qp5 and qp5 ~='' and options.qual5 and options.qual5 ~= '' then s = s .. qoo(QPrefix, options.qual5pref, qp5, QSuffix) end |
|||
if 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) end |
|||
if d and d ~='' and options.withdate and options.withdate ~= '' then |
|||
if 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) |
|||
end |
|||
end |
|||
if awardqual and options.awardqua and options.awardqua ~= '' then s = s .. qoo(QPrefix, '' , awardqual, QSuffix) end |
|||
if tf and options.bothdates and options.bothdates ~= '' then |
|||
if options.bothdates == 'line' |
|||
then s = s .. mw.text.tag('br') .. qoo(QPrefix, '' , tf, QSuffix) |
|||
elseif options.bothdates == 'before' |
|||
then s = qoo(QPrefix, '' , tf, QSuffix) .. s |
|||
else |
|||
s = s .. qoo(QPrefix, '' , tf, QSuffix) |
|||
end |
|||
end |
|||
--if utgivort and options.withutgivort and options.withutgivort ~= '' then |
|||
--if options.withutgivort == 'قوسين' then s = s .. ' ' .. qoo(QPrefix, '' , utgivort, QSuffix) |
|||
--else s = s .. ' ' .. utgivort |
|||
--end |
|||
--end |
|||
if pr and pr ~= '' and options.getsimpleproperty and options.getsimpleproperty ~= '' then |
|||
if 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 .. '') |
|||
end |
|||
end |
|||
if type(ref) == 'table' or (options.noref and options.noref ~='') or (options.justthisqual and options.justthisqual ~='') |
|||
then |
|||
--table.insert( formattedStatements, s ) |
|||
vava = s |
|||
else |
|||
local t = formatReferences( statement, options ) |
|||
stat.ref = t |
|||
if options.justref and options.justref ~= '' |
|||
then |
|||
vava = t |
|||
elseif options.onlyvaluewithref and options.onlyvaluewithref ~= '' then |
|||
if t and t ~= "" then |
|||
vava = s .. t |
|||
end |
|||
else |
|||
vava = s .. t |
|||
end |
|||
end |
|||
end |
|||
--table.insert(statementsraw, stat) |
|||
end |
|||
return { v = vava , raw = stat} |
|||
end |
|||
function formatStatements( options, ref ) |
function formatStatements( options, ref ) |
||
local formattedStatements = {} |
local formattedStatements = {} |
||
local claims = {} |
local claims = {} |
||
if not options.property then |
if not options.property then return formatError( 'property-param-not-provided' ) end |
||
return formatError( 'property-param-not-provided' ) |
|||
end |
|||
if type(ref) == 'table' then -- |
if type(ref) == 'table' then -- f?r de fall d?r funktionen anropas och alla claims redan finns i en tabell |
||
claims = ref[options.property] or {} |
claims = ref[options.property] or {} |
||
else |
else |
||
--Get entity |
--Get entity |
||
local entity = nil |
local entity = nil |
||
if options.entity and type( options.entity ) == "table" then |
if options.entity and type( options.entity ) == "table" then |
||
entity = options.entity |
entity = options.entity |
||
else |
else |
||
entity = getEntityFromId( options.entityId ) |
--entity = getEntityFromId( options.entityId ) |
||
id = get_entityId( options ) |
|||
end |
|||
entity = getEntityFromId( id ) |
|||
if not entity then |
|||
return '' --TODO error? |
|||
end |
end |
||
if not entity then return '' end --TODO error? |
|||
if not entity.claims or not entity.claims[options.property:upper()] then |
if not entity.claims or not entity.claims[options.property:upper()] then |
||
return '' --TODO error? |
return '' --TODO error? |
||
سطر 188: | سطر 443: | ||
if options.rank == 'best' or not options.rank then |
if options.rank == 'best' or not options.rank then |
||
claims = entity:getBestStatements( options.property:upper() ) |
claims = entity:getBestStatements( options.property:upper() ) |
||
elseif options.rank == 'valid' then |
elseif options.rank == 'valid' then |
||
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
||
if statement.rank == 'preferred' or statement.rank == 'normal' then |
if statement.rank == 'preferred' or statement.rank == 'normal' then |
||
table.insert( claims, statement ) |
table.insert( claims, statement ) |
||
end |
end |
||
end |
end |
||
elseif options.rank == 'all' then |
elseif options.rank == 'all' then |
||
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
||
table.insert( claims, statement ) |
table.insert( claims, statement ) |
||
end |
end |
||
else |
else |
||
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
for i, statement in pairs( entity.claims[options.property:upper()] ) do |
||
سطر 205: | سطر 460: | ||
end |
end |
||
end |
end |
||
if options.avoidqualifier then |
if options.avoidqualifier then -- to avoid value with a given qualifier |
||
local claims2 = {} |
local claims2 = {} |
||
for i, statement in pairs( claims ) do |
for i, statement in pairs( claims ) do |
||
سطر 213: | سطر 468: | ||
end |
end |
||
claims = claims2 |
claims = claims2 |
||
if options.preferqualifier and options.preferqualifier ~= '' then |
|||
claims = preferqualifier(claims, options) |
|||
end |
end |
||
end |
|||
--om det finns vissa statements som har en qualifier som säger "språk = svenska", ta bara med dessa |
|||
-- |
--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 == '' then |
if not options.langpref or options.langpref == '' then |
||
local claims2 = {} |
local claims2 = {} |
||
سطر 248: | سطر 506: | ||
local statementsraw = {} |
local statementsraw = {} |
||
if claims then |
if claims then |
||
--========================================== |
|||
for i, statement in pairs( claims ) do |
|||
if options['property-module'] or options['property-function'] then |
|||
options.num = i |
|||
if not options['property-module'] or not options['property-function'] then |
|||
local stat = formatStatement( statement, options ) |
|||
return formatError( 'unknown-property-module' ) |
|||
if stat then |
|||
local s = stat.value |
|||
local d = stat.datum |
|||
local tf = stat.tifr |
|||
local awardqual = stat.foto |
|||
local pr = stat.pr |
|||
local utgivort = stat.utgivort |
|||
local ro = stat.ro |
|||
local qp1a = stat.qp1a |
|||
local onlyqualifier = stat.onlyqualifier |
|||
local qp1 = stat.qp1 |
|||
local qp2 = stat.qp2 |
|||
local qp3 = stat.qp3 |
|||
local qp4 = stat.qp4 |
|||
local qp5 = stat.qp5 |
|||
local amatch =stat.amatch |
|||
local goal =stat.goal |
|||
local start2 = stat.start1 |
|||
local finish2 = stat.finish1 |
|||
local before2 = stat.before1 |
|||
local after2 = stat.after1 |
|||
local constituency2 = stat.constituency1 |
|||
local series2 = stat.series1 |
|||
local electedin2 = stat.electedin1 |
|||
local P1001 = stat.pp1001 |
|||
if s == '' then s = nil end |
|||
if s then |
|||
if options.football and options.football ~= '' then |
|||
s =mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args = {(start2 or ''),(finish2 or '') ,s,amatch,goal } } |
|||
end |
end |
||
local formatter = require ('Module:' .. options['property-module']) |
|||
if |
if not formatter then |
||
return formatError( 'property-module-not-found' ) |
|||
s = mw.getCurrentFrame():expandTemplate{ title = "معلومات صاحب منصب/منصب ويكي بيانات/نواة", args = {office = s, termstart = start2, termend = finish2, constituency = constituency2, predecessor = before2, successor = after2, series= series2,electedin=electedin2,jurisdiction=P1001,entityId=options.entityId} } |
|||
end |
end |
||
local fun = formatter[options['property-function']] |
|||
if qp1 and options.qual1 and options.qual1 and qp1a and options.qual1a and options.qual1a ~= '' then |
|||
if not fun then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual1pref or '').. qp1 ..(options.qualifiersuffix or ')')) .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. (options.qp1apref or '') .. qp1a .. (options.qualifiersuffix or ')')) |
|||
return formatError( 'property-function-not-found' ) |
|||
else |
|||
end |
|||
if qp1 and options.qual1 and options.qual1 ~= '' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual1pref or '') .. qp1 .. (options.qualifiersuffix or ')')) |
|||
mw.log("work with property-module: " .. options['property-module'] .. "|" .. options['property-function']) |
|||
else |
|||
return fun( claims, options ) |
|||
else |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qp1apref or '') .. qp1a .. (options.qualifiersuffix or ')')) |
|||
--========================================== |
|||
end end end |
|||
for i, statement in pairs( claims ) do |
|||
if qp2 and options.qual2 and options.qual2 ~= '' then |
|||
options.num = i |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual2pref or '') .. qp2 .. (options.qualifiersuffix or ')')) |
|||
local va = formatOneStatement( statement,ref, options ) |
|||
end |
|||
if va.v then |
|||
table.insert( formattedStatements, va.v ) |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual3pref or '') .. qp3 .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if qp4 and options.qual4 and options.qual4 ~= '' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual4pref or '') .. qp4 .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if qp5 and options.qual5 and options.qual5 ~= '' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (').. (options.qual5pref or '') .. qp5 .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if options.justthisqual then |
|||
if onlyqualifier then |
|||
s = onlyqualifier |
|||
else |
|||
if not options.justthisqual ~= '' then s = nil end-- We need only the qualifier |
|||
end |
|||
end |
|||
if ro and options.withro and options.withro ~= '' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. ro .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if d and options.withdate and options.withdate ~= '' then |
|||
if options.withdate == 'y' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') 'سنة ' .. d .. (options.qualifiersuffix or ')')) |
|||
else |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. d .. (options.qualifiersuffix or ')')) |
|||
end |
|||
end |
|||
if awardqual and options.awardqua and options.awardqua ~= '' then |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. awardqual .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if tf and options.withintervall and options.withintervall ~= '' then |
|||
if options.withintervall == 'gift' then |
|||
s = s .. mw.text.tag('br') .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. tf .. (options.qualifiersuffix or ')')) |
|||
else |
|||
if options.withintervall == 'before' then |
|||
s = mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. tf .. (options.qualifiersuffix or ')')) .. s |
|||
else |
|||
s = s .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. tf .. (options.qualifiersuffix or ')')) |
|||
end end |
|||
end |
|||
if utgivort and options.withutgivort and options.withutgivort ~= '' then |
|||
if options.withutgivort == 'قوسين' then |
|||
s = s .. ' ' .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') .. utgivort .. (options.qualifiersuffix or ')')) |
|||
else |
|||
s = s .. ' ' .. utgivort |
|||
end |
|||
end |
|||
if options.getsimpleproperty == 'född' and pr and pr ~= '' then |
|||
s = s .. ' ' .. mw.text.tag('small', {}, (options.qualifierprefix or ' (') 'f. ' .. pr .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if options.getsimpleproperty == 'parentes' and pr and pr ~= '' then |
|||
s = s .. ' ' .. mw.text.tag('span', {}, (options.qualifierprefix or ' (') .. pr .. (options.qualifiersuffix or ')')) |
|||
end |
|||
if options.getsimpleproperty == 'avnågon' and pr and pr ~= '' then |
|||
s = s .. ' ' .. mw.text.tag('span', {}, ' av ' .. pr .. '') |
|||
end |
|||
if type(ref) == 'table' or (options.noref and options.noref ~='') then --Inte leta efter referenser om själva anropet görs från en referens |
|||
table.insert( formattedStatements, s ) |
|||
else |
|||
local t = formatReferences( statement, options ) |
|||
stat.ref = t |
|||
if options.justref and options.justref ~= '' then |
|||
table.insert( formattedStatements, t ) |
|||
else table.insert( formattedStatements, s .. t ) |
|||
end |
|||
end |
|||
end |
end |
||
table.insert(statementsraw, |
table.insert( statementsraw, va.raw ) |
||
end |
end |
||
end |
end |
||
end |
end |
||
local tot = mw.text.listToText( formattedStatements, options.separator, options.conjunction ) |
|||
local Separator = options.separator-- or "" |
|||
local Conjunction = options.conjunction-- or "" |
|||
if Conjunction and Conjunction == "br" then Conjunction = "\n" end |
|||
if Separator and Separator == "br" |
|||
then |
|||
Separator = "\n" |
|||
Conjunction = "\n" |
|||
end |
|||
local tot = mw.text.listToText( formattedStatements, Separator, Conjunction ) |
|||
if tot == '' then tot = nil end |
if tot == '' then tot = nil end |
||
if options.raw and options.raw ~= '' then |
if options.raw and options.raw ~= '' then |
||
سطر 379: | سطر 551: | ||
return tot |
return tot |
||
end |
end |
||
function formatReferences( statement, options ) |
function formatReferences( statement, options ) |
||
local reference = {} |
local reference = {} |
||
سطر 384: | سطر 557: | ||
local cite = require('وحدة:Cite') |
local cite = require('وحدة:Cite') |
||
for i, ref in pairs(statement.references) do |
for i, ref in pairs(statement.references) do |
||
local items |
local items = {} |
||
if ref.snaks then |
if ref.snaks then |
||
s = cite.citeitem2(ref , options ) |
|||
--s = cite.citeitem( items , ref.snaks , ref.hash , options ) |
|||
end |
|||
table.insert(reference, s) |
|||
end |
|||
end |
|||
local final = table.concat(reference) |
|||
if final and final ~= '' then |
|||
final = final .. i18n.cateref |
|||
end |
|||
return final |
|||
end |
|||
function formatqualifiers( statement,s, options ) |
|||
if ref.snaks.P248 then |
|||
function qua(p,enbarten,modifytime) |
|||
for j, prop in pairs(ref.snaks.P248) do |
|||
if p and p ~='' then return (formatStatements({property =p,enlabelcate = 't', enbarten = (enbarten or '') |
|||
table.insert(items, 'Q' .. prop.datavalue.value['numeric-id']) |
|||
,modifytime = (modifytime or 'longdate'), noref = 'true'}, statement.qualifiers) or '') end |
|||
end |
|||
end |
|||
if options.template and options.template ~= '' then |
|||
s.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) |
|||
end |
|||
if statement.qualifiers.P1350 or statement.qualifiers.P1351 then |
|||
s.amatch = qua("P1350",'true') |
|||
s.goal = qua("P1351",'true') |
|||
end |
|||
if statement.qualifiers.P580 or statement.qualifiers.P582 or statement.qualifiers.P1365 or statement.qualifiers.P1366 then |
|||
s.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") |
|||
end |
|||
if statement.qualifiers.P585 then |
|||
s.datum = qua("P585",'true',options.modifyqualifiertime) |
|||
end |
|||
local qwe = options.qwer |
|||
if statement.qualifiers.qwe then |
|||
s.ro = qua(qwe,'true') |
|||
end |
|||
if statement.qualifiers.P574 then |
|||
s.dateoftaxpub = qua("P574",'true',options.modifyqualifiertime) |
|||
end |
|||
if statement.qualifiers.P405 then |
|||
local author = {} |
|||
for i, j in pairs(statement.qualifiers.P405) do |
|||
if j.snaktype == 'value' then |
|||
local item = 'Q' .. j.datavalue.value['numeric-id'] |
|||
local authorname = formatStatements({property = "P428", entityId = item, noref = 'true', enbarten = 'true'}) |
|||
if author and authorname ~= '' then |
|||
table.insert(author, formatEntityId(item, {label = authorname }).value) |
|||
else |
|||
table.insert(author, formatEntityId(item, {}).value) |
|||
end |
end |
||
if ref.snaks.P143 then |
|||
for j, prop in pairs(ref.snaks.P143) do |
|||
table.insert(items, 'Q' .. prop.datavalue.value['numeric-id']) |
|||
end |
|||
end |
|||
s = cite.citeitem( items, ref.snaks, options ) |
|||
end |
end |
||
table.insert(reference, mw.getCurrentFrame():expandTemplate{ title = "وسم", args = {'ref', s,ref.hash,cateref}}) |
|||
end |
end |
||
s.auktor = mw.text.listToText(author, ', ', ' & ') |
|||
end |
|||
if statement.qualifiers.P580 or statement.qualifiers.P582 then |
|||
local f = qua("P580",'true',options.modifyqualifiertime) |
|||
local t = qua("P582",'true',options.modifyqualifiertime) |
|||
s.tifr = f .. '–' .. t |
|||
end |
end |
||
if statement.qualifiers.P585 or statement.qualifiers.P1346 then |
|||
return table.concat(reference) |
|||
local fo = qua("P585",'true',options.modifyqualifiertime) |
|||
local to = qua('P1346','true') |
|||
s.foto = fo .. ' ' .. mw.text.tag('span', {}, ' ' .. to .. '') |
|||
end |
|||
function quaaal(opti,options) |
|||
if opti and opti ~='' and statement.qualifiers[opti] then |
|||
return (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 '') |
|||
end |
|||
end |
|||
--if statement.qualifiers.P291 then -- خاصية بلد النشر |
|||
--s.utgivort = quaaal('P291',options) |
|||
--end |
|||
if statement.qualifiers.P2096 then |
|||
s.bildtext = formatStatements({property = "P2096", noref = 'true', langpref = (options.langpref or 'ar')}, statement.qualifiers) |
|||
end |
|||
if options.justthisqual and options.justthisqual ~= '' and statement.qualifiers[options.justthisqual] then |
|||
s.onlyqualifier = quaaal(options.justthisqual,options) |
|||
end |
|||
if options.qual1 and options.qual1 ~= '' and statement.qualifiers[options.qual1] then s.qp1 = quaaal(options.qual1,options) end |
|||
if options.qual1a and options.qual1a ~= '' and statement.qualifiers[options.qual1a] then s.qp1a = quaaal(options.qual1a,options) end |
|||
if options.qual2 and options.qual2 ~= '' and statement.qualifiers[options.qual2] then s.qp2 = quaaal(options.qual2,options) end |
|||
if options.qual3 and options.qual3 ~= '' and statement.qualifiers[options.qual3] then s.qp3 = quaaal(options.qual3,options) end |
|||
if options.qual4 and options.qual4 ~= '' and statement.qualifiers[options.qual4] then s.qp4 = quaaal(options.qual4,options) end |
|||
if options.qual5 and options.qual5 ~= '' and statement.qualifiers[options.qual5] then s.qp5 = quaaal(options.qual5,options) end |
|||
end |
end |
||
function formatStatement( statement, options ) |
function formatStatement( statement, options ) |
||
if |
if options['claim-module'] or options['claim-function'] then |
||
if not options['claim-module'] or not options['claim-function'] then |
|||
local s = formatSnak( statement.mainsnak, options ) |
|||
return {value = formatError( 'unknown-claim-module' )} |
|||
if statement.qualifiers then |
|||
end |
|||
if statement.qualifiers.P1350 or statement.qualifiers.P1351 then |
|||
local formatter = require ('Module:' .. options['claim-module']) |
|||
s.amatch = formatStatements({property = "P1350", enbarten = 'true'}, statement.qualifiers) or '' |
|||
if not formatter then |
|||
s.goal = formatStatements({property = "P1351", enbarten = 'true'}, statement.qualifiers) or '' |
|||
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 ~= '' then |
|||
if statement.references then |
|||
if options.reff and options.reff ~= '' then |
|||
s.reff = formatReferences( statement, options ) |
|||
end |
|||
end |
end |
||
if statement.qualifiers then |
|||
qualu = formatqualifiers( statement,s, options ) |
|||
if qualu and qualu ~= '' then table.insert(qualu) end |
|||
if statement.qualifiers.P580 or statement.qualifiers.P582 or statement.qualifiers.P1365 or statement.qualifiers.P1366 then |
|||
s.start1 = formatStatements({property = "P580", enbarten = 'true'}, statement.qualifiers) or ' ' |
|||
s.finish1 = formatStatements({property = "P582", enbarten = 'true'}, statement.qualifiers) or ' ' |
|||
s.before1 = formatStatements({property = "P1365", enbarten = 'true'}, statement.qualifiers) or ' ' |
|||
s.after1 = formatStatements({property = "P1366", enbarten = 'true'}, statement.qualifiers) or ' ' |
|||
s.constituency1 = formatStatements({property = "P768"}, statement.qualifiers) or ' ' |
|||
s.series1 = formatStatements({property = "P1545", enbarten = 'true'}, statement.qualifiers) or ' ' |
|||
s.electedin1 = formatStatements({property = "P2715"}, statement.qualifiers) or ' ' |
|||
s.pp1001 = formatStatements({property = "P1001"}, statement.qualifiers) or ' ' |
|||
end |
end |
||
end |
|||
if statement.qualifiers.P585 then |
|||
s.datum = formatStatements({property = "P585", enbarten = 'true', noref = 'true', modifytime = options.modifyqualifiertime}, statement.qualifiers) |
|||
end |
|||
local qwe = options.qwer |
|||
if statement.qualifiers.qwe then |
|||
s.ro = formatStatements({property = qwe, enbarten = 'true', noref = 'true'}, statement.qualifiers) |
|||
end |
|||
if statement.qualifiers.P574 then |
|||
s.dateoftaxpub = formatStatements({property = "P574", enbarten = 'true', noref = 'true', modifytime = options.modifyqualifiertime}, statement.qualifiers) |
|||
end |
|||
if statement.qualifiers.P405 then |
|||
local auktorer = {} |
|||
for i, j in pairs(statement.qualifiers.P405) do |
|||
if j.snaktype == 'value' then |
|||
local item = 'Q' .. j.datavalue.value['numeric-id'] |
|||
local auktorsnamn = formatStatements({property = "P428", entityId = item, noref = 'ja', enbarten = 'ja'}) |
|||
if auktorsnamn and auktorsnamn ~= '' then |
|||
table.insert(auktorer, formatEntityId(item, {label = auktorsnamn}).value) |
|||
else |
|||
table.insert(auktorer, formatEntityId(item, {}).value) |
|||
end |
|||
end |
|||
end |
|||
s.auktor = mw.text.listToText(auktorer, ', ', ' & ') |
|||
end |
|||
if statement.qualifiers.P580 or statement.qualifiers.P582 then |
|||
local f = formatStatements({property = "P580", enbarten = 'true', noref = 'true', modifytime = options.modifyqualifiertime}, statement.qualifiers) or '' |
|||
local t = formatStatements({property = "P582", enbarten = 'true', noref = 'true', modifytime = options.modifyqualifiertime}, statement.qualifiers) or '' |
|||
s.tifr = f .. '–' .. t |
|||
end |
|||
if statement.qualifiers.P585 or statement.qualifiers.P1346 then |
|||
local fo = formatStatements({property = "P585", enbarten = 'true', noref = 'true', modifytime = options.modifyqualifiertime}, statement.qualifiers) or '' |
|||
local to = formatStatements({property = "P1346", enbarten = 'true', noref = 'true'}, statement.qualifiers) or '' |
|||
s.foto = fo .. ' ' .. mw.text.tag('span', {}, ' ' .. to .. '') |
|||
end |
|||
if statement.qualifiers.P291 then -- خاصية بلد النشر |
|||
s.utgivort = formatStatements({property = "P291", noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
if statement.qualifiers.P2096 then |
|||
s.bildtext = formatStatements({property = "P2096", noref = 'true', langpref = (options.langpref or 'ar')}, statement.qualifiers) |
|||
end |
|||
if s then |
|||
if options.qual1 and options.qual1 ~= '' and statement.qualifiers[options.qual1] then -- عرض تصفيات لبنود الخاصية |
|||
s.qp1 = formatStatements({property = options.qual1, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction,size =options.size,image =options.image}, statement.qualifiers) |
|||
end |
|||
if options.qual1a and options.qual1a ~= '' and statement.qualifiers[options.qual1a] then |
|||
s.qp1a = formatStatements({property = options.qual1a, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
if options.justthisqual and options.justthisqual ~= '' and statement.qualifiers[options.justthisqual] then |
|||
s.onlyqualifier = formatStatements({property = options.justthisqual , noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
if options.qual2 and options.qual2 ~= '' and statement.qualifiers[options.qual2] then |
|||
s.qp2 = formatStatements({property = options.qual2, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction,size =options.size,image =options.image}, statement.qualifiers) |
|||
end |
|||
if options.qual3 and options.qual3 ~= '' and statement.qualifiers[options.qual3] then |
|||
s.qp3 = formatStatements({property = options.qual3, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
if options.qual4 and options.qual4 ~= '' and statement.qualifiers[options.qual4] then |
|||
s.qp4 = formatStatements({property = options.qual4, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
if options.qual5 and options.qual5 ~= '' and statement.qualifiers[options.qual5] then |
|||
s.qp5 = formatStatements({property = options.qual5, noref = 'true', separator = options.qualifierseparator, conjunction = options.qualifierconjunction}, statement.qualifiers) |
|||
end |
|||
end |
|||
end |
|||
return s |
return s |
||
elseif not statement.type then |
elseif not statement.type then |
||
سطر 521: | سطر 721: | ||
return {value = i18n['novalue']} |
return {value = i18n['novalue']} |
||
elseif snak.snaktype == 'value' then |
elseif snak.snaktype == 'value' then |
||
local s = formatDatavalue( snak.datavalue |
local s = formatDatavalue( snak.datavalue, snak.datatype, options ) |
||
if s and options.prefix and options.prefix ~= '' then |
if s and s.value and options.prefix and options.prefix ~= '' then |
||
s.value = options.prefix .. s.value |
s.value = options.prefix .. s.value |
||
end |
end |
||
if s and options.suffix and options.suffix ~= '' then |
if s and s.value and options.suffix and options.suffix ~= '' then |
||
s.value = s.value .. options.suffix |
s.value = s.value .. options.suffix |
||
end |
end |
||
if s and s.item and options.getsimpleproperty and options.getsimpleproperty ~= '' and options.getproperty and options.getproperty ~= '' then |
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 = ' |
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 |
if pr then s.pr = pr end |
||
end |
end |
||
سطر 537: | سطر 737: | ||
end |
end |
||
end |
end |
||
function formatDatavalue( datavalue, options, datatype ) |
|||
--[[ |
|||
--Use the customize handler if provided |
|||
datatype wikibase-item |
|||
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' )} |
|||
function formatwikibaseitem( datavalue, datatype, options ) |
|||
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.value, options )} |
|||
end |
|||
--Default formatters |
|||
if datatype == 'wikibase-item' then |
|||
if options.formatting and options.formatting ~= '' |
if options.formatting and options.formatting ~= '' |
||
then |
then |
||
if options.formatting == 'raw' then |
if options.formatting == 'raw' then |
||
return {value = getEntityIdFromValue( datavalue.value )} |
return {value = getEntityIdFromValue( datavalue.value )} |
||
elseif options.formatting == 'fu' then |
|||
else |
|||
return {value = mw.getCurrentFrame():expandTemplate{ title = "Cycling race/stageclassification1" |
|||
, args = {getEntityIdFromValue( datavalue.value )}} } |
|||
elseif options.formatting == 'sitelink' then -- for Wikidata property giving Wikimedia list |
|||
return {value = formatsitelink(datavalue.value.id , options ) } |
|||
else |
|||
return {value = formatFromPattern( formatcharacters(datavalue.value, options), options )} |
|||
end |
end |
||
elseif options.property1 and options.property1 ~= '' then |
elseif options.property1 and options.property1 ~= '' then |
||
for i, statement in pairs( datavalue ) do |
for 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 entit = getEntityIdFromValue( datavalue.value ) |
|||
local caca = formatStatements( {property =options.property1, entityId = entit, noref =options.noref ,rank=options.rank,pattern =options.pattern,size =options.size,image =options.image,noref='true',enbarten ='true' }) |
|||
local cooooca = (options.property1pref or '') ..''.. caca ..''.. (options.property1suff or '') |
|||
local asdf = formatEntityId( entit , options ).value |
local asdf = formatEntityId( entit , options ).value |
||
if asdf and asdf ~= '' then |
if asdf and asdf ~= '' then |
||
if caca and caca ~= '' then |
|||
local cooooca = (options.property1pref or '') ..''.. caca ..''.. (options.property1suff or '') |
|||
end |
|||
if options.property1after and options.property1after ~= "" then |
|||
return {value = asdf .. cooooca } |
|||
else |
|||
return {value = cooooca .. ' '.. asdf } |
|||
end |
|||
else |
|||
return {value = asdf } |
|||
end |
|||
end |
|||
end |
end |
||
elseif options.propertyimage and options.propertyimage ~= '' then |
elseif options.propertyimage and options.propertyimage ~= '' then |
||
سطر 577: | سطر 777: | ||
local entit = getEntityIdFromValue( datavalue.value ) |
local entit = getEntityIdFromValue( datavalue.value ) |
||
local caca = formatStatements( {property =options.propertyimage , entityId = entit, noref =options.noref ,rank=options.rank,pattern =options.pattern,size =options.size,image =options.image,noref='true',enbarten ='true' }) |
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 |
local asdf = formatEntityId( entit , options ).value |
||
سطر 588: | سطر 788: | ||
local entit = getEntityIdFromValue( datavalue.value ) |
local entit = getEntityIdFromValue( datavalue.value ) |
||
local caca = formatStatements( {property =options.property2, entityId = entit, noref =options.noref ,rank=options.rank,pattern =options. |
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 |
local asdf = formatEntityId( entit , options ).value |
||
if asdf and asdf ~= '' then |
if asdf and asdf ~= '' then |
||
سطر 594: | سطر 794: | ||
end |
end |
||
end else |
end else |
||
return {value = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).value} |
return {value = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).value, item = getEntityIdFromValue( datavalue.value )} |
||
end |
end |
||
end |
|||
--[[ |
|||
elseif datatype == 'wikibase-property' then |
|||
datatype wikibase-property |
|||
if options.formatting and options.formatting ~= '' |
|||
]] |
|||
function formatwikibaseproperty( datavalue, datatype, options ) |
|||
if options.formatting and options.formatting ~= '' |
|||
then |
then |
||
if options.formatting == 'raw' then |
if options.formatting == 'raw' then |
||
tid = getEntityIdFromValue( datavalue.value ) |
|||
else |
else |
||
end |
end |
||
else |
else |
||
tid = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).value |
|||
end |
|||
return {value = tid} |
|||
end |
|||
--[[ |
|||
tabular-data |
|||
]] |
|||
function formattabulardata( 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 |
|||
--[[ |
|||
elseif datatype == 'commonsMedia' then --and datavalue.type == 'string' |
|||
commonsMedia |
|||
if options.image and options.image ~= '' then |
|||
]] |
|||
return {value = '[[file:' .. datavalue.value .. '|'.. (options.size or '120')..'px|'..'border'..']]' } |
|||
function formatcommonsMedia( datavalue, datatype, options ) |
|||
if options.image and options.image ~= '' then -- return real image |
|||
tid = '[[file:' .. datavalue.value .. '|'.. (options.size or '60')..'px|'..'border'..']]' |
|||
else |
else |
||
tid = formatcharacters(datavalue.value, options) |
|||
end |
end |
||
return {value = tid} |
|||
elseif datatype == 'math' then |
|||
end |
|||
--return {value = mw.text.tag('math', {}, ''.. datavalue.value..'') } |
|||
--[[ |
|||
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..'' ) } |
return {value =mw.getCurrentFrame():callParserFunction( '#tag:math', ''.. datavalue.value..'' ) } |
||
end |
|||
--[[ |
|||
elseif datatype == 'string' or datatype == 'external-id' then |
|||
datatype string - external-id |
|||
if options.pattern and options.pattern ~= '' then |
|||
]] |
|||
if options.pattern == "auktoritetsdata" then |
|||
function formatstring( datavalue, datatype, options ) |
|||
local patter = formatStatements( {property = "P1630", entityId = options.property, enbarten = 'true', noref = 'true' }) |
|||
--old value: auktoritetsdata , auktoritetsdata2 , auktoritetsdata3 |
|||
return {value = formatFromPattern( datavalue.value, {pattern = patter} )} |
|||
if options.pattern and options.pattern ~= '' then |
|||
par = options.pattern |
|||
local patter = formatStatements( {property = "P1630", entityId = options.property, enbarten = 'true', noref = 'true' }) |
|||
if par == "autourl" or par == "autourl2" or par == "autourl3" or par == "autourl4" |
|||
return {value = '[' .. formatFromPattern( datavalue.value, {pattern = patter} ) .. ' ' .. datavalue.value .. ']' } |
|||
then tid = formatcharacters(datavalue.value, options) |
|||
elseif options.pattern == "auktoritetsdata3" then |
|||
else tid = formatFromPattern( formatcharacters(datavalue.value, options), options ) |
|||
local patter = formatStatements( {property = "P1630", entityId = options.property, enbarten = 'true', noref = 'true' }) |
|||
end |
|||
return {value = '[' .. formatFromPattern( datavalue.value, {pattern = patter} ) .. ' ' .. formatFromPattern( datavalue.value, {pattern = patter} ) .. ']' } |
|||
else |
|||
tid = formatcharacters(datavalue.value, options) |
|||
end |
|||
end |
|||
return {value = tid} |
|||
else |
|||
end |
|||
return {value = versalisering(datavalue.value, options), label = datavalue.value} |
|||
end |
|||
elseif datatype == 'time' then |
|||
local Time = require 'Module:Time2' |
|||
local tid = Time.newFromWikidataValue( datavalue.value ):toHtml() |
|||
if options.modifytime == 'Y' then |
|||
local mall = '{{ {{{|safesubst:}}}#time:Y|' .. string.gsub(datavalue.value.time,'-00','-01') .. '}}' |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'F' then |
|||
local mall = '{{ {{{|safesubst:}}}#time:F|' .. string.gsub(datavalue.value.time,'-00','-01') .. '}}' |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'j' then |
|||
local mall = '{{ {{{|safesubst:}}}#time:j|' .. string.gsub(datavalue.value.time,'-00','-01') .. '}}' |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'j F Y' then |
|||
local mall = '{{ {{{|safesubst:}}}#time:j F Y|' .. string.gsub(datavalue.value.time,'-00','-01') .. '}}' |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'j F' then |
|||
local mall = '{{ {{{|safesubst:}}}#time:j F|' .. string.gsub(datavalue.value.time,'-00','-01') .. '}}' |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'q' then |
|||
local mall = datavalue.value.time |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'qq' then |
|||
local mall = datavalue.value |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
function formatexternalid( datavalue, datatype, options ) |
|||
if options.pattern and options.pattern ~= '' |
|||
then |
|||
par = options.pattern |
|||
local 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.wikibase |
|||
then plabel = mw.wikibase.label( options.property ) or pp |
|||
end |
end |
||
ppp = mw.ustring.gsub( pp, ' ', '_' ) |
|||
return {value = tid} |
|||
if patter and patter ~= '' then -- if P1630 are there |
|||
elseif datatype == 'globe-coordinate' then |
|||
if par == "autourl" then -- like http://example.com/$1.html |
|||
tid = ppp |
|||
elseif 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 .. ']' |
|||
else |
|||
tid = formatFromPattern( formatcharacters(datavalue.value, options), options ) |
|||
end |
|||
else -- P1630 are not there |
|||
if par == "autourl" or par == "autourl2" or par == "autourl3" or par == "autourl4" |
|||
then |
|||
tid = formatcharacters(datavalue.value, options) --just return value |
|||
else |
|||
tid = formatFromPattern( formatcharacters(datavalue.value, options), options ) |
|||
end |
|||
end |
|||
else |
|||
tid = formatcharacters(datavalue.value, options) --just return value |
|||
end |
|||
return {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 ~= '' then |
|||
if options.modifytime == 'q' then |
|||
local mall = datavalue.value.time |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
elseif options.modifytime == 'precision' then |
|||
local mall = datavalue.value.precision |
|||
tid = mw.getCurrentFrame():preprocess(mall) |
|||
end |
|||
end |
|||
return {value = tid} |
|||
end |
|||
--[[ |
|||
datatype globe-coordinate |
|||
]] |
|||
function formatcoordinate( datavalue, datatype, options ) |
|||
--local GlobeCoordinate = require 'Module:GlobeCoordinate' |
--local GlobeCoordinate = require 'Module:GlobeCoordinate' |
||
--return {value = GlobeCoordinate.newFromWikidataValue( datavalue.value ):toHtml()} |
--return {value = GlobeCoordinate.newFromWikidataValue( datavalue.value ):toHtml()} |
||
local coord = datavalue.value |
local coord = datavalue.value |
||
local globe = datavalue.value.globe |
|||
local globetable = { Q2 = 'earth', Q111 = 'mars', Q405 = 'moon'} |
|||
globe2 = require('Module:Wikidata2/Globes')[globe] |
|||
if options.formatting and options.formatting ~= '' then |
if options.formatting and options.formatting ~= '' then |
||
if options.formatting == 'latitude' then |
if options.formatting == 'latitude' then pro =coord.latitude |
||
elseif options.formatting == 'longitude' then pro =coord.longitude |
|||
return {value =coord.latitude } |
|||
elseif options.formatting == ' |
elseif options.formatting == 'dimension' then pro =coord.dimension |
||
elseif options.formatting == 'precision' then pro =coord.precision |
|||
return {value =coord.longitude } |
|||
elseif options.formatting == ' |
elseif options.formatting == 'globe' then pro = globe |
||
elseif options.formatting == 'globe2' then pro = globe2 |
|||
return {value =coord.dimension } |
|||
elseif options.formatting == ' |
--elseif options.formatting == 'coord' then |
||
return {value = |
--return {value = } |
||
--elseif options.formatting == 'coord' then |
|||
--return {value = } |
|||
else |
else |
||
end |
end |
||
else |
else |
||
pro = |
|||
return {value =mw.getCurrentFrame():expandTemplate{ title = "coord", args = {coord.latitude,coord.longitude,display=inline} }..catewikidatainfo(options) } |
|||
mw.getCurrentFrame():preprocess('{{ {{{|safesubst:}}}#invoke:Coordinates|coord' |
|||
.. '|'.. coord.latitude |
|||
.. '|'.. coord.longitude |
|||
.. '|display=inline' |
|||
.. '|globe:'.. globe2 ..'_type:landmark' |
|||
.. '|format='..(options.formatcoord or '')..'}}' |
|||
)..catewikidatainfo(options) |
|||
end |
end |
||
return {value = pro } |
|||
end |
|||
elseif datatype == 'quantity' then |
|||
--[[ |
|||
datatype quantity |
|||
]] |
|||
function formatquantity( datavalue, datatype, options ) |
|||
local amount, unit, cat = datavalue.value.amount, datavalue.value.unit, nil |
local amount, unit, cat = datavalue.value.amount, datavalue.value.unit, nil |
||
if unit then |
if unit then |
||
سطر 700: | سطر 965: | ||
local formatera = require('وحدة:Math') |
local formatera = require('وحدة:Math') |
||
local number = formatera.newFromWikidataValue(datavalue.value) |
local number = formatera.newFromWikidataValue(datavalue.value) |
||
amount = mw.ustring.gsub( amount , '+', '' ) |
|||
local unitraw = unit |
local unitraw = unit |
||
if unit then |
if 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'}) |
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 == '' ) then |
if lab and ( not options.nounitshort or options.nounitshort == '' ) then |
||
local s = formatEntityId( unit, {label = lab, nolink = (options.nounitlink or options.nolink) }) |
local s = formatEntityId( unit, {label = lab ,enlabelcate ='t' , nolink = (options.nounitlink or options.nolink) }) |
||
unit = s.value |
unit = s.value |
||
cat = s.cat |
cat = s.cat |
||
else -- om det inte finns en |
else -- om det inte finns en f?rkortning |
||
local s = formatEntityId( unit, {nolink = options.nounitlink}) |
local s = formatEntityId( unit, {nolink = options.nounitlink ,enlabelcate ='t'}) |
||
unit = s.value |
unit = s.value |
||
cat = s.cat |
cat = s.cat |
||
end |
end |
||
end |
end |
||
local Value = amount .. ' ' .. (unit or '') |
|||
if options.nounit and options.nounit ~= "" then |
|||
Value = amount |
|||
elseif datatype == 'url' then |
|||
if options.label and options.label ~= '' then |
|||
return {value = '[' .. datavalue.value .. ' ' .. options.label .. ']'} |
|||
else |
|||
return {value = datavalue.value} |
|||
end |
end |
||
return {value = Value, amount = amount, unit = unit, unitraw = unitraw, cat = cat} |
|||
end |
|||
elseif datatype == 'monolingualtext' then |
|||
--[[ |
|||
lange = '('.. mw.language.fetchLanguageName(datavalue.value.language, 'ar')..')' |
|||
datatype url |
|||
]] |
|||
if not options.langpref or options.langpref == '' then |
|||
valu = mw.text.tag('span', {title = mw.language.fetchLanguageName(datavalue.value.language, 'ar')}, datavalue.value.text) |
|||
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 = 'الموقع الرسمي' end |
|||
if label and label ~= '' then |
|||
pro = '[' .. va .. ' ' .. label .. ']' |
|||
else |
else |
||
-- if property =='P856' then pro = formatFromPattern( formatcharacters(va, options), {pattern = '[$1 الموقع الرسمي]'} ) |
|||
if options.langpref == datavalue.value.language then |
|||
-- else |
|||
valu = mw.text.tag('span', {title = mw.language.fetchLanguageName(datavalue.value.language, 'ar')}, datavalue.value.text) |
|||
pro = va |
|||
-- end |
|||
end |
end |
||
return {value = pro } |
|||
if options.showlang and options.showlang ~= '' |
|||
end |
|||
then return {value = valu ..' '..lange, text = datavalue.value.text} |
|||
else return {value = valu , text = datavalue.value.text} |
|||
end |
|||
--[[ |
|||
datatype monolingualtext |
|||
]] |
|||
function formatmonolingualtext( datavalue, datatype, options ) |
|||
local Moduletext = require 'Module:wikidata2/monolingualtext' |
|||
local tid = Moduletext._main( datavalue, datatype, options ) |
|||
return {value = tid} |
|||
end |
|||
function 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 == 'tabular-data' then return formattabulardata( datavalue, datatype, options ) |
|||
else |
else |
||
return {value = formatError( 'unknown-datatype' )} |
return {value = formatError( 'unknown-datatype' )} |
||
end |
end |
||
end |
end |
||
function formatEntityId( entityId, options ) |
function formatEntityId( entityId, options ) |
||
سطر 752: | سطر 1٬059: | ||
label = mw.wikibase.label( entityId ) or nil |
label = mw.wikibase.label( entityId ) or nil |
||
end |
end |
||
local link = mw.wikibase.sitelink( entityId ) |
local link = mw.wikibase.sitelink( entityId ) |
||
if link and (not options.nolink or options.nolink == '') then |
if link and (not options.nolink or options.nolink == '') then |
||
if label and label ~= '' then |
if label and label ~= '' then |
||
return {value = '[[:' .. link .. '|' .. |
return {value = '[[:' .. link .. '|' .. formatcharacters(label, options) .. ']]'.. catewikidatainfo(options), label = label } |
||
else |
else |
||
return {value = '[[:' .. |
return {value = '[[:' .. link .. '|' .. formatcharacters(link, options) .. ']]'.. catewikidatainfo(options), label = link } |
||
end |
end |
||
else |
else |
||
if label |
if label and label ~= '' |
||
then |
|||
return {value = versalisering(label, options), label = label} |
|||
local label3 = Labelfunction( entityId, label,options.label, options) |
|||
return {value = label3 , label = label} |
|||
else return '' |
else return '' |
||
--local s = getLabelFromFallBack( entityId ) |
|||
--local l = mw.language.fetchLanguageName(s.language, 'ar') |
|||
--if not l or l == '' then |
|||
--l = 'okänt språk' |
|||
--end |
|||
--if s then |
|||
--return {value = mw.text.tag('span', {title = l, ['data-q'] = entityId, class='modulwikidata2_missingswedishlabel'}, versalisering(s.value, options) ), cat = 'Wikidataetiketter på ' .. l, label = s.value } |
|||
--end |
|||
end |
end |
||
return '' --{value = entityId, cat = 'som har labels med Qid', label = entityId} |
return '' --{value = entityId, cat = 'som har labels med Qid', label = entityId} |
||
end |
end |
||
end |
end |
||
--[[ |
|||
function to get any link from any sister project |
|||
]] |
|||
function sitelink_g( id , wikisite ) |
|||
if not mw.wikibase then return '' end |
|||
local site = wikisite or 'arwiki' |
|||
local link = mw.wikibase.sitelink( id , site ) or "" |
|||
--mw.log("mw.wikibase.sitelink,site: " .. site.. ",link:" .. link ) |
|||
return link |
|||
end |
|||
function sitelink( id , wikisite ) |
|||
local site = wikisite or 'arwiki' |
|||
if not mw.wikibase then return '' end |
|||
local entity = mw.wikibase.getEntityObject(id) |
|||
if entity |
|||
and entity.sitelinks |
|||
and entity.sitelinks[''..site..''] |
|||
and entity.sitelinks[''..site..''].site |
|||
and entity.sitelinks[''..site..''].title |
|||
then |
|||
if entity.sitelinks[''..site..''].site == site then |
|||
return entity.sitelinks[''..site..''].title |
|||
else return '' |
|||
end |
|||
end |
|||
end |
|||
--[[ |
|||
function to get only the value with link |
|||
]] |
|||
function formatsitelink( entityId, options ) |
|||
local link = sitelink( entityId ) |
|||
if link and link ~= '' then |
|||
if 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 '' |
|||
end |
|||
end |
|||
--[[ |
|||
function to replace $1 with string |
|||
]] |
|||
function formatFromPattern( str, options ) |
function formatFromPattern( str, options ) |
||
--if options.pattern and options.pattern ~='' then |
|||
return mw.ustring.gsub( options.pattern, '$1', str ) .. '' --الحصول على اول نتيجة للدالة |
|||
--mw.log( str .. ':' .. options.pattern ) |
|||
return mw.ustring.gsub( options.pattern, '$1', str ) --الحصول على اول نتيجة للدالة |
|||
-- else return str |
|||
--end |
|||
end |
end |
||
function addTrackingCategory(prop,options) |
|||
local cat = require('Module:Wikidata/تتبع').makecategory1 |
|||
local category = cat(options) |
|||
if prop and prop ~= '' then |
|||
if category and category ~= '' then |
|||
return prop .. ' ' .. category |
|||
else |
|||
return prop .. ' ' |
|||
end |
|||
end |
|||
end |
|||
-- 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 end |
|||
local entity = mw.wikibase.getEntity(pItem) |
|||
if not entity then return false end |
|||
local claims31 |
|||
local claims279 |
|||
if entity.claims then |
|||
if property and property ~= '' then |
|||
claims31 = entity.claims[mw.wikibase.resolvePropertyId(property)] |
|||
else |
|||
claims31 = entity.claims[mw.wikibase.resolvePropertyId('P31')] |
|||
claims279 = entity.claims[mw.wikibase.resolvePropertyId('P279')] |
|||
end |
|||
else |
|||
return false |
|||
end |
|||
function getSnakValue(snak) |
|||
if snak.snaktype == "value" then |
|||
if snak.datavalue.type == "wikibase-entityid" then |
|||
data = snak.datavalue.value['numeric-id'] |
|||
return data |
|||
end |
|||
end |
|||
end |
|||
if not claims31 and not claims279 then return false end |
|||
local parentIds = {} |
|||
if claims31 and #claims31 > 0 then |
|||
for i, v in ipairs(claims31) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) end |
|||
end |
|||
if claims279 and #claims279 > 0 then |
|||
for i, v in ipairs(claims279) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) end |
|||
end |
|||
-- check if searched parent or exit item is reached or do recursive call |
|||
if not parentIds[1] or #parentIds == 0 then return false end |
|||
local itemString = "" |
|||
local result = nil |
|||
for i, v in ipairs(parentIds) do |
|||
if not v then return false end |
|||
itemString = "Q" .. v |
|||
if itemString == pParent then |
|||
-- successful! |
|||
return true |
|||
elseif itemString == pExitItem then --or itemString == "Q35120" |
|||
-- exit if either "exit item" or node item (Q35120) is reached |
|||
return false |
|||
else |
|||
if pDepth+1 < pMaxDepth then |
|||
result = isParent(property, itemString, pParent, pExitItem, pMaxDepth, pDepth+1) |
|||
else return false end |
|||
if result == true then return result end |
|||
end |
|||
end |
|||
do return false end |
|||
end |
|||
function isSubclass(options) |
|||
if not options.parent then return false end |
|||
local maxDepth |
|||
maxDepth = tonumber(options.maxDepth) or 10 |
|||
if not type(maxDepth) == "number" then maxDepth = 5 end |
|||
property = options.property |
|||
local result |
|||
result = isParent(property, options.id, options.parent , options.exitItem, maxDepth) |
|||
if options.returnInt then |
|||
if result == true then return 1 else return nil end |
|||
else |
|||
return result |
|||
end |
|||
end |
|||
local p = {} |
local p = {} |
||
سطر 787: | سطر 1٬226: | ||
return formatEntityId( entityId, (options or {}) ) |
return formatEntityId( entityId, (options or {}) ) |
||
end |
end |
||
--[[ |
|||
function to add tracking category |
|||
]] |
|||
--[[ |
|||
The main function |
|||
]] |
|||
function p.formatStatements( frame, key ) |
function p.formatStatements( frame, key ) |
||
local args = frame.args |
local args = frame.args |
||
--If a value if already set, use it |
--If a value if already set, use it |
||
if args.value and args.value ~= '' then |
if args.value and args.value ~= '' then |
||
return args.value |
return args.value |
||
end |
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 |
|||
end |
|||
if args.addTrackingCat and args.addTrackingCat ~= '' then -- add tracking cat |
|||
prop = addTrackingCategory(prop,frame.args) |
|||
end |
|||
if args.mainsuffixAfterIcon and args.mainsuffixAfterIcon ~= '' then -- another suffix but after wikidata icon |
|||
prop = prop .. args.mainsuffixAfterIcon |
|||
end |
|||
else |
|||
if args.NoPropValue and args.NoPropValue ~= '' then -- value if no local value and no wikidata value |
|||
prop = args.NoPropValue |
|||
end |
|||
end |
|||
return prop |
|||
end |
end |
||
function p.formatStatementsFromLua( options, key ) |
function p.formatStatementsFromLua( options, key ) -- main function but to use from lua module |
||
--If a value if already set, use it |
--If a value if already set, use it |
||
if options.value and options.value ~= '' then |
if options.value and options.value ~= '' then |
||
سطر 807: | سطر 1٬270: | ||
s = nil |
s = nil |
||
end |
end |
||
if options.addTrackingCat and options.addTrackingCat ~= '' then -- add tracking cat |
|||
s= addTrackingCategory(s,options) |
|||
end |
|||
return s |
return s |
||
end |
end |
||
function p.getSiteLink(frame) |
|||
function p.isSubclass(frame) |
|||
local project = frame.args[2] or frame.args.site |
|||
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.site |
|||
local id = frame.args[1] or frame.args.id |
local id = frame.args[1] or frame.args.id |
||
if not id or id == "" then |
|||
if frame.args.page and frame.args.page ~= "" then |
|||
id = mw.wikibase.getEntityIdForTitle( frame.args.page ) |
|||
end |
|||
end |
|||
local link = sitelink( id , site ) |
|||
if link and link ~= '' then |
|||
return link |
|||
end |
|||
end |
|||
function p.getSiteLink1(frame) |
|||
local entity = mw.wikibase.getEntityObject(id) |
|||
local project = frame.args[1] |
|||
if not entity or entity == '' then return nil end |
|||
local |
local id = frame.args[2] |
||
local link =sitelink( id , project ) |
|||
var = link |
var = link |
||
return var |
return var |
||
end |
|||
function descriptionIn(langcode,id) |
|||
local lan = langcode or 'ar' |
|||
local entity = mw.wikibase.getEntityObject(id) |
|||
if entity |
|||
and entity.descriptions |
|||
and entity.descriptions[''..lan..''] |
|||
and entity.descriptions[''..lan..''].value |
|||
then |
|||
local lang = entity.descriptions[''..lan..''] |
|||
if lang['language'] == lan then |
|||
return entity.descriptions[''..lan..''].value |
|||
else return nil end |
|||
end |
|||
end |
end |
||
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata |
|||
function labelIn(langcode,id) |
|||
function p.pageId(frame) |
|||
local lan = langcode or 'ar' |
|||
local entity = mw.wikibase.getEntityObject( |
local entity = mw.wikibase.getEntityObject() |
||
if not entity then return nil else return entity.id end |
|||
if entity |
|||
and entity.labels |
|||
and entity.labels[''..lan..''] |
|||
and entity.labels[''..lan..''].value |
|||
then |
|||
local lang = entity.labels[''..lan..''] |
|||
if lang['language'] == lan then |
|||
return entity.labels[''..lan..''].value |
|||
else return nil end |
|||
end |
|||
end |
end |
||
سطر 860: | سطر 1٬315: | ||
return descriptionIn( langcode ,id ) |
return descriptionIn( langcode ,id ) |
||
end |
end |
||
function p.labelIn(frame) |
function p.labelIn(frame) |
||
local langcode = frame.args[1] |
local langcode = frame.args[1] |
||
سطر 867: | سطر 1٬321: | ||
return labelIn( langcode ,id ) |
return labelIn( langcode ,id ) |
||
end |
end |
||
function p.ViewSomething(frame) -- from en:Module:Wikidata |
|||
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent() |
|||
function p.pageId(frame) |
|||
if f.args.id and f.args.id ~='' then aa = f.args.id end |
|||
local entity = mw.wikibase.getEntityObject() |
|||
local data = mw.wikibase.getEntityObject(aa) |
|||
if not entity then return nil else return entity.id end |
|||
if not data then |
|||
return nil |
|||
end |
|||
local i = 1 |
|||
while true do |
|||
local index = f.args[i] |
|||
if not index then |
|||
if type(data) == "table" then |
|||
return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY) |
|||
else |
|||
return tostring(data) |
|||
end |
|||
end |
|||
data = data[index] or data[tonumber(index)] |
|||
if not data then |
|||
return |
|||
end |
|||
i = i + 1 |
|||
end |
|||
end |
end |
||
function p.Dump(frame) |
function p.Dump(frame) |
||
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent() |
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 end |
|||
local data = mw.wikibase.getEntityObject(f.args.id) |
|||
local data = mw.wikibase.getEntityObject(aa) |
|||
if not data then |
if not data then |
||
return i18n.warnDump |
return i18n.warnDump |
||
end |
end |
||
local i = 1 |
local i = 1 |
||
while true do |
while true do |
||
سطر 885: | سطر 1٬357: | ||
if not index then |
if not index then |
||
return frame:extensionTag("source", mw.dumpObject(data),{ lang= 'lua'}).. i18n.warnDump |
return frame:extensionTag("source", mw.dumpObject(data),{ lang= 'lua'}).. i18n.warnDump |
||
end |
end |
||
data = data[index] or data[tonumber(index)] |
data = data[index] or data[tonumber(index)] |
||
if not data then |
if not data then |
||
return i18n.warnDump |
return i18n.warnDump |
||
end |
end |
||
i = i + 1 |
i = i + 1 |
||
end |
end |
||
سطر 902: | سطر 1٬371: | ||
--mw.log(str) |
--mw.log(str) |
||
return str |
return str |
||
end |
end |
||
return p |
return p |
مراجعة 21:22، 14 ديسمبر 2017
مثال
{{#invoke:Wikidata2|formatStatements|property=p17}}
أنظر قائمة قوالب تستخدم هذه الوحدة.
الوسائط
formatStatements
|property=
مطلوب الخاصية المطلوبة.
|entityId=
معرف عنصر ويكي بيانات.|page=
يمكن إستخدامه بدلاً من|entityId=Q805
كالتالي:|page=اليمن
.
|enbarten=
يعرض أول قيمة فقط في الخاصية.|separator=
فاصلة بين البنود|
انظر أيضاconjunction
|conjunction=
الفاصلة الأخيرة قبل اخر بند، افتراضي، و
.
|prefix=
بادئة|suffix=
لاحقة|formatting=
يحدد تنسيق القيم يستخدم مع إحداثيات جغرافية، وعنصر، وخاصية.
|label=
اذا كنت تريد الاختيار كيفية ظهور الوصلات. مثلا[[شعار مقاطعة بليكينج|الشعار]]
يمكن الحصول عليها عن طريق اضافة|label=الشعار
تؤثر هذه المعلمة على الوحدات.
رتبة القيم
|rank=
يحدد نوع البيانات المطلوب عرضها:|rank=all
يظهر جميع البنود في الخاصية.|rank=valid
يظهر البنود المفضلة والتي بوضع "ترتيب عادي" ولكن لا يظهر المهملة.|rank=best
(افتراضي) يظهر القيم المفضلة.
فرز النتيجة
|sortbytime=
الترتيب حسب الوقت يفيد هذا مع المعلمة|enbarten=
أعلاه|sortbytime=chronological
ترتيب البنود حسب زمن التصفيات المذكورة.|sortbytime=inverted
عكس البنذ السابق.
|sortingproperty=
تحديد الخواص المدعومة، الافتراضي هو:'P585','P571','P580','P569','P582','P570'
بالترتيب، الخواص المعتمدة حالياً هي خواص الوقت. بتاريخ (P585) ،البداية (P571) ،تاريخ البدء (P580) ،تاريخ الميلاد (P569) ،تاريخ الانتهاء (P582) ،تاريخ الوفاة (P570).|sortingproperty=sortbyarbitrary
فرز القيم بواسطة تاريخ العناصر المرتبطة مثل تاريخ ولادة أبناء شخص "الأطفال". القيم المسموح بها هي:|sortingproperty=chronological
|sortingproperty=inverted
. وتعطى مع الخاصية المراد تفتيشها 'sortingproperty
اعلاه'.
المراجع
|noref=
أدخل قيمة في هذه المعلمة إذا كنت لا تريد جلب المصادر من ويكي بيانات.|justref=
أدخل قيمة في هذه المعلمة إذا كنت تريد جلب المصادر فقط دون ظهور القيمة!.|onlyvaluewithref =
لإظهار البيانات التي لها مراجع فقط.
صياغة النص
|formatcharacters=
تحديد صيغة اخراج القيمة، القيم المسموح بها هي:lc/uc/lcfirst/ucfirst
|formatcharacters=lc
: تحويل جميع أحرف النص الإنجليزي إلى حروف صغيرة.|formatcharacters=lcfirst
: تحويل الحرف الأول من النص الإنجليزي إلى حرف صغير.|formatcharacters=uc
: تحويل جميع أحرف النص الإنجليزي إلى حروف كبيرة.|formatcharacters=ucfirst
: تحويل الحرف الأول من النص الإنجليزي إلى حرف كبير.
تصفيات
|avoidqualifier=
يتجاهل القيم التي تحتوي تصفيات معينة، مثل:|avoidqualifier=P518
يظهر البند الذي لا يحتوي على تصفية ينطبق على جزء (P518).|withdate=
يضيف تصفية بتاريخ (P585) إذا كانت موجودة.|bothdates=
يضيف تصفيات تاريخ البدء (P580) وتاريخ الانتهاء (P582) إذا كانتا موجودتان كلاهما أو إحداهما.|bothdates=line
يضع سطر جديد قبل التاريخ.|bothdates=before
يضع التاريخ قبل القيمة.
|qual1=
يضيف تصفية محددة.|qual1=P1545
يضيف تصفية الترتيب في التسلسل (P1545) الى بنود الخاصية، مثال:منصب باراك أوباما + ترتيبه:{{#invoke:Wikidata2|formatStatements|entityId=Q76|property=P39|qual1=P1545|noref=true|rank=best}}
ينتج :← رئيس الولايات المتحدة (44)
|preferqualifier=
تحديد خاصية تصفيات يجب أن تكون بيانات الخاصية متضمنتها.|preferqualifiervalue=
تحدد القيمة التي تناسب أعلاه. يدعم حالياً العناصر فقط.
وسائط حسب نوع البيانات
عنصر
|nolink=
يظهر النتيجة دون وصلات.|getonly=
يستخدم هذا الوسيط إذا أردنا الحصول على عناصر معينة التي تكون قيمة نموذج من (P31) فيها تساوي قيمة هذا الوسيط، مثال:|getonly=Q5
للحصول على الأفراد فقط.- القيم المتعددة ممكنة، مثل :
|getonly=Q127448,Q193556
للحصول على البلديات السويدية والمناظر الطبيعية.
|getonlyproperty=
إذا أردنا استخدام خاصية أخرى بدلاً من نموذج من (P31) في البند السابق.
|formatting=raw
يعرض القيمة بشكل Q505.|formatting=sitelink
ينتج الوصلة إذا كانت موجودة في الويكي العربية.
ملف وسائط من كومنز
- تظهر الصور افتراضياً كالتالي:
{{#invoke:Wikidata2|formatStatements|entityId=Q76|property=P18|noref=true|rank=best}}
ينتج ← President Barack Obama.jpg
|image=
عند استخدام هذا الوسيط في خواص الصور تظهر الصورة مباشرة.|size=
لتحديد حجم الصورة (60 افتراضياً)، ضع القيمة دون (بك/px إلخ).
توصيف | يظهر |
---|---|
{{#invoke:Wikidata2|formatStatements|entityId=Q76|property=P18|image=true|noref=true|rank=best|size=100}} |
|
إحداثيات جغرافية
|formatting=latitude
يعرض خط العرض فقط.|formatting=longitude
يعرض خط الطول فقط.|formatting=precision
يعرض الدقة.|formatting=globe
يعرض عنصر الكوكب. مثال:
توصيف | يظهر |
---|---|
{{#invoke:Wikidata2|formatStatements|entityId=Q805|property=P625|formatting=globe}} |
http://www.wikidata.org/entity/Q2 |
نص أحادي اللغة نص بلغة وحيدة
|langpref=
في الوحدة، هناك مرشح يعطي أولوية للقيم التي تحتوي على "اللغة = العربية". أضف القيمة المطلوبة لتعطيل هذا الفلتر.|langpref=justlang
لإظهار لغة النص فقط دون النص.|showlang=
استخدم أي قيمة لإظهار النص حسب تنسيق قالب:رمز لغة واسمها.
كمية
|nounitlink=
يظهر وحدة القياس دون وصلة.|noshortunit=
لا يظهر الوحدات مختصرة. مثلاً لا يظهر كم بدلاً عن كيلومتر.
نص
نقطة زمنية
|modifytime=
يحدد تنسيق الوقت أو التاريخ:|modifytime=longdate
يكتب التاريخ في شكل "27 أبريل 2024"|modifytime=Y
يكتب التاريخ في شكل "2024" يظهر فقط السنة.|modifytime= F
يكتب التاريخ في شكل "أبريل" يظهر فقط الشهر.|modifytime= j
يكتب التاريخ في شكل "27" يظهر فقط اليوم.
|modifyqualifiertime=
تنسيق التاريخ على النحو الوارد أعلاه، ولكن يؤثر فقط على التصفيات.qualifier
معرف خارجي
|pattern=
طريقة عرض الخاصية مثلاً في وصلات الضبط الاستنادي$1
مثلاً:<nowiki>https://viaf.org/viaf/$1/</nowiki>
.|pattern=autourl
من خواص البند أعلاه، لنمط مستخدم في الخاصية المسار المنسق (P1630) (تنسيق عنوان URL) للخاصية المطلوبة.|pattern=autourl2
كما سبق، يقدم وصلة من نوع<nowiki>[https://viaf.org/viaf/$1/ $1] </nowiki>
المسار
|urllabel=
وضع تسمية لتظهر بدلاً من الوصلة، كما في معرف خارجي ولكن في خواص الروابط.- مثال عند استخدام (P2035) لباراك أوباما (Q76) مع/بدون الوسيط
|urllabel=لينكد إن
:
- مثال عند استخدام (P2035) لباراك أوباما (Q76) مع/بدون الوسيط
توصيف | يظهر |
---|---|
{{#invoke:Wikidata2|formatStatements|entityId=Q76|property=P2035}} |
|
{{#invoke:Wikidata2|formatStatements|urllabel=لينكد إن|entityId=Q76|property=P2035}} |
|
pageId
مثال: {{#invoke:Wikidata2|pageId}}
- Q24575438
getSiteLink
مثال: {{#invoke:Wikidata2|getSiteLink|Q76}}
- باراك أوباما
مثال: {{#invoke:Wikidata2|getSiteLink|Q76|enwiki}}
أو: {{#invoke:Wikidata2|getSiteLink|id=Q76|site=enwiki}}
- Barack Obama
أو:
{{#invoke:Wikidata2 |getSiteLink |page=اليمن |site=enwiki }}
- Yemen
Dump
مثال: {{#invoke:Wikidata2|Dump|claims|P19}}
- مثال2:
{{#invoke:Wikidata2|Dump|id=Q76|claims|P19}}
- مثال موسع:
{{#invoke:Wikidata2|Dump|claims|P1791|1|references|1|snaks|P244|1|datavalue|value}}
isSubclass / نوع فرعي من
إن كانت قيمة نموذج من (P31) أو صنف فرعي من (P279) للصفحة التي وضع فيها الكود أو للصفحة في الوسيط |id=
مساوية للوسيط |parent=
ينتج 'true' غير ذلك لا ينتج شيئاً.
كامل الخيارات:{{#invoke:Wikidata2|isSubclass|parent=|maxDepth=1|property=|id=|exitItem=}}
- مطلوب:
|parent=
مثلاً إنسان (Q5) |maxDepth=
عمق البحث في الصفحات.|property=
الخاصية المطلوبه (افتراضياً نموذج من (P31)، وصنف فرعي من (P279))|id=
الصفحة المطلوب البحث فيها.|exitItem=
مثال:
توصيف | يظهر |
---|---|
{{#invoke:Wikidata2|isSubclass|parent=Q5|maxDepth=1|id=Q76}} |
true |
{{#invoke:Wikidata2|isSubclass|parent=Q45|maxDepth=5|id=Q76}} |
false |
EntityIdForTitle
يعطي معرف ويكي بيانات من خلال عنوان المقالة: مثال:
{{#invoke:Wikidata2|EntityIdForTitle|اليمن}}
- ينتج: Q805
{{#invoke:Wikidata2|EntityIdForTitle|وحدة:Wikidata2}}
- ينتج: Q24575438
-- local fallback = {'en', 'nb', 'da', 'nn', 'de', 'fr', 'es', 'it', 'pt'}
local formatera = require('وحدة:Math')
local i18n = {
["errors"] = {
["property-param-not-provided"] = "Property parameter 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."
},
["noarabiclabel"] = "تصنيف:صفحات_ويكي_بيانات_بحاجة_لتسمية_عربية",
["warnDump"] = "[[Category:Called function 'Dump' from module Wikidata]]",
["somevalue"] = "", --''غير محدد''
["novalue"] ="",--قيمة مجهولة
["cateref"] ="[[تصنيف:صفحات بها مراجع ويكي بيانات]]"
}
local sortingproperties = {'P585','P571','P580','P569','P582','P570'}
function catewikidatainfo(options)
local prop = options.property
local catewikidatainfo = ' [[تصنيف:صفحات بها بيانات ويكي بيانات|'.. (prop or 'wikidata')..']]'
if (not options.nolink or options.nolink == '')
then return catewikidatainfo else return ''
end
end
--auktoritetsdata
function formatcharacters(label, options)
local formatcharacters = options.formatcharacters
--if options.FormatfirstCharacter and options.num == 1 then
--formatcharacters = options.FormatfirstCharacter
--end
if options.illwd2y and options.illwd2y ~= '' then
String2 = 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 String
return ca
end
if not formatcharacters or formatcharacters == '' then
return label
end
if formatcharacters == 'lcfirst' then
return mw.getCurrentFrame():preprocess("{{lcfirst: " .. label .. " }}")
elseif formatcharacters == 'ucfirst' then
return mw.language.getContentLanguage():ucfirst( label )
elseif formatcharacters == 'lc' then
return mw.getCurrentFrame():preprocess("{{lc: " .. label .. " }}")
elseif formatcharacters == 'uc' then
return mw.getCurrentFrame():preprocess("{{uc: " .. label .. " }}")
end
return label
end
function getqualifierbysortingproperty(claim, sortingproperty)
for k, v in pairs(sortingproperty) do
if claim.qualifiers and claim.qualifiers[v] and claim.qualifiers[v][1].snaktype == 'value' then
return claim.qualifiers[v][1].datavalue.value.time
end
end
return nil
end
function getDate(claim, options)
local sortingproperty = sortingproperties
if type(options.sortingproperty) == 'table' then
sortingproperty = options.sortingproperty
elseif type(options.sortingproperty) == 'string' then
sortingproperty = {options.sortingproperty}
end
return getqualifierbysortingproperty(claim, sortingproperty)
end
function get_entityId(options)
local id = options.entityId
if not id or id == "" then
if options.page and options.page ~= "" then
id = mw.wikibase.getEntityIdForTitle( options.page )
end
end
--mw.log("id :" .. id)
return id or ""
end
function getDateArb(claim, options)
local sortingproperty = options.sortingproperty or 'P569'
if claim.mainsnak.snaktype == 'value' then
local item = claim.mainsnak.datavalue.value['numeric-id']
if claim.mainsnak.datavalue.value['entity-type'] == 'item' then
item = 'Q' .. item
elseif claim.mainsnak.datavalue.value['entity-type'] == 'property' then
item = 'P' .. item
end
return formatStatements({property = sortingproperty, entityId = item, enbarten = 'true', sortbytime = 'chronological', noref = 'true'})
end
end
function descriptionIn(langcode , id) -- returns item description for a given language
local lan = langcode or 'ar'
if not mw.wikibase then return nil end
local description, lange = mw.wikibase.getDescriptionWithLang( id )
if lange == lan
then
return description
else
return nil
--return str
end
--[[local entity = mw.wikibase.getEntityObject(id)
if entity
and entity.descriptions
and entity.descriptions[''..lan..'']
and entity.descriptions[''..lan..''].value
then
local lang = entity.descriptions[''..lan..'']
if lang['language'] == lan then
return entity.descriptions[''..lan..''].value
else return nil end
end
]]
end
function labelIn(langcode,id) -- returns item label for a given language
if not mw.wikibase then return nil end
local lan = langcode or 'ar'
local label, lange = mw.wikibase.getLabelWithLang( id )
if lange == lan
then
return label
else
return nil
--return str
end
--[[local entity = mw.wikibase.getEntityObject(id)
if entity
and entity.labels
and entity.labels[''..lan..'']
and entity.labels[''..lan..''].value
then
local lang = entity.labels[''..lan..'']
if lang['language'] == lan then
return entity.labels[''..lan..''].value
else return nil end
end
]]
end
function comparedates(a, b) -- returns true if a is earlier than B or if a has a date but not b
if a and b then
return a > b
elseif a then
return true
end
end
function preferqualifier(claims, options)
local claims2 = {}
for i, statement in pairs( claims ) do --
if statement.qualifiers and statement.qualifiers[options.preferqualifier:upper()] then
if options.preferqualifiervalue and options.preferqualifiervalue ~= '' then
local active = false
for k, t in pairs(mw.text.split(options.preferqualifiervalue,',')) do
for j, value in pairs(formatStatements({property=options.preferqualifier:upper(), raw = 'true', formatting = 'raw'}, statement.qualifiers)) do
if value.item == t and not active then
--if value == t and not active then
table.insert( claims2, statement)
active = true
end
end
end
else
table.insert( claims2, statement)
end
end
end
return claims2
end
function sortbyqualifier(claims, options)
table.sort(claims, function(a,b)
local timeA = getDate(a, options)
local timeB = getDate(b, options)
if options.sortbytime == 'inverted' then
return comparedates(timeB, timeA)
else
return comparedates(timeA, timeB)
end
end
)
return claims
end
function sortbyarb(claims, options)
table.sort(claims, function(a,b)
local timeA = getDateArb(a, options)
local timeB = getDateArb(b, options)
if options.sortbyarbitrary == 'inverted' then
return comparedates(timeB, timeA)
else
return comparedates(timeA, timeB)
end
end
)
return claims
end
function Labelfunction( entityId, label ,labeloption , options) -- label with no arwiki sitelink
if options.illwd2nowd and options.illwd2nowd ~= '' then noWD='' else noWD='y' end
local jlabel = label --formatcharacters(label, options) -- The label
local ar = labelIn('ar',entityId ) -- The arabic label
local arlabel = ar --formatcharacters(ar, options)
if labeloption and labeloption ~= '' then
jlabel = labeloption
elseif options.illwd2 and options.illwd2 ~= '' then
if arlabel and arlabel ~= '' then
jlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {arlabel, id=entityId, y = (options.illwd2y or '') } }
else
jlabel = mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {id=entityId, target='en', y = (options.illwd2y or '') } }
end
elseif options.enlabelcate and options.enlabelcate ~= '' then
if not arlabel or arlabel == '' then
jlabel = label --formatcharacters(label, options)
if jlabel and jlabel ~= '' then
jlabel = jlabel ..' [['.. i18n.noarabiclabel ..'|'.. entityId ..']]'
end end
else--if options.justarabic and options.justarabic ~= '' then
if arlabel and arlabel ~= ''
then jlabel = arlabel
else jlabel = nil
end
end
if jlabel and jlabel ~= ''
then
return jlabel.. catewikidatainfo(options)
end
end
function getEntityFromId( id )
if not mw.wikibase then return nil end
if id and id ~= "" then
return mw.wikibase.getEntityObject( id )
else
return mw.wikibase.getEntityObject()
end
end
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' )
end
end
function formatError( key )
return i18n.errors[key]
end
function formatOneStatement( statement ,ref , options)
local vava = nil
local stat = formatStatement( statement, options )
if stat then
local s = stat.value
local d = stat.datum
local tf = stat.tifr
local awardqual = stat.foto
local pr = stat.pr
--local utgivort = stat.utgivort
local ro = stat.ro
local qp1a = stat.qp1a
local onlyqualifier = stat.onlyqualifier
local qp1 = stat.qp1
local qp2 = stat.qp2
local qp3 = stat.qp3
local qp4 = stat.qp4
local qp5 = stat.qp5
local amatch =stat.amatch
local reff =stat.reff
local goal =stat.goal
local start2 = stat.start1
local finish2 = stat.finish1
local before2 = stat.before1
local after2 = stat.after1
local constituency2 = stat.constituency1
local series2 = stat.series1
local electedin2 = stat.electedin1
local P1001 = stat.pp1001
local P108 = stat.pp108
local P642 = stat.pp642
if s == '' then s = nil end
if s then
if reff and options.reff and options.reff ~= '' then
s= s .. reff
end
if options.template and options.template ~= '' then
s = 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} }
end
if options.football and options.football ~= '' then
s =mw.getCurrentFrame():expandTemplate{ title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args = {(start2 or ''),(finish2 or '') ,s,amatch,goal } }
end
if options.office and options.office ~= '' then
s = 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
} }
end
function qoo(Prefix,qualpref,p,Suffix)
if p and p ~='' then
return mw.text.tag('small', {}, (Prefix or ' (').. (qualpref or '') .. p .. (Suffix or ')')) end
end
QPrefix = options.qualifierprefix
QSuffix = options.qualifiersuffix
if qp1 and qp1 ~='' and options.qual1 and options.qual1 and qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= ''
then
s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix)
elseif qp1 and qp1 ~='' and options.qual1 and options.qual1 ~= '' then
s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix)
elseif qp1a and qp1a ~='' and options.qual1a and options.qual1a ~= '' then
s = s .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix)
end
if qp2 and qp2 ~='' and options.qual2 and options.qual2 ~= '' then s = s .. qoo(QPrefix, options.qual2pref, qp2, QSuffix) end
if qp3 and qp3 ~='' and options.qual3 and options.qual3 ~= '' then s = s .. qoo(QPrefix, options.qual3pref, qp3, QSuffix) end
if qp4 and qp4 ~='' and options.qual4 and options.qual4 ~= '' then s = s .. qoo(QPrefix, options.qual4pref, qp4, QSuffix) end
if qp5 and qp5 ~='' and options.qual5 and options.qual5 ~= '' then s = s .. qoo(QPrefix, options.qual5pref, qp5, QSuffix) end
if 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) end
if d and d ~='' and options.withdate and options.withdate ~= '' then
if 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)
end
end
if awardqual and options.awardqua and options.awardqua ~= '' then s = s .. qoo(QPrefix, '' , awardqual, QSuffix) end
if tf and options.bothdates and options.bothdates ~= '' then
if options.bothdates == 'line'
then s = s .. mw.text.tag('br') .. qoo(QPrefix, '' , tf, QSuffix)
elseif options.bothdates == 'before'
then s = qoo(QPrefix, '' , tf, QSuffix) .. s
else
s = s .. qoo(QPrefix, '' , tf, QSuffix)
end
end
--if utgivort and options.withutgivort and options.withutgivort ~= '' then
--if options.withutgivort == 'قوسين' then s = s .. ' ' .. qoo(QPrefix, '' , utgivort, QSuffix)
--else s = s .. ' ' .. utgivort
--end
--end
if pr and pr ~= '' and options.getsimpleproperty and options.getsimpleproperty ~= '' then
if 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 .. '')
end
end
if type(ref) == 'table' or (options.noref and options.noref ~='') or (options.justthisqual and options.justthisqual ~='')
then
--table.insert( formattedStatements, s )
vava = s
else
local t = formatReferences( statement, options )
stat.ref = t
if options.justref and options.justref ~= ''
then
vava = t
elseif options.onlyvaluewithref and options.onlyvaluewithref ~= '' then
if t and t ~= "" then
vava = s .. t
end
else
vava = s .. t
end
end
end
--table.insert(statementsraw, stat)
end
return { v = vava , raw = stat}
end
function 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 tabell
claims = 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 cleanly
if options.rank == 'best' or not options.rank then
claims = entity:getBestStatements( options.property:upper() )
elseif options.rank == 'valid' then
for i, statement in pairs( entity.claims[options.property:upper()] ) do
if statement.rank == 'preferred' or statement.rank == 'normal' then
table.insert( claims, statement )
end
end
elseif options.rank == 'all' then
for i, statement in pairs( entity.claims[options.property:upper()] ) do
table.insert( claims, statement )
end
else
for i, statement in pairs( entity.claims[options.property:upper()] ) do
if statement.rank == options.rank then
table.insert( claims, statement )
end
end
end
if options.avoidqualifier then -- to avoid value with a given qualifier
local claims2 = {}
for i, statement in pairs( claims ) do
if not statement.qualifiers or not statement.qualifiers[options.avoidqualifier:upper()] then
table.insert( claims2, statement)
end
end
claims = claims2
if options.preferqualifier and options.preferqualifier ~= '' then
claims = preferqualifier(claims, options)
end
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 == '' then
local claims2 = {}
for i, statement in pairs( claims ) do
if statement.qualifiers and statement.qualifiers.P407 then
for k, v in pairs( statement.qualifiers.P407 ) do
if v.snaktype == 'value' and v.datavalue.value['numeric-id'] == 13955 then -- Q13955 = 'العربية'
table.insert( claims2, statement )
end
end
elseif statement.qualifiers and statement.qualifiers.P282 then
for k, v in pairs( statement.qualifiers.P282 ) do
if v.snaktype == 'value' and v.datavalue.value['numeric-id'] == 8196 then -- Q8196 = 'أبجدية عربية'
table.insert( claims2, statement )
end
end
end
end
if #claims2 > 0 then
claims = claims2
end
end
if options.sortbytime == 'chronological' or options.sortbytime == 'inverted' then
claims = sortbyqualifier(claims, options)
elseif options.sortbyarbitrary == 'chronological' or options.sortbyarbitrary == 'inverted' then
claims = sortbyarb(claims, options)
end
end
if options.enbarten and options.enbarten ~= '' and #claims > 1 then
claims = {claims[1]}
end
local statementsraw = {}
if claims then
--==========================================
if options['property-module'] or options['property-function'] then
if not options['property-module'] or not options['property-function'] then
return formatError( 'unknown-property-module' )
end
local formatter = require ('Module:' .. options['property-module'])
if not formatter then
return formatError( 'property-module-not-found' )
end
local fun = formatter[options['property-function']]
if not fun then
return formatError( 'property-function-not-found' )
end
mw.log("work with property-module: " .. options['property-module'] .. "|" .. options['property-function'])
return fun( claims, options )
else
--==========================================
for i, statement in pairs( claims ) do
options.num = i
local va = formatOneStatement( statement,ref, options )
if va.v then
table.insert( formattedStatements, va.v )
end
table.insert( statementsraw, va.raw )
end
end
end
local Separator = options.separator-- or ""
local Conjunction = options.conjunction-- or ""
if Conjunction and Conjunction == "br" then Conjunction = "\n" end
if Separator and Separator == "br"
then
Separator = "\n"
Conjunction = "\n"
end
local tot = mw.text.listToText( formattedStatements, Separator, Conjunction )
if tot == '' then tot = nil end
if options.raw and options.raw ~= '' then
return statementsraw
end
return tot
end
function formatReferences( statement, options )
local reference = {}
if statement.references then
local cite = require('وحدة:Cite')
for i, ref in pairs(statement.references) do
local items = {}
if ref.snaks then
s = cite.citeitem2(ref , options )
--s = cite.citeitem( items , ref.snaks , ref.hash , options )
end
table.insert(reference, s)
end
end
local final = table.concat(reference)
if final and final ~= '' then
final = final .. i18n.cateref
end
return final
end
function 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 '') end
end
if options.template and options.template ~= '' then
s.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)
end
if statement.qualifiers.P1350 or statement.qualifiers.P1351 then
s.amatch = qua("P1350",'true')
s.goal = qua("P1351",'true')
end
if statement.qualifiers.P580 or statement.qualifiers.P582 or statement.qualifiers.P1365 or statement.qualifiers.P1366 then
s.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")
end
if statement.qualifiers.P585 then
s.datum = qua("P585",'true',options.modifyqualifiertime)
end
local qwe = options.qwer
if statement.qualifiers.qwe then
s.ro = qua(qwe,'true')
end
if statement.qualifiers.P574 then
s.dateoftaxpub = qua("P574",'true',options.modifyqualifiertime)
end
if statement.qualifiers.P405 then
local author = {}
for i, j in pairs(statement.qualifiers.P405) do
if j.snaktype == 'value' then
local item = 'Q' .. j.datavalue.value['numeric-id']
local authorname = formatStatements({property = "P428", entityId = item, noref = 'true', enbarten = 'true'})
if author and authorname ~= '' then
table.insert(author, formatEntityId(item, {label = authorname }).value)
else
table.insert(author, formatEntityId(item, {}).value)
end
end
end
s.auktor = mw.text.listToText(author, ', ', ' & ')
end
if statement.qualifiers.P580 or statement.qualifiers.P582 then
local f = qua("P580",'true',options.modifyqualifiertime)
local t = qua("P582",'true',options.modifyqualifiertime)
s.tifr = f .. '–' .. t
end
if statement.qualifiers.P585 or statement.qualifiers.P1346 then
local fo = qua("P585",'true',options.modifyqualifiertime)
local to = qua('P1346','true')
s.foto = fo .. ' ' .. mw.text.tag('span', {}, ' ' .. to .. '')
end
function quaaal(opti,options)
if opti and opti ~='' and statement.qualifiers[opti] then
return (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 '')
end
end
--if statement.qualifiers.P291 then -- خاصية بلد النشر
--s.utgivort = quaaal('P291',options)
--end
if statement.qualifiers.P2096 then
s.bildtext = formatStatements({property = "P2096", noref = 'true', langpref = (options.langpref or 'ar')}, statement.qualifiers)
end
if options.justthisqual and options.justthisqual ~= '' and statement.qualifiers[options.justthisqual] then
s.onlyqualifier = quaaal(options.justthisqual,options)
end
if options.qual1 and options.qual1 ~= '' and statement.qualifiers[options.qual1] then s.qp1 = quaaal(options.qual1,options) end
if options.qual1a and options.qual1a ~= '' and statement.qualifiers[options.qual1a] then s.qp1a = quaaal(options.qual1a,options) end
if options.qual2 and options.qual2 ~= '' and statement.qualifiers[options.qual2] then s.qp2 = quaaal(options.qual2,options) end
if options.qual3 and options.qual3 ~= '' and statement.qualifiers[options.qual3] then s.qp3 = quaaal(options.qual3,options) end
if options.qual4 and options.qual4 ~= '' and statement.qualifiers[options.qual4] then s.qp4 = quaaal(options.qual4,options) end
if options.qual5 and options.qual5 ~= '' and statement.qualifiers[options.qual5] then s.qp5 = quaaal(options.qual5,options) end
end
function formatStatement( statement, options )
if options['claim-module'] or options['claim-function'] then
if 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 ~= '' then
if statement.references then
if options.reff and options.reff ~= '' then
s.reff = formatReferences( statement, options )
end
end
if statement.qualifiers then
qualu = formatqualifiers( statement,s, options )
if qualu and qualu ~= '' then table.insert(qualu) end
end
end
return s
elseif not statement.type then
return formatSnak( statement, options )
end
return {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' )}
end
end
--[[
datatype wikibase-item
]]
function formatwikibaseitem( datavalue, datatype, options )
if options.formatting and options.formatting ~= ''
then
if 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 list
return {value = formatsitelink(datavalue.value.id , options ) }
else
return {value = formatFromPattern( formatcharacters(datavalue.value, options), options )}
end
elseif options.property1 and options.property1 ~= '' then
for 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 ~= '' then
if caca and caca ~= '' then
local cooooca = (options.property1pref or '') ..''.. caca ..''.. (options.property1suff or '')
if options.property1after and options.property1after ~= "" then
return {value = asdf .. cooooca }
else
return {value = cooooca .. ' '.. asdf }
end
else
return {value = asdf }
end
end
end
elseif options.propertyimage and options.propertyimage ~= '' then
for 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 ~= '' then
for 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 } end
end
end else
return {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 ~= ''
then
if options.formatting == 'raw' then
tid = getEntityIdFromValue( datavalue.value )
else
end
else
tid = formatEntityId( getEntityIdFromValue( datavalue.value ), options ).value
end
return {value = tid}
end
--[[
tabular-data
]]
function formattabulardata( 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 image
tid = '[[file:' .. datavalue.value .. '|'.. (options.size or '60')..'px|'..'border'..']]'
else
tid = formatcharacters(datavalue.value, options)
end
return {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 , auktoritetsdata3
if options.pattern and options.pattern ~= '' then
par = options.pattern
if 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 )
end
else
tid = formatcharacters(datavalue.value, options)
end
return {value = tid}
end
function formatexternalid( datavalue, datatype, options )
if options.pattern and options.pattern ~= ''
then
par = options.pattern
local 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.wikibase
then plabel = mw.wikibase.label( options.property ) or pp
end
ppp = mw.ustring.gsub( pp, ' ', '_' )
if patter and patter ~= '' then -- if P1630 are there
if par == "autourl" then -- like http://example.com/$1.html
tid = ppp
elseif 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 .. ']'
else
tid = formatFromPattern( formatcharacters(datavalue.value, options), options )
end
else -- P1630 are not there
if par == "autourl" or par == "autourl2" or par == "autourl3" or par == "autourl4"
then
tid = formatcharacters(datavalue.value, options) --just return value
else
tid = formatFromPattern( formatcharacters(datavalue.value, options), options )
end
end
else
tid = formatcharacters(datavalue.value, options) --just return value
end
return {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 ~= '' then
if options.modifytime == 'q' then
local mall = datavalue.value.time
tid = mw.getCurrentFrame():preprocess(mall)
elseif options.modifytime == 'precision' then
local mall = datavalue.value.precision
tid = mw.getCurrentFrame():preprocess(mall)
end
end
return {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
globe2 = require('Module:Wikidata2/Globes')[globe]
if options.formatting and options.formatting ~= '' then
if 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
elseif options.formatting == 'globe2' then pro = globe2
--elseif options.formatting == 'coord' then
--return {value = }
else
end
else
pro =
mw.getCurrentFrame():preprocess('{{ {{{|safesubst:}}}#invoke:Coordinates|coord'
.. '|'.. coord.latitude
.. '|'.. coord.longitude
.. '|display=inline'
.. '|globe:'.. globe2 ..'_type:landmark'
.. '|format='..(options.formatcoord or '')..'}}'
)..catewikidatainfo(options)
end
return {value = pro }
end
--[[
datatype quantity
]]
function formatquantity( datavalue, datatype, options )
local amount, unit, cat = datavalue.value.amount, datavalue.value.unit, nil
if unit then
unit = unit:match('Q%d+')
end
local formatera = require('وحدة:Math')
local number = formatera.newFromWikidataValue(datavalue.value)
amount = mw.ustring.gsub( amount , '+', '' )
local unitraw = unit
if 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 == '' ) then
local s = formatEntityId( unit, {label = lab ,enlabelcate ='t' , nolink = (options.nounitlink or options.nolink) })
unit = s.value
cat = s.cat
else -- om det inte finns en f?rkortning
local s = formatEntityId( unit, {nolink = options.nounitlink ,enlabelcate ='t'})
unit = s.value
cat = s.cat
end
end
local Value = amount .. ' ' .. (unit or '')
if options.nounit and options.nounit ~= "" then
Value = amount
end
return {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 = 'الموقع الرسمي' end
if label and label ~= '' then
pro = '[' .. va .. ' ' .. label .. ']'
else
-- if property =='P856' then pro = formatFromPattern( formatcharacters(va, options), {pattern = '[$1 الموقع الرسمي]'} )
-- else
pro = va
-- end
end
return {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}
end
function 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 == 'tabular-data' then return formattabulardata( datavalue, datatype, options )
else
return {value = formatError( 'unknown-datatype' )}
end
end
function formatEntityId( entityId, options )
local label = options.label or mw.wikibase.label( entityId )
if label == '' then
label = mw.wikibase.label( entityId ) or nil
end
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}
end
end
--[[
function to get any link from any sister project
]]
function sitelink_g( id , wikisite )
if not mw.wikibase then return '' end
local site = wikisite or 'arwiki'
local link = mw.wikibase.sitelink( id , site ) or ""
--mw.log("mw.wikibase.sitelink,site: " .. site.. ",link:" .. link )
return link
end
function sitelink( id , wikisite )
local site = wikisite or 'arwiki'
if not mw.wikibase then return '' end
local entity = mw.wikibase.getEntityObject(id)
if entity
and entity.sitelinks
and entity.sitelinks[''..site..'']
and entity.sitelinks[''..site..''].site
and entity.sitelinks[''..site..''].title
then
if entity.sitelinks[''..site..''].site == site then
return entity.sitelinks[''..site..''].title
else return ''
end
end
end
--[[
function to get only the value with link
]]
function formatsitelink( entityId, options )
local link = sitelink( entityId )
if link and link ~= '' then
if 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 ''
end
end
--[[
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
--end
end
function addTrackingCategory(prop,options)
local cat = require('Module:Wikidata/تتبع').makecategory1
local category = cat(options)
if prop and prop ~= '' then
if category and category ~= '' then
return prop .. ' ' .. category
else
return prop .. ' '
end
end
end
-- 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 end
local entity = mw.wikibase.getEntity(pItem)
if not entity then return false end
local claims31
local claims279
if entity.claims then
if property and property ~= '' then
claims31 = entity.claims[mw.wikibase.resolvePropertyId(property)]
else
claims31 = entity.claims[mw.wikibase.resolvePropertyId('P31')]
claims279 = entity.claims[mw.wikibase.resolvePropertyId('P279')]
end
else
return false
end
function getSnakValue(snak)
if snak.snaktype == "value" then
if snak.datavalue.type == "wikibase-entityid" then
data = snak.datavalue.value['numeric-id']
return data
end
end
end
if not claims31 and not claims279 then return false end
local parentIds = {}
if claims31 and #claims31 > 0 then
for i, v in ipairs(claims31) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) end
end
if claims279 and #claims279 > 0 then
for i, v in ipairs(claims279) do parentIds[#parentIds+1] = getSnakValue(v.mainsnak) end
end
-- check if searched parent or exit item is reached or do recursive call
if not parentIds[1] or #parentIds == 0 then return false end
local itemString = ""
local result = nil
for i, v in ipairs(parentIds) do
if not v then return false end
itemString = "Q" .. v
if itemString == pParent then
-- successful!
return true
elseif itemString == pExitItem then --or itemString == "Q35120"
-- exit if either "exit item" or node item (Q35120) is reached
return false
else
if pDepth+1 < pMaxDepth then
result = isParent(property, itemString, pParent, pExitItem, pMaxDepth, pDepth+1)
else return false end
if result == true then return result end
end
end
do return false end
end
function isSubclass(options)
if not options.parent then return false end
local maxDepth
maxDepth = tonumber(options.maxDepth) or 10
if not type(maxDepth) == "number" then maxDepth = 5 end
property = options.property
local result
result = isParent(property, options.id, options.parent , options.exitItem, maxDepth)
if options.returnInt then
if result == true then return 1 else return nil end
else
return result
end
end
local 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
end
if args.addTrackingCat and args.addTrackingCat ~= '' then -- add tracking cat
prop = addTrackingCategory(prop,frame.args)
end
if args.mainsuffixAfterIcon and args.mainsuffixAfterIcon ~= '' then -- another suffix but after wikidata icon
prop = prop .. args.mainsuffixAfterIcon
end
else
if args.NoPropValue and args.NoPropValue ~= '' then -- value if no local value and no wikidata value
prop = args.NoPropValue
end
end
return prop
end
function 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
end
if options.addTrackingCat and options.addTrackingCat ~= '' then -- add tracking cat
s= addTrackingCategory(s,options)
end
return s
end
function 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.site
local id = frame.args[1] or frame.args.id
if not id or id == "" then
if frame.args.page and frame.args.page ~= "" then
id = mw.wikibase.getEntityIdForTitle( frame.args.page )
end
end
local link = sitelink( id , site )
if link and link ~= '' then
return link
end
end
function p.getSiteLink1(frame)
local project = frame.args[1]
local id = frame.args[2]
local link =sitelink( id , project )
var = link
return var
end
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata
function p.pageId(frame)
local entity = mw.wikibase.getEntityObject()
if not entity then return nil else return entity.id end
end
function 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 configuration
return descriptionIn( langcode ,id )
end
function 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 configuration
return labelIn( langcode ,id )
end
function p.ViewSomething(frame) -- from en:Module:Wikidata
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 end
local data = mw.wikibase.getEntityObject(aa)
if not data then
return nil
end
local i = 1
while true do
local index = f.args[i]
if not index then
if type(data) == "table" then
return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY)
else
return tostring(data)
end
end
data = data[index] or data[tonumber(index)]
if not data then
return
end
i = i + 1
end
end
function 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 end
local data = mw.wikibase.getEntityObject(aa)
if not data then
return i18n.warnDump
end
local i = 1
while true do
local index = f.args[i]
if not index then
return frame:extensionTag("source", mw.dumpObject(data),{ lang= 'lua'}).. i18n.warnDump
end
data = data[index] or data[tonumber(index)]
if not data then
return i18n.warnDump
end
i = i + 1
end
end
function p.EntityIdForTitle(frame)
local title = frame.args[1]
local str = mw.wikibase.getEntityIdForTitle( title )
--mw.log(str)
return str
end
return p