For faster navigation, this Iframe is preloading the Wikiwand page for 模組:WikidataCheck/sandbox.

模組:WikidataCheck/sandbox

文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

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
{{bottomLinkPreText}} {{bottomLinkText}}
模組:WikidataCheck/sandbox
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?