Module:SDC tracking/sandbox

--[[   __  __           _       _        ____  ____   ____    _                  _    _              |  \/  | ___   __| |_   _| | ___ _/ ___||  _ \ / ___|  | |_ _ __ __ _  ___| | _(_)_ __   __ _  | |\/| |/ _ \ / _` | | | | |/ _ (_)___ \| | | | |      | __| '__/ _` |/ __| |/ / | '_ \ / _` | | |  | | (_) | (_| | |_| | |  __/_ ___) | |_| | |___   | |_| | | (_| | (__|   <| | | | | (_| | |_|  |_|\___/ \__,_|\__,_|_|\___(_)____/|____/ \____|___\__|_|  \__,_|\___|_|\_\_|_| |_|\__, |                                                    |_____|                              |___/ This module is intended to be the engine behind "Template:SDC_tracking".

Please do not modify this code without applying the changes first at "Module:SDC_tracking/sandbox" and testing at "Module:SDC_tracking/testcases".

Authors and maintainers: ]]
 * User:Jarekt - original version

-- ================================================== -- === local functions =========================== -- ==================================================

-- -- Based on frame structure create "args" table with all the input parameters. -- All inputs are not not case-sensitive and underscored are treated the same -- way as speces. Input values are trimmed and empty string are converted to -- nils. If "lang" is not provided than we substitute user's prefered language. function getArgs(frame) local function normalize_input_args(input_args, output_args) for name, value in pairs( input_args ) do 			if value ~= '' then -- nuke empty strings name = string.gsub( string.lower(name), ' ', '_') output_args[name] = value end end return output_args end local args = {} args = normalize_input_args(frame:getParent.args, args) args = normalize_input_args(frame.args, args) return args end

local function Category(catName) if catName then return '' else return '' end end

-- ================================================== -- === external functions =========================== -- ==================================================

local p = {}

function p.SDC_statement_exist(frame) local args = getArgs(frame) -- skip if we are not in file namespace local page = mw.title.getCurrentTitle if page.namespace~=(args.namespace or 6) then return '' end -- check if statement exist local entity = mw.wikibase.getEntity if entity and entity.statements and entity.statements[args.property] then return Category(args.positive_category) else return Category(args.negative_category) end end

--- function p.SDC_statement_has_value (frame) local args = getArgs(frame) -- skip if we are not in the right namespace -- original intention of this function was to work only on SDC -- statements (in namespace 6), however it seems like we can also -- use it in other namespaces with Wikidata statements local page = mw.title.getCurrentTitle if (page.namespace~=(args.namespace or 6)) or (not args.value) then return end -- check if statement exist local entity = mw.wikibase.getEntity if entity and entity.statements and entity.statements[args.property] then for _, statement in pairs( entity:getBestStatements( args.property )) do			if (statement.mainsnak.snaktype == "value") then local val = statement.mainsnak.datavalue.value if val.id then val = val.id				elseif val.text then val = val.text end if val==args.value then return Category(args.matching_category) end end end return Category(args.mismatching_category) else return Category(args.missing_category) end end

return p