Module:Multiple releases/sandbox explained

local p =

local wikidata = require("Module:Wd")

local properties =

local version_types =

local platforms =

local labels =

local date_template = "Start date and age"

--- Returns a date formatted with the template.------ @param date string--- @return stringlocal function get_formatted_date(date) local formatted_date = mw.getCurrentFrame:expandTemplate return formatted_dateend

--- Returns a Wikidata qualifier request for the date.--- @param args []--- @return stringlocal function get_wikidata_date(args) local wikidata_args = mw.clone(args) table.insert(wikidata_args, 1, "single") table.insert(wikidata_args, properties.publication_date) local result = wikidata._qualifier(wikidata_args) return resultend

--- Returns a Wikidata property request for the version number.------ @param args []--- @return stringlocal function get_wikidata_version(args) local wikidata_args = mw.clone(args) table.insert(wikidata_args, 1, "references") table.insert(wikidata_args, 2, "preferred") table.insert(wikidata_args, 3, "sourced") table.insert(wikidata_args, 4, "edit") local result = wikidata._property(wikidata_args) return resultend

--- Returns an entity for Wikidata.------ @param software string--- @param platform string--- @param version_type string--- @param use_platform boolean--- @return tablelocal function get_wikidata_args(software, platform, version_type, use_platform) local args =

if use_platform then args[properties.platform] = platform end

return argsend

--- Creates an infobox row with the label and either a version number or a version number and date value.--- Returns the number of the next infobox row.------ @param infobox_args table--- @param software_id string--- @param platform_id string--- @param version_type string--- @param use_platform boolean--- @param row_number number--- @param label string--- @return numberlocal function get_infobox_row(infobox_args, software_id, platform_id, version_type, use_platform, row_number, label) local wikidata_args = get_wikidata_args(software_id, platform_id, version_type, use_platform) local version = get_wikidata_version(wikidata_args) if version and version ~= "" then row_number = row_number + 1 infobox_args["label" .. row_number] = label local date = get_wikidata_date(wikidata_args) if date and date ~= "" then date = get_formatted_date(date) infobox_args["data" .. row_number] = version .. " / " .. date else infobox_args["data" .. row_number] = version end end

return row_numberend

--- Creates an infobox row.--- A row consists of a label of the version type and a data value of either a version number or a version number and date value.--- Returns the total number of rows created.------ @param infobox_args table--- @param software_id string--- @param version_type string--- @param isDiscontinued string--- @return numberlocal function get_single_row(infobox_args, software_id, version_type, isDiscontinued) local label = "" if version_type

version_types.stable then if isDiscontinued then label = labels.final else label = labels.stable end elseif version_type

version_types.pre_release then label = labels.beta end

return get_infobox_row(infobox_args, software_id, nil, version_type, false, 0, label)end

--- Creates one or more infobox rows.--- A row consists of a label of the platform name and a data value of either a version number or a version number and date value.--- Returns the total number of rows created.------ @param infobox_args table--- @param software_id string--- @param requested_platforms string--- @param version_type string--- @return numberlocal function get_multiple_rows(infobox_args, software_id, requested_platforms, version_type) ---@type table local used_platforms = for platform in string.gmatch(requested_platforms, "[^,]+") do used_platforms[platform] = true end

local ordered_pairs = require("Module:Ordered pairs").orderedPairs local row_number = 0 for platform, _ in ordered_pairs(used_platforms) do local platform_id = platforms[platform].id row_number = get_infobox_row(infobox_args, software_id, platform_id, version_type, true, row_number, platforms[platform].label) end

return row_numberend

--- Returns a child Infobox with one or more infobox rows for a software release or an empty string.------ The list of platforms is a comma separated list. Valid platforms are listed in the platforms table at the top.--- If args.platforms is empty then only the latest release is returned.--- Valid version types are listed at the version_types table at the top.------ Infobox parameters used:---- |discontinued=---- |platforms=---- |version_type=------ Testing parameters used:---- |software=------ @param args table--- @return stringlocal function _main(args) if not args.version_type then return "" end

local version_type = version_types[args.version_type] if not version_type then return "" end

local software_id = args.software or "" local infobox_args =

local row_number if args.platforms then row_number = get_multiple_rows(infobox_args, software_id, args.platforms, version_type) else row_number = get_single_row(infobox_args, software_id, version_type, args.discontinued) end

if row_number

0 then return "" end

local infobox = require("Module:Infobox").infobox return infobox(infobox_args)end

--- Returns a subbox Infobox with one or more infobox rows for a software release or an empty string.------ @param frame table--- @return stringfunction p.main(frame) local getArgs = require("Module:Arguments").getArgs local args = getArgs(frame) return _main(args)end

return p