Module:Multiple releases/sandbox: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 105: | Line 105: | ||
end |
end |
||
--- Returns a subbox Infobox with an infobox row for a programming language release or an empty string. |
|||
--- Creates an infobox row with a the label and either a version number or a version number and date value for a single row. |
|||
--- Returns the total number of rows created. |
|||
--- |
--- |
||
⚫ | |||
--- Valid version types are listed at the version_types table at the top. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
--- Infobox parameters used: |
|||
--- @param isDiscontinued string |
|||
---- |discontinued= |
|||
--- @return number |
|||
⚫ | |||
--- |
|||
--- Testing parameters used: |
|||
---- |language= |
|||
--- |
|||
⚫ | |||
⚫ | |||
local function _language(args) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local version_type = version_types[args.version_type] |
|||
⚫ | |||
return "" |
|||
⚫ | |||
local software_id = args.language or "" |
|||
local infobox_args = {subbox = "yes"} |
|||
local label = "" |
local label = "" |
||
if version_type == version_types.stable then |
if version_type == version_types.stable then |
||
if |
if isDiscontinued then |
||
label = "[[Software release life cycle|Final release]]" |
label = "[[Software release life cycle|Final release]]" |
||
else |
else |
||
Line 141: | Line 125: | ||
label = "[[Software release life cycle#BETA|Preview release]]" |
label = "[[Software release life cycle#BETA|Preview release]]" |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
--- Creates one or more infobox rows with a the label and either a version number or a version number and date value for a single row. |
|||
⚫ | |||
--- Returns the total number of rows created. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
--- @param requested_platforms string |
|||
--- @param version_type string |
|||
--- @return number |
|||
local function get_multiple_rows(infobox_args, software_id, requested_platforms, version_type) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if number_of_results == 0 then |
|||
⚫ | |||
return "" |
|||
⚫ | |||
⚫ | |||
row_number = get_infobox_row(infobox_args, software_id, platform_id, version_type, true, row_number, platforms[platform].label) |
|||
end |
end |
||
return row_number |
|||
local infobox = require('Module:Infobox').infobox |
|||
⚫ | |||
end |
end |
||
Line 155: | Line 161: | ||
--- |
--- |
||
--- The list of platforms is a comma separated list. Valid platforms are listed in the platforms table at the top. |
--- 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. |
--- Valid version types are listed at the version_types table at the top. |
||
--- |
--- |
||
--- Infobox parameters used: |
--- Infobox parameters used: |
||
---- | |
---- |discontinued= |
||
---- |platforms= |
---- |platforms= |
||
---- |version_type= |
|||
--- |
--- |
||
--- Testing parameters used: |
--- Testing parameters used: |
||
Line 166: | Line 174: | ||
--- @param args table |
--- @param args table |
||
--- @return string |
--- @return string |
||
local function |
local function _main(args) |
||
if not args.version_type |
if not args.version_type then |
||
return "" |
return "" |
||
end |
end |
||
Line 175: | Line 183: | ||
return "" |
return "" |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
local software_id = args.software or "" |
local software_id = args.software or "" |
||
local infobox_args = {subbox = "yes"} |
local infobox_args = {subbox = "yes"} |
||
⚫ | |||
local row_number |
|||
⚫ | |||
⚫ | |||
⚫ | |||
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 |
end |
||
Line 198: | Line 200: | ||
local infobox = require('Module:Infobox').infobox |
local infobox = require('Module:Infobox').infobox |
||
return infobox(infobox_args) |
return infobox(infobox_args) |
||
end |
|||
--- Returns a subbox Infobox with an infobox row for a programming language release or an empty string. |
|||
--- |
|||
⚫ | |||
⚫ | |||
function p.language(frame) |
|||
local getArgs = require('Module:Arguments').getArgs |
|||
local args = getArgs(frame) |
|||
return _language(args) |
|||
end |
end |
||
Line 214: | Line 206: | ||
--- @param frame table |
--- @param frame table |
||
--- @return string |
--- @return string |
||
function p. |
function p.main(frame) |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
return |
return _main(args) |
||
end |
end |
||
Revision as of 11:42, 23 December 2021
![]() | This is the module sandbox page for Module:Multiple releases (diff). See also the companion subpage for test cases (run). |
Implements {{Multiple releases}}
local p = {}
local wikidata = require('Module:Wd')
local properties = {
platform = "P400",
publication_date = "P577",
software_version_identifier = "P348",
version_type = "P548",
}
local version_types = {
pre_release = "Q51930650",
stable = "Q2804309",
}
local platforms = {
android = {id = "Q94", label = "[[Android (operating system)|Android]]"},
ios = {id = "Q48493", label = "[[iOS]]"},
linux = {id = "Q388", label = "[[Linux]]"},
macos = {id = "Q14116", label = "[[macOS]]"},
windows = {id = "Q1406", label = "[[Microsoft Windows|Windows]]"},
web = {id = "Q6368", label = "[[Web application|Web]]"},
}
--- Returns a date formatted with the {{Start date and age}} template.
---
--- @param date string
--- @return string
local function get_formatted_date(date)
local formatted_date = mw.getCurrentFrame():expandTemplate{title = "Start date and age", args = {date}}
return formatted_date
end
--- Returns a Wikidata qualifier request for the date.
--- @param args []
--- @return string
local function get_wikidata_date(args)
local wikidata_args = mw.clone(args)
table.insert(wikidata_args, properties.publication_date)
local result = wikidata._qualifier(wikidata_args)
return result
end
--- Returns a Wikidata property request for the version number.
---
--- @param args []
--- @return string
local function get_wikidata_version(args)
local wikidata_args = mw.clone(args)
table.insert(wikidata_args, 1, "reference")
table.insert(wikidata_args, 2, "edit")
local result = wikidata._property(wikidata_args)
return result
end
--- Returns an entity for Wikidata.
---
--- @param software string
--- @param platform string
--- @param version_type string
--- @param use_platform boolean
--- @return table
local function get_wikidata_args(software, platform, version_type, use_platform)
local args = {
software,
properties.software_version_identifier,
[properties.version_type] = version_type,
}
if use_platform then
args[properties.platform] = platform
end
return args
end
--- Creates an infobox row with a 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 number
local 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_number
end
--- Creates an infobox row with a the label and either a version number or a version number and date value for a single row.
--- Returns the total number of rows created.
---
--- @param infobox_args table
--- @param software_id string
--- @param version_type string
--- @param isDiscontinued string
--- @return number
local function get_single_row(infobox_args, software_id, version_type, isDiscontinued)
local label = ""
if version_type == version_types.stable then
if isDiscontinued then
label = "[[Software release life cycle|Final release]]"
else
label = "[[Software release life cycle|Stable release]]"
end
elseif version_type == version_types.pre_release then
label = "[[Software release life cycle#BETA|Preview release]]"
end
local x = get_infobox_row(infobox_args, software_id, nil, version_type, false, 0, label)
mw.logObject(infobox_args)
return x
end
--- Creates one or more infobox rows with a the label and either a version number or a version number and date value for a single row.
--- Returns the total number of rows created.
---
--- @param infobox_args table
--- @param software_id string
--- @param requested_platforms string
--- @param version_type string
--- @return number
local 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_number
end
--- Returns a subbox 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 string
local 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 = {subbox = "yes"}
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 string
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return _main(args)
end
return p