Module:WikidataCheck: Difference between revisions

From Random Island Wiki
Jump to navigation Jump to search
>Happy5214
(Should be done)
>Happy5214
m (Forgot category syntax)
Line 13: Line 13:
     local hasProp = entity.claims[property]
     local hasProp = entity.claims[property]
     if not hasProp then
     if not hasProp then
         return "[[" .. catbase .. " not in Wikidata]]"
         return "[[Category:" .. catbase .. " not in Wikidata]]"
     end
     end
     local propValue = hasProp[0].mainsnak.datavalue.value
     local propValue = hasProp[0].mainsnak.datavalue.value
     if propValue == value then
     if propValue == value then
         return "[[" .. catbase .. " same as Wikidata]]"
         return "[[Category:" .. catbase .. " same as Wikidata]]"
     else
     else
         return "[[" .. catbase .. " different from Wikidata]]"
         return "[[Category:" .. catbase .. " different from Wikidata]]"
     end
     end
end
end


return p
return p

Revision as of 05:49, 28 April 2013

Documentation for this module may be created at Module:WikidataCheck/doc

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
    local catbase = config.category
    
    local entity = mw.wikibase.getEntity()
    local hasProp = entity.claims[property]
    if not hasProp then
        return "[[Category:" .. catbase .. " not in Wikidata]]"
    end
    local propValue = hasProp[0].mainsnak.datavalue.value
    if propValue == value then
        return "[[Category:" .. catbase .. " same as Wikidata]]"
    else
        return "[[Category:" .. catbase .. " different from Wikidata]]"
    end
end

return p