Module:WikiProjectBanner/data export

< Module:WikiProjectBanner
Revision as of 07:59, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:WikiProjectBanner/data export/doc

local export = {}

local schema_array = { [0]    = true; };
local schema_map   = { [true] = true; };

local schema_scale = {
	_REDIRECT = schema_map;
	[true]    = schema_array;
}

local schema_config = {
	importance_scale = schema_scale;
	quality_scale    = schema_scale;
	
	task_forces = {
		[0] = {
			force = true;
			icon  = true;
			link  = true;
			-- TODO
		};
	};

	notices = {
		[0] = {
			icon  = true;
			text  = true;
			link  = true;
			-- TODO
		};
	};
}

function export.export_data(frame)
	local m_json = require("Module:microJSON")
	local output = {}

	for _, banner_name in ipairs(frame.args) do
		if banner_name ~= "" then
			local data = maybe_load_data("Module:WikiProjectBanner/config/" .. banner_name)
			if data then
				output[#output + 1] = m_json.encode_str(banner_name) .. ":" .. m_json.encode_object(data, schema)
			end
		else
			-- TODO: not sure what will be put there. version info?
		end
	end

	return "{" .. table.concat(output, ",") .. "}"
end

return export