模組:WikidataCheck
外觀
![]() | 此模組被引用於約63,000個頁面。 為了避免造成大規模的影響,所有對此模組的編輯應先於沙盒或測試樣例上測試。 測試後無誤的版本可以一次性地加入此模組中,但是修改前請務必於討論頁發起討論。 模板引用數量會自動更新。 |
![]() | 此模組使用Lua語言: |
相關頁面 |
---|
Template:WikidataCheck模板允許您比較一個模板參數與維基數據中的一個屬性。它的核心代碼是Lua模塊Module:WikidataCheck。
調用方式:{{WikidataCheck|property=P###|value={{{value|}}}|category=分类填入名|namespaces=0,14}}
- 必填參數
|property=
是屬性的P###編號。「P」必須大寫。|value=
是所用的模板的值。例如{{{id|}}}
|category=
是有關追蹤分類中使用的名稱。分類如「不在維基數據的[名稱]」、「與維基數據相同的[名稱]」、「與維基數據不同的[名稱]」。- 推薦您在應用此模板前用
{{hiddencat}}
創建這些分類。
- 推薦您在應用此模板前用
- 選填參數
|namespaces=
是該模板要適用的逗號分隔的命名空間編號列表。默認為0,即僅適用於條目。|nocatsame=
如果有設值,會防止"相同"分類被創建。"不同"和"不在"的分類還是被創建。|qid=
如果有設值,將查考其他維基數據條目。
- 示例
以{{Sinaweibo}}
為例,所添加的代碼為:
{{WikidataCheck|property=P3579|value={{{1|{{{id|}}}}}}|category=新浪微博用戶名}}
另見
local p = {}
function p.wikidatacheck(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local property = config.property
local value = config.value or ""
local catbase = config.category
local namespaces = config.namespaces
local nocatsame = config.nocatsame or ""
local qid = config.qid or ""
local ok = false -- one-way flag to check if we're in a good namespace
local ns = mw.title.getCurrentTitle().namespace
for v in mw.text.gsplit( namespaces, ",", true) do
if tonumber(v) == ns then
ok = true
end
end
if not ok then -- not in one of the approved namespaces
return ""
end
local entity
if qid == "" then
entity = mw.wikibase.getEntityObject()
else
entity = mw.wikibase.getEntityObject(qid)
end
if not entity then -- no Wikidata item (根本找不到对应的维基数据页)
return "[[Category:不在維基數據的" .. catbase .. "]]"
end
if value == "" then
return nil -- Using Wikidata (检索维基数据页)
end
local claims = entity.claims or {}
local hasProp = claims[property]
if not hasProp then -- no claim of that property (在维基数据页的各条信息项都中没有对应的信息)
return "[[Category:不在維基數據的" .. catbase .. "]]" -- bad. Bot needs to add the property (这不是好事,但可以由机器人完成对应项的添加)
end
for i, v in ipairs(hasProp) do -- Now we try to iterate over all possible values? (将要检查的模板参数与多条信息记录逐个取值比对)
propValue = (v.mainsnak.datavalue or {}).value
if propValue == value then
if nocatsame == "" then
return "[[Category:與維基數據相同的" .. catbase .. "]]" -- yay! (这是好结果,表示调用模板时填写的信息参数和wikidata中填写的信息能对得上号,万事大吉)
else
return nil -- if nocatsame, the "same as" category is not added (如果有nocatsame参数,不加入“相同”分类)
end
end
end
return "[[Category:與維基數據不同的" .. catbase .. "]]" -- needs human review :( (此结果表示虽然wikidata中有对应的信息项,但是与调用模板时填写的参数不匹配,需要人工查证)
end
return p