local p = {} local Frame_args = {} local Moduletext local Modulecite local Moduleflags local InfoboxImage local ModuleGlobes local formatera local weblink local citetitle = "Module:Cite Q" if nil ~= string.find(mw.getCurrentFrame():getTitle(), "ملعب", 1, true) then citetitle = "Module:Cite Q/ملعب" end local i18n = { ["errors"] = { ["property-param-not-provided"] = "وسيط property غير متوفر.", ["entity-not-found"] = "الكيان غير موجود.", ["unknown-claim-type"] = "نوع claim غير معروف.", ["unknown-snak-type"] = "نوع snak غير معروف.", ["unknown-datatype"] = "نوع data غير معروف.", ["unknown-entity-type"] = "نوع entity غير معروف.", ["unknown-value-module"] = "يجب عليك تعيين كل من value-module و value-function.", ["unknown-claim-module"] = "يجب عليك تعيين كل من claim-module و claim-function.", ["unknown-property-module"] = "يجب عليك تعيين كل من property-module و property-function.", ["property-module-not-found"] = "الوحدة المستخدمة في وسيط property-module غير موجودة.", ["property-function-not-found"] = "الوظيفة المستخدمة في وسيط property-function غير موجودة.", ["value-module-not-found"] = "الوحدة المستخدمة في وسيط value-module غير موجودة.", ["value-function-not-found"] = "الوظيفة المستخدمة في وسيط value-function غير موجودة.", ["claim-module-not-found"] = "الوحدة المستخدمة في وسيط claim-module غير موجودة.", ["claim-function-not-found"] = "الوظيفة المستخدمة في وسيط claim-function غير موجودة." }, ["noarabiclabel"] = "تصنيف:صفحات_ويكي_بيانات_بحاجة_لتسمية_عربية", ["warnDump"] = "[[Category:Called function 'Dump' from module Wikidata]]", ["somevalue"] = "", --'"غير محدد"' ["novalue"] = "", --قيمة مجهولة ["cateref"] = "[[" .. "تصنيف:صفحات بها مراجع ويكي بيانات" .. "]]", ["to translate"] = "صفحات تستعمل معطيات من ويكي بيانات بحاجة لترجمة", ["trackingcat"] = "صفحات تستخدم خاصية $1", ["see-wikidata-value"] = "الاطلاع ومراجعة البيانات على ويكي داتا", ["see-wikidata"] = "راجع العنصر من ويكي بيانات المقابل", ["see-another-project"] = "مقالة على $1", ["see-another-language"] = "مقالة على ويكيبيديا $1" } local sortingproperties = {"P585", "P571", "P580", "P569", "P582", "P570"} local sorting_methods = { ["chronological"] = "chronological", ["تصاعدي"] = "chronological", ["asc"] = "chronological", ["inverted"] = "inverted", ["تنازلي"] = "inverted", ["desc"] = "inverted" } local falsetitles = { "قالب:قيمة ويكي بيانات", "وحدة:Wikidata2" } local skiip_items = { ["P106"] = { "Q42857", -- prophet "Q14886050", -- terrorist "Q2159907" -- criminal } } function isvalid(x) if x and x ~= "" then return x end return nil end function isntvalid(x) if not x or x == "" or x == nil then return true end return false end function No_Tracking_cat(options) if isvalid(options.formatting) == "raw" or isvalid(options.formatting) == "sitelink" then return true end local notracking = isvalid(options.nocate) or isvalid(options.notracking) or isvalid(Frame_args.notracking) local raw = isvalid(options.raw) or isvalid(Frame_args.raw) or isvalid(options.raw2) or isvalid(Frame_args.raw2) local nolink = isvalid(options.nolink) or isvalid(Frame_args.nolink) if notracking or raw or nolink then return true end local pagetitle = mw.title.getCurrentTitle().text for _, title in pairs(falsetitles) do if string.find(pagetitle, title, 1, true) then mw.log("notracking for title with: " .. title) return true end end return false end function addTrackingCategory(options) if No_Tracking_cat(options) then return "" end local cat = require("Module:Wikidata/تتبع").makecategory1 local category = cat(options) local nbsp = " " if isvalid(options.nbsp) then nbsp = "" end if isvalid(category) then return nbsp .. category end return "" end function catewikidatainfo(options) --[[ function to add tracking category ]] if No_Tracking_cat(options) then return "" end local cat = "" local prop = options.property cat = cat .. " [[" .. "تصنيف:صفحات بها بيانات ويكي بيانات|" .. (prop or "wikidata") .. "]]" if isntvalid(options.nolink) then return cat else return "" end end function getqualifierbysortingproperty(claim, sortingproperty) for k, v in pairs(sortingproperty) do if claim and claim.qualifiers and claim.qualifiers[v] and claim.qualifiers[v][1].snaktype == "value" then local vali = claim.qualifiers[v][1].datavalue.value.time or claim.qualifiers[v][1].datavalue.value.amount if vali:sub(1, 1) == "+" then vali = vali:sub(2) end --mw.log(vali) return vali end end return nil end function get_sorting_properties(options) if type(options.sortingproperty) == "table" then return options.sortingproperty elseif type(options.sortingproperty) == "string" and options.sortingproperty ~= "" then return mw.text.split(options.sortingproperty, ",") else return sortingproperties end end function getDate(claim, options) local sortingproperty = get_sorting_properties(options) return getqualifierbysortingproperty(claim, sortingproperty) end function get_entityId(options) local id = isvalid(options.entityId) or isvalid(options.id) or isvalid(options.qid) if id then return id end if isvalid(options.page) then id = mw.wikibase.getEntityIdForTitle(options.page) else id = mw.wikibase.getEntityIdForCurrentPage() end return id or "" end function countSiteLinks(id) local numb = 0 local entity = mw.wikibase.getEntityObject(id) if entity and entity.sitelinks then for i, v in pairs(entity.sitelinks) do numb = numb + 1 end end return numb end function make_format_num(String) local line = String line = mw.getCurrentFrame():preprocess("{{ {{{|safesubst:}}}formatnum: " .. String .. " }}") line = mw.ustring.gsub(line, "٫", ".") line = mw.ustring.gsub(line, "٬", ",") return line end function formatcharacters(label, options) local formatch = options.formatcharacters --if options.FormatfirstCharacter and options.num == 1 then --formatch = options.FormatfirstCharacter --end local String2 = mw.ustring.gsub(label, "–", "-") local march_y = 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) or mw.ustring.match(String2, "%d%d%d%d", 1) or mw.ustring.match(String2, "%d%d%d%d%-%d%d", 1) or mw.ustring.match(String2, "%d%d%d%d", 1) if isvalid(options.illwd2y) then return march_y or label end if isvalid(options.illwd2noy) and march_y then label = mw.ustring.gsub(label, march_y, "") return label end if isntvalid(formatch) then return label end local prepr = { ["lcfirst"] = "{{lcfirst: " .. label .. " }}", ["lc"] = "{{lc: " .. label .. " }}", ["uc"] = "{{uc: " .. label .. " }}" } if prepr[formatch] then return mw.getCurrentFrame():preprocess(prepr[formatch]) elseif formatch == "ucfirst" then return mw.language.getContentLanguage():ucfirst(label) elseif formatch == "formatnum" then return make_format_num(label) end return label end function descriptionIn(langcode, id) -- returns item description for a given language if isntvalid(langcode) then langcode = "ar" end langcode = mw.text.trim(langcode or "") id = mw.text.trim(id or "") if langcode == "ar" then local description, lange = mw.wikibase.getDescriptionWithLang(id) if lange == langcode then return description else return nil end else local entity = getEntityFromId(id) if entity and entity.descriptions then local description = entity.descriptions[langcode] if description and description.value then if description["language"] == langcode then return description.value end end end end return nil end function labelIn(langcode, id) -- returns item label for a given language if isntvalid(langcode) then langcode = "ar" end if type(id) ~= "string" then id = tostring(id) end langcode = mw.text.trim(langcode or "") id = mw.text.trim(id or "") local label = mw.wikibase.getLabelByLang(id, langcode) or nil return label end function get_snak_id(snak) if snak and snak.type and snak.type == "statement" and snak.mainsnak and snak.mainsnak.snaktype and snak.mainsnak.snaktype == "value" and snak.mainsnak.datavalue and snak.mainsnak.datavalue.type and snak.mainsnak.datavalue.type == "wikibase-entityid" and snak.mainsnak.datavalue.value and snak.mainsnak.datavalue.value.id then ID = snak.mainsnak.datavalue.value.id return ID 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 getDateArb(claim, sorting_properties) local sortingproperty = sorting_properties 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 for k, prop in pairs(sortingproperty) do local date = formatStatements({property = prop, entityId = item, firstvalue = "t", noref = "t", modifytime = "q"}) if isvalid(date) then --mw.log("item:".. item .. ", prop:".. prop .. ", date:".. date) return date end end end end function table_contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end function dontget(claims, options) --[[ options.dontget options.dontgetproperty ]] local claims2 = {} local dontget_values = mw.text.split(options.dontget, ",") for _, claim in pairs(claims) do local id = get_snak_id(claim) if id then local valid = true local t2 = formatStatements({property = (options.dontgetproperty or "P31"), entityId = id, noref = "t", raw = "t"}) if t2 and #t2 > 0 then for _, state in pairs(t2) do if table_contains(dontget_values, state.item) then valid = false break end end end if valid then table.insert(claims2, claim) end end end return claims2 end function getonly(claims, options) --[[ -- options.getonly -- options.getonlyproperty ]] local claims2 = {} local getonly_values = mw.text.split(options.getonly, ",") for _, claim in pairs(claims) do local id = get_snak_id(claim) if id then local t2 = formatStatements({property = (options.getonlyproperty or "P31"), entityId = id, noref = "t", raw = "t"}) if t2 and #t2 > 0 then for _, state in pairs(t2) do if table_contains(getonly_values, state.item) then table.insert(claims2, claim) break end end end end end return claims2 end function claimindex(claims, options) local claims2 = {} for j, index in pairs(mw.text.split(options.claimindex, ",")) do if tonumber(index) and #claims >= tonumber(index) then table.insert(claims2, claims[tonumber(index)]) end end return claims2 end function avoidvalue(claims, options) local avoidvalue = options.avoidvalue if type(avoidvalue) == "string" then avoidvalue = mw.text.split(avoidvalue, ",") elseif type(avoidvalue) ~= "table" then return claims end local claims4 = {} for i, j in pairs(claims) do local ID = get_snak_id(j) if ID and not table_contains(avoidvalue, ID) then table.insert(claims4, j) end end return claims4 end function prefervalue(claims, options) local prefervalue = options.prefervalue if type(prefervalue) == "string" then prefervalue = mw.text.split(prefervalue, ",") elseif type(prefervalue) ~= "table" then return claims end local claims3 = {} for _, claim in pairs(claims) do local ID = get_snak_id(claim) if ID and table_contains(prefervalue, ID) then table.insert(claims3, claim) end end return claims3 end function preferqualifier(claims, options) --[[ -- options.preferqualifier -- options.preferqualifiervalue ]] local claims2 = {} local preferq_values = mw.text.split(options.preferqualifiervalue or "", ",") for _, statement in pairs(claims) do if statement.qualifiers and statement.qualifiers[options.preferqualifier:upper()] then if isvalid(options.preferqualifiervalue) then for _, quall in pairs(statement.qualifiers[options.preferqualifier:upper()]) do if quall.snaktype == "value" and table_contains(preferq_values, quall.datavalue.value["id"]) then table.insert(claims2, statement) break end end else table.insert(claims2, statement) end end end return claims2 end function avoidqualifier(claims, options) -- options.avoidqualifier -- options.avoidqualifiervalue if isntvalid(options.avoidqualifier) then return claims end local av = options.avoidqualifier:upper() local avoidqualifiervalue_values = type(options.avoidqualifiervalue) == "string" and mw.text.split(options.avoidqualifiervalue, ",") or options.avoidqualifiervalue local claims2 = {} for _, statement in pairs(claims) do if not statement.qualifiers or not statement.qualifiers[av] then table.insert(claims2, statement) elseif isvalid(options.avoidqualifiervalue) then local active = true for _, quall in pairs(statement.qualifiers[av]) do if quall.snaktype == "value" and quall.datavalue and quall.datavalue.value and quall.datavalue.value["id"] and table_contains(avoidqualifiervalue_values, quall.datavalue.value["id"]) then active = false break end end if active then table.insert(claims2, statement) end end end return claims2 end function claims_limit(claims, limit) local newclaims = {} if type(limit) ~= "number" then limit = tonumber(limit) end if limit and type(limit) == "number" then if limit < 1 or #claims < limit then return claims end for i = 1, #claims do if i <= limit then newclaims[i] = claims[i] end end return newclaims end return claims end function claims_offset(claims, offset) local offsetclaims = {} if type(offset) ~= "number" then offset = tonumber(offset) end if offset and type(offset) == "number" then for i = offset + 1, #claims do offsetclaims[#offsetclaims + 1] = claims[i] end return offsetclaims end return claims end function sortbyarb(claims, sorting_properties, options) local sortingmethod = options.sortbyarbitrary or options.sortingmethod --mw.log("sortbyarb: " .. sortingmethod) table.sort( claims, function(a, b) local timeA = getDateArb(a, sorting_properties) local timeB = getDateArb(b, sorting_properties) if sortingmethod == "inverted" or sorting_methods[sortingmethod] == "inverted" then return comparedates(timeB, timeA) else return comparedates(timeA, timeB) end end ) return claims end function sort_langs(claims, options) local claims7 = {} local arabic_id = {["P407"] = 13955, ["P282"] = 8196} -- Q13955 = "العربية", Q8196 = "أبجدية عربية" for _, statement in pairs(claims) do for prop, id in pairs(arabic_id) do if statement.qualifiers and statement.qualifiers[prop] then for _, v in pairs(statement.qualifiers[prop]) do if v.snaktype == "value" and v.datavalue.value["numeric-id"] == id then table.insert(claims7, statement) break end end end end end if #claims7 > 0 then claims = claims7 end return claims end function sortbyqualifier(claims, sorting_properties, options) if not sorting_properties or #sorting_properties == 0 then sorting_properties = get_sorting_properties(options) end local sort_by = sorting_methods[options.sortbytime] or options.sortbytime table.sort( claims, function(a, b) local timeA = getqualifierbysortingproperty(a, sorting_properties) local timeB = getqualifierbysortingproperty(b, sorting_properties) if sort_by == "inverted" then return comparedates(timeB, timeA) else return comparedates(timeA, timeB) end end ) return claims end function sortbyqualifiernumber(claims, sorting_properties, options) if not sorting_properties or #sorting_properties == 0 then sorting_properties = get_sorting_properties(options) end local sort_by = sorting_methods[options.sortbynumber] or options.sortbynumber table.sort( claims, function(a, b) local timeA = getqualifierbysortingproperty(a, sorting_properties) local timeB = getqualifierbysortingproperty(b, sorting_properties) if sort_by == "inverted" then return comparedates(timeB, timeA) else return comparedates(timeA, timeB) end end ) return claims end function sort_claims(claims, options) local sortingmethod = options.sortbyarbitrary or options.sortingmethod local sorting_properties = get_sorting_properties(options) if isvalid(options.sortbytime) and sorting_methods[options.sortbytime] then if #sorting_properties == 0 then sorting_properties = sortingproperties end claims = sortbyqualifier(claims, sorting_properties, options) elseif isvalid(options.sortbynumber) and sorting_methods[options.sortbynumber] then claims = sortbyqualifiernumber(claims, sorting_properties, options) elseif isvalid(sortingmethod) and sorting_methods[sortingmethod] then claims = sortbyarb(claims, sorting_properties, options) end return claims end function filter_claims(claims, options) local claims = claims if isntvalid(options.langpref) then claims = sort_langs(claims, options) end claims = sort_claims(claims, options) local offset = options.offset if isvalid(offset) then claims = claims_offset(claims, offset) end local limit = options.limit if isvalid(limit) then claims = claims_limit(claims, limit) end if isvalid(options.avoidqualifier) then -- to avoid value with a given qualifier claims = avoidqualifier(claims, options) end if isvalid(options.preferqualifier) then claims = preferqualifier(claims, options) end -- options.avoidvalue if isvalid(options.avoidvalue) then claims = avoidvalue(claims, options) end -- options.prefervalue if isvalid(options.prefervalue) then claims = prefervalue(claims, options) end -- options.getonly if isvalid(options.getonly) then claims = getonly(claims, options) end -- options.dontget if isvalid(options.dontget) then claims = dontget(claims, options) end local firstvalue = options.enbarten or options.firstvalue local first = isvalid(tonumber(firstvalue)) if isvalid(first) and #claims > 1 then if #claims > 0 then first = tonumber(first) or 1 if first > 0 and first <= #claims then claims = {claims[first]} else claims = {claims[1]} end end elseif isvalid(firstvalue) and #claims > 0 then claims = {claims[1]} end local numval = options.numval if numval and type(numval) ~= "number" then numval = tonumber(numval) end if numval and type(numval) == "number" and #claims > 1 and #claims > numval then local claimsnumval = {} local ic = 1 while (numval >= ic) and (#claims >= ic) do table.insert(claimsnumval, claims[ic]) ic = ic + 1 end claims = claimsnumval end return claims end function getEntityFromId(id) return isvalid(id) and mw.wikibase.getEntityObject(id) or mw.wikibase.getEntityObject() end function formatError(key) return i18n.errors[key] end function formatOneStatement(statement, ref, options) local value = nil local stat = formatStatement(statement, options) if not stat then return {v = value, raw = stat} end local s = stat.value if isntvalid(s) then return {v = value, raw = stat} end if not stat.qualifiers then stat.qualifiers = {} end local P585 = stat.P585 or "" local tf = stat.tifr local awardqual = stat.foto 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 reff = stat.reff if reff and isvalid(options.reff) then s = s .. reff end if isvalid(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, entityId = options.entityId, v1 = options.v1, id = stat.ID } } end if isvalid(options.football) then s = mw.getCurrentFrame():expandTemplate { title = "صندوق معلومات سيرة كرة قدم/سطر فريق", args = { stat.qualifiers.P580 or "", stat.qualifiers.P582 or "", s, stat.amatch, stat.goal } } end if isvalid(options.office) then s = mw.getCurrentFrame():expandTemplate { title = "معلومات صاحب منصب/منصب ويكي بيانات/نواة", args = { office = s, termstart = stat.qualifiers.P580 or "", termend = stat.qualifiers.P582 or "", constituency = stat.qualifiers.P768 or "", predecessor = stat.qualifiers.P1365 or "", successor = stat.qualifiers.P1366 or "", series = stat.qualifiers.P1545 or "", of = stat.qualifiers.P642 or "", electedin = stat.qualifiers.P2715 or "", jurisdiction = stat.qualifiers.P1001 or "", employer = stat.qualifiers.P108 or "", entityId = options.entityId } } end local function qoo(Prefix, qualpref, p, Suffix) if isvalid(p) then local stri = (Prefix or " (") .. (qualpref or "") .. p .. (Suffix or ")") if isvalid(options.nosmall) then return stri else return mw.text.tag("small", {}, stri) end end end local QPrefix = isvalid(options.qualifierprefix) local QSuffix = isvalid(options.qualifiersuffix) if isvalid(qp1) and isvalid(options.qual1) and isvalid(qp1a) and isvalid(options.qual1a) then s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix) elseif isvalid(qp1) and isvalid(options.qual1) then s = s .. qoo(QPrefix, options.qual1pref, qp1, QSuffix) elseif isvalid(qp1a) and isvalid(options.qual1a) then s = s .. qoo(QPrefix, options.qp1apref, qp1a, QSuffix) end if isvalid(qp2) and isvalid(options.qual2) then s = s .. qoo(QPrefix, options.qual2pref, qp2, QSuffix) end if isvalid(qp3) and isvalid(options.qual3) then s = s .. qoo(QPrefix, options.qual3pref, qp3, QSuffix) end if isvalid(qp4) and isvalid(options.qual4) then s = s .. qoo(QPrefix, options.qual4pref, qp4, QSuffix) end if isvalid(qp5) and isvalid(options.qual5) then s = s .. qoo(QPrefix, options.qual5pref, qp5, QSuffix) end if isvalid(options.justthisqual) then if onlyqualifier then s = onlyqualifier else s = nil -- We need only the qualifier end end if isvalid(ro) and isvalid(options.withro) then s = s .. qoo(QPrefix, "", ro, QSuffix) end if isvalid(P585) and isvalid(options.withdate) then if options.withdate == "y" then s = s .. qoo(QPrefix, "سنة ", P585, QSuffix) elseif options.withdate == "before" then s = "*" .. P585 .. ":" .. s .. "\n" else s = s .. qoo(QPrefix, "", P585, QSuffix) end end if awardqual and isvalid(options.awardqua) then s = s .. qoo(QPrefix, "", awardqual, QSuffix) end local bothdates = options.withintervall or options.bothdates if tf and isvalid(bothdates) then if bothdates == "line" then s = s .. mw.text.tag("br") .. qoo(QPrefix, "", tf, QSuffix) elseif bothdates == "before" then s = qoo(QPrefix, "", tf, QSuffix) .. s else s = s .. qoo(QPrefix, "", tf, QSuffix) end end if type(ref) == "table" or (isvalid(options.noref)) or (isvalid(options.justthisqual)) then value = s else local t = formatReferences(statement, options) stat.ref = t if isvalid(options.justref) then value = t elseif isvalid(options.onlyvaluewithref) then if isvalid(t) then value = s .. t end else value = s .. t end end return {v = value, raw = stat} end function formatStatements(options, LuaClaims) local valuetable = {} -- formattedStatements local claims = {} if isntvalid(options.property) and isvalid(options.pid) then options.property = options.pid end if isntvalid(options.property) then return formatError("property-param-not-provided") end local option1 = options.option1 if option1 and options.option1value then options[option1] = options.option1value options['"' .. option1 .. '"'] = options.option1value --mw.log( "option1: " .. option1 .. "value: " .. options.option1value ) end if type(LuaClaims) == "table" then claims = LuaClaims[options.property] or {} mw.log("module:wikidata2: claims = LuaClaims[options.property]") else --Get entity local entity = nil if options.entity and type(options.entity) == "table" then entity = options.entity else local id = get_entityId(options) if isvalid(id) then local check = mw.ustring.match(id, "Q%d+") or mw.ustring.match(id, "P%d+") if check == nil then mw.addWarning(id .. " لا يمثل معرف ويكي بيانات صحيح") return "" else options.entityId = id options.qid = id end end entity = getEntityFromId(id) end --local property = mw.wikibase.resolvePropertyId( options.property:upper() ) local property = options.property:upper() if not entity then return "" end --TODO error? if not entity.claims or not entity.claims[property] then if isvalid(options.otherproperty) then options.property = options.otherproperty property = options.otherproperty:upper() end end if property == nil then return "" end if not entity.claims or not entity.claims[property] then return "" --TODO error? end --Format statement and concat them cleanly if options.rank == "best" or isntvalid(options.rank) then --claims = entity:getAllStatements( property ) claims = entity:getBestStatements(property) elseif options.rank == "valid" then for i, statement in pairs(entity.claims[property]) 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[property]) do table.insert(claims, statement) end else for i, statement in pairs(entity.claims[property]) do if statement.rank == options.rank then table.insert(claims, statement) end end end end claims = filter_claims(claims, options) local statementsraw = {} local All_claims = claims 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, LuaClaims, options) if va.v then table.insert(valuetable, va.v) end table.insert(statementsraw, va.raw) end end end if isvalid(options.raw) then if isvalid(options.rawtolua) then return mw.getCurrentFrame():extensionTag("source", mw.dumpObject(statementsraw), {lang = "lua"}) end return statementsraw end local priff = "" local Separator = options.separator -- or "" local Conjunction = options.conjunction -- or "" if Separator == "br" or Conjunction == "br" then Separator = mw.text.tag("br") end if Separator == "*" then priff = "\n*" Separator = "\n*" end if Separator == "#" then priff = "\n#" Separator = "\n#" end if isvalid(options.justref) then priff = "" Separator = "" end local tot = mw.text.listToText(valuetable, Separator, Separator) if #valuetable > 1 then tot = priff .. tot end if isntvalid(tot) then tot = nil end if isvalid(options.returnnumberofvalues) or options.returnnumberofvalues == true then return tot, #valuetable end if isvalid(options.numberofclaims) then return #All_claims end return tot end function p.formatAndCat(args) if args == nil then return nil end Frame_args = args args.linkback = args.linkback or true args.addcat = true if isvalid(args.value) and args.value == "-" then return nil end if isvalid(args.value) then local val = args.value .. addTrackingCategory(args) val = p.addLinkBack(val, args.entity, args.property) return val end return p.formatStatementsFromLua(args) end function formatReferences(statement, options) local ic = 1 local reference = {} local numberofref = tonumber(options.numberofreferences) or 7 local qid = get_entityId(options) local statementreferences = statement.references if statementreferences then if Modulecite == nil then Modulecite = require(citetitle) end for i, ref in ipairs(statementreferences) do if ref.snaks and numberofref >= ic then local s = Modulecite._cite_wikidata(ref, qid) if isvalid(s) then ic = ic + 1 table.insert(reference, s) end end end end local final = table.concat(reference) if isvalid(final) then final = final .. i18n.cateref end return final or "" end function formatqualifiers(statement, s, options) s.qualifiers = {} local function qua(p, firstvalue, modifytime) local vvv if isvalid(p) then vvv = formatStatements( { property = p, enlabelcate = "t", firstvalue = (firstvalue or ""), modifytime = (modifytime or "longdate"), noref = "t" }, statement.qualifiers ) or "" s.qualifiers[p] = vvv return vvv end end if isvalid(options.template) then s.ID = statement.mainsnak.datavalue.value.id 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 isvalid(options.football) then if statement.qualifiers.P1350 or statement.qualifiers.P1351 then s.amatch = qua("P1350", "true") s.goal = qua("P1351", "true") end end if (isvalid(options.football)) or (isvalid(options.office)) then s.start1 = qua("P580", "true") s.finish1 = qua("P582", "true") end if isvalid(options.office) then if statement.qualifiers.P580 or statement.qualifiers.P582 or statement.qualifiers.P1365 or statement.qualifiers.P1366 then 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 end if isvalid(options.withdate) then --if statement.qualifiers.P585 then s.P585 = qua("P585", "true", options.modifyqualifiertime) end local qwe = options.qwer if statement.qualifiers.qwe then s.ro = qua(qwe, "true") end local bothdates_option = options.withintervall or options.bothdates if isvalid(bothdates_option) then 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 isvalid(options.awardqua) then 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 end local function quaaal(opti, options) if isvalid(opti) and statement.qualifiers[opti] then local kkk = formatStatements( { property = opti, noref = "t", 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 "" s.qualifiers[opti] = kkk return kkk end end if isvalid(options.justthisqual) and statement.qualifiers[options.justthisqual] then s.onlyqualifier = quaaal(options.justthisqual, options) end if isvalid(options.qual1) and statement.qualifiers[options.qual1] then s.qp1 = quaaal(options.qual1, options) end if isvalid(options.qual1a) and statement.qualifiers[options.qual1a] then s.qp1a = quaaal(options.qual1a, options) end if isvalid(options.qual2) and statement.qualifiers[options.qual2] then s.qp2 = quaaal(options.qual2, options) end if isvalid(options.qual3) and statement.qualifiers[options.qual3] then s.qp3 = quaaal(options.qual3, options) end if isvalid(options.qual4) and statement.qualifiers[options.qual4] then s.qp4 = quaaal(options.qual4, options) end if isvalid(options.qual5) and statement.qualifiers[options.qual5] then s.qp5 = quaaal(options.qual5, options) end end function formatSnak(snak, options) if snak.snaktype == "somevalue" then local somevalue = options.somevalue or i18n["somevalue"] return {value = somevalue} elseif snak.snaktype == "novalue" then local novalue = options.novalue or i18n["novalue"] return {value = novalue} elseif snak.snaktype == "value" then local s = formatDatavalue(snak.datavalue, snak.datatype, options) if s and s.value and isvalid(s.value) then s.value = (options.prefix or "") .. s.value .. (options.suffix or "") end return s else return {value = formatError("unknown-snak-type")} 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 formatter == nil then return {value = formatError("claim-module-not-found")} end local fun = formatter[options["claim-function"]] if fun == nil 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 isvalid(s) then s.qualifiers = {} if statement.qualifiers then local qualu = formatqualifiers(statement, s, options) --if isvalid(qualu) then table.insert(qualu) end end if statement.references then if isvalid(options.reff) then s.reff = formatReferences(statement, options) end end end return s elseif not statement.type then return formatSnak(statement, options) end return {value = formatError("unknown-claim-type")} end function get_property1(options, item) --[[ function to get countries flags without reload large countries items ]] local flagprop = {"p27", "p1532", "p17", "p495", "p1376"} local work_flag = false if string.lower(options.property1) == "p41" then for k, l in pairs(flagprop) do if string.lower(options.property) == l then work_flag = true end end end local caca = "" local size = options.size or "" if isntvalid(size) then size = "20" end if work_flag then if Moduleflags == nil then Moduleflags = require("Module:Wikidata2/Flags") end local flag = Moduleflags[item] if isntvalid(flag) then flag = formatStatements( { property = options.property1, otherproperty = options.otherproperty1, entityId = item, rank = options.property1rank, pattern = options.property1pattern, formatting = options.property1formatting, noref = "t", firstvalue = "t" } ) --mw.log("get flag2 :" .. flag .. ", for item ".. item ) end if isvalid(flag) then -- return real image if isvalid(options.image) then -- return real image caca = "[[file:" .. flag .. "|" .. size .. "px|" .. "border" .. "]]" --caca = Infobox_Image( {image=flag, size=size, maxsize = "280x330px", center=options.center} ) --mw.log("get flag :" .. flag .. ", for item ".. item ) end end end if isntvalid(caca) then caca =