Line 2: |
Line 2: |
| local private = {} | | local private = {} |
| | | |
− | --########## | + | -- whether to handle Stardew Valley beta fields (don't forget to comment or uncomment the beta fields in /doc) |
− | --## Constants
| + | local enableBeta = false |
− | --##########
| |
− | -- The valid status values.
| |
− | local statuses = { | |
− | ok = "ok",
| |
− | optional = "optional",
| |
− | unofficial = "unofficial",
| |
− | workaround = "workaround",
| |
− | broken = "broken",
| |
− | abandoned = "abandoned",
| |
− | obsolete = "obsolete"
| |
− | }
| |
− | | |
| | | |
| --########## | | --########## |
Line 21: |
Line 9: |
| --########## | | --########## |
| -- Start a SMAPI compatibility table. | | -- Start a SMAPI compatibility table. |
− | -- @test mw.log(p.header()) | + | -- @test mw.log(p.header({})) |
− | function p.header() | + | function p.header(frame) |
− | local row = mw.html.create("tr") | + | return |
− | row:node(mw.html.create("th"):wikitext("mod name"))
| + | private.style(frame) |
− | row:node(mw.html.create("th"):wikitext("author"))
| + | .. '<table class="wikitable sortable plainlinks" id="mod-list">' |
− | row:node(mw.html.create("th"):wikitext("compatibility"))
| + | .. "<tr><th>mod name</th><th>author</th><th><abbr title=\"This only shows whether a mod is *compatible*; it may have bugs unrelated to SMAPI compatibility.\">compatibility</abbr></th><th>broke in</th><th>source</th><th> </th></tr>"; |
− | row:node(mw.html.create("th"):wikitext("broke in"))
| |
− | row:node(mw.html.create("th"):wikitext("source"))
| |
− | row:node(mw.html.create("th"):wikitext(" "))
| |
− | | |
− | return '<table class="wikitable plainlinks">' .. tostring(row)
| |
| end | | end |
| | | |
Line 38: |
Line 21: |
| function p.footer() | | function p.footer() |
| return '</table>' | | return '</table>' |
| + | end |
| + | |
| + | --- Render the SMAPI compatibility table based on JSON input. |
| + | -- @param frame The arguments passed to the script. |
| + | -- @test mw.log(p.table({ args = { [1]='[ { "name": "24h Clock", "author": "Lajna", // test\n"id": "Lajna.24hClock", "nexus": 1695, "github": "LajnaLegenden/Stardew_Valley_Mods", "brokeIn": "SMAPI 3.0", "unofficial": [ "1.0.1-unofficial.1-pathoschild", "https://community.playstarbound.com/threads/updating-mods-for-stardew-valley-1-3.142524/page-76#post-3342641" ] } ]' }})) |
| + | function p.table(frame) |
| + | -- parse data |
| + | local json = string.gsub(frame.args[1], '%s*//[^"\n]+', '') |
| + | local data = mw.text.jsonDecode(json, mw.text.JSON_TRY_FIXING) |
| + | |
| + | -- start table |
| + | local table = mw.html.create("table") |
| + | table:addClass("wikitable sortable plainlinks") |
| + | table:attr("id", "mod-list") |
| + | table:wikitext("<tr><th>mod name</th><th>author</th><th><abbr title=\"This only shows whether a mod is *compatible*; it may have bugs unrelated to SMAPI compatibility.\">compatibility</abbr></th><th>broke in</th><th>source</th><th> </th></tr>") |
| + | |
| + | -- add mod rows |
| + | for index,mod in pairs(data) do |
| + | -- temporarily passthrough args to avoid duplicating code until we migrate fully to JSON |
| + | -- (We need tostring on numeric fields since the previous code doesn't support numbers) |
| + | mod.chucklefish = private.toSafeString(mod.chucklefish) |
| + | mod.curse = private.toSafeString(mod.curse) |
| + | mod.moddrop = private.toSafeString(mod.moddrop) |
| + | mod.nexus = private.toSafeString(mod.nexus) |
| + | |
| + | local row = p.entry({ args = mod }) |
| + | table:node(row) |
| + | end |
| + | |
| + | -- return output |
| + | return private.style(frame) .. tostring(table) |
| end | | end |
| | | |
| --- Render a mod row in the SMAPI compatibility table. | | --- Render a mod row in the SMAPI compatibility table. |
| -- @param frame The arguments passed to the script. | | -- @param frame The arguments passed to the script. |
− | -- @test mw.log(p.entry({ args = { name="Lookup Anything", name2="LookupAnything", author="Pathoschild", author2="Pathos", id="Pathoschild.LookupAnything", ["old ids"]="LookupAnything", ["nexus id"]="541", ["cf id"]="4250", ["github"]="Pathoschild/StardewMods", warnings="warning A, warning B", links="https://google.ca" }})) | + | -- @test mw.log(p.entry({ args = { name="Content Patcher, ContentPatcher", author="Pathoschild, Pathos", id="Pathoschild.ContentPatcher, ContentPatcher", nexus="1915", chucklefish="4250", curse="309243,content-patcher", github="Pathoschild/StardewMods", warnings="warning A, warning B" }})) |
| function p.entry(frame) | | function p.entry(frame) |
| -- read input args | | -- read input args |
− | local names = private.parseCommaDelimited((private.trim(frame.args["name"]) or '') .. ',' .. (private.trim(frame.args["name2"]) or '')) | + | local names = private.parseCommaDelimited(frame.args["name"] or '') |
− | local authors = private.parseCommaDelimited((private.trim(frame.args["author"]) or '') .. ',' .. (private.trim(frame.args["author2"]) or '')) | + | local authors = private.parseCommaDelimited(frame.args["author"] or '') |
− | local ids = private.parseCommaDelimited((private.trim(frame.args["id"]) or '') .. ',' .. (private.trim(frame.args["old ids"]) or '')) | + | local ids = private.parseCommaDelimited(frame.args["id"] or '') |
− | local nexusID = private.emptyToNil(private.trim(frame.args["nexus id"])) | + | local nexusId = private.emptyToNil(frame.args["nexus"]) |
− | local github = private.emptyToNil(private.trim(frame.args["github"])) | + | local github = private.emptyToNil(frame.args["github"]) |
− | local summary = private.emptyToNil(private.trim(frame.args["summary"])) | + | local summary = private.emptyToNil(frame.args["summary"]) |
− | local brokeIn = private.emptyToNil(private.trim(frame.args["broke in"])) | + | local brokeIn = private.emptyToNil(frame.args["broke in"]) |
− | | |
− | local status = private.emptyToNil(private.trim(frame.args["status"]))
| |
− | local unofficialVersion = private.emptyToNil(private.trim(frame.args["unofficial version"]))
| |
− | local unofficialUrl = private.emptyToNil(private.trim(frame.args["unofficial url"]))
| |
− | local oldIDs = private.emptyToNil(private.trim(frame.args["old ids"]))
| |
− | local chucklefishID = private.emptyToNil(private.trim(frame.args["cf id"]))
| |
− | local customUrl = private.emptyToNil(private.trim(frame.args["url"]))
| |
− | local customSource = private.emptyToNil(private.trim(frame.args["source"]))
| |
− | local name2 = private.emptyToNil(private.trim(frame.args["name2"]))
| |
− | local author2 = private.emptyToNil(private.trim(frame.args["author2"]))
| |
− | local links = private.parseCommaDelimited(frame.args["links"])
| |
− | local warnings = private.parseCommaDelimited(frame.args["warnings"])
| |
| | | |
− | local betaSummary = private.emptyToNil(private.trim(frame.args["beta summary"])) | + | local status = private.emptyToNil(frame.args["status"]) |
− | local betaBrokeIn = private.emptyToNil(private.trim(frame.args["beta broke in"])) | + | local unofficialVersion = private.emptyToNil(frame.args["unofficial version"]) |
− | local betaStatus = private.emptyToNil(private.trim(frame.args["beta status"])) | + | local unofficialUrl = private.emptyToNil(frame.args["unofficial url"]) |
− | local betaUnofficialVersion = private.emptyToNil(private.trim(frame.args["beta unofficial version"])) | + | local chucklefishId = private.emptyToNil(frame.args["chucklefish"]) |
− | local betaUnofficialUrl = private.emptyToNil(private.trim(frame.args["beta unofficial url"])) | + | local curseforgeId = private.emptyToNil(frame.args["curse"]) |
| + | local moddropId = private.emptyToNil(frame.args["moddrop"]) |
| + | local customUrl = private.emptyToNil(frame.args["url"]) |
| + | local customSource = private.emptyToNil(frame.args["source"]) |
| | | |
− | -- parse compatibility
| + | local warnings = private.parseCommaDelimited(frame.args["warnings"]) |
− | local compat = private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl) | + | local devNote = private.emptyToNil(frame.args["dev note"]) |
− | local betaCompat = nil | + | local contentPackFor = private.emptyToNil(frame.args["content pack for"]) |
− | if betaStatus or betaBrokeIn or betaUnofficialUrl or betaUnofficialVersion then | |
− | betaCompat = private.getCompatInfo(betaStatus, betaSummary, betaBrokeIn, betaUnofficialVersion, betaUnofficialUrl)
| |
− | end
| |
| | | |
− | -- get main URL | + | local betaSummary = nil |
− | local url = nil | + | local betaBrokeIn = nil |
− | if nexusID then | + | local betaStatus = nil |
− | url = "https://www.nexusmods.com/stardewvalley/mods/" .. mw.uri.encode(nexusID, "PATH") | + | local betaUnofficialVersion = nil |
− | elseif chucklefishID then
| + | local betaUnofficialUrl = nil |
− | url = "https://community.playstarbound.com/resources/" .. mw.uri.encode(chucklefishID, "PATH") | + | if enableBeta then |
− | else
| + | betaSummary = private.emptyToNil(frame.args["beta summary"]) |
− | url = customUrl | + | betaBrokeIn = private.emptyToNil(frame.args["beta broke in"]) |
| + | betaStatus = private.emptyToNil(frame.args["beta status"]) |
| + | betaUnofficialVersion = private.emptyToNil(frame.args["beta unofficial version"]) |
| + | betaUnofficialUrl = private.emptyToNil(frame.args["beta unofficial url"]) |
| end | | end |
| | | |
Line 92: |
Line 97: |
| if github then | | if github then |
| sourceUrl = "https://github.com/" .. string.gsub(mw.uri.encode(github, "PATH"), "%%2F", "/") | | sourceUrl = "https://github.com/" .. string.gsub(mw.uri.encode(github, "PATH"), "%%2F", "/") |
| + | end |
| + | local hasSource = sourceUrl ~= nil |
| + | |
| + | -- parse compatibility |
| + | local compat = private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl, hasSource) |
| + | local betaCompat = nil |
| + | if enableBeta and (betaStatus or betaBrokeIn or betaUnofficialUrl or betaUnofficialVersion) then |
| + | betaCompat = private.getCompatInfo(betaStatus, betaSummary, betaBrokeIn, betaUnofficialVersion, betaUnofficialUrl, hasSource) |
| end | | end |
| | | |
− | -- get background color | + | -- get main URL |
− | local background = '#999' | + | local url = nil |
− | if compat.status == statuses.ok or compat.status == statuses.optional then | + | if nexusId then |
− | background = '#9F9' | + | url = "https://www.nexusmods.com/stardewvalley/mods/" .. mw.uri.encode(nexusId, "PATH") |
− | elseif compat.status == statuses.workaround or compat.status == statuses.unofficial then | + | elseif moddropId then |
− | background = '#CF9' | + | url = "https://www.moddrop.com/stardew-valley/mods/" .. mw.uri.encode(moddropId, "PATH") |
− | elseif compat.status == statuses.broken then | + | elseif curseforgeId then |
− | background = '#F99' | + | url = "https://www.curseforge.com/projects/" .. mw.uri.encode(curseforgeId, "PATH") |
− | elseif compat.status == statuses.obsolete or compat.status == statuses.abandoned then | + | elseif chucklefishId then |
− | background = '#999' | + | url = "https://community.playstarbound.com/resources/" .. mw.uri.encode(chucklefishId, "PATH") |
| + | elseif customUrl then |
| + | url = customUrl |
| + | elseif hasSource then |
| + | url = sourceUrl |
| end | | end |
| | | |
Line 109: |
Line 126: |
| local row = mw.html.create("tr") | | local row = mw.html.create("tr") |
| row:addClass("mod") | | row:addClass("mod") |
− | row:attr("id", names[1] and mw.uri.anchorEncode(names[1]) or nil); | + | row:attr("id", names[1] and mw.uri.anchorEncode(names[1])); |
| + | row:attr("data-id", table.concat(ids, ",")) |
| row:attr("data-name", table.concat(names, ",")) | | row:attr("data-name", table.concat(names, ",")) |
− | row:attr("data-id", table.concat(ids, ","))
| |
| row:attr("data-author", table.concat(authors, ",")) | | row:attr("data-author", table.concat(authors, ",")) |
− | row:attr("data-url", url) | + | row:attr("data-cf-id", chucklefishId) |
− | row:attr("data-nexus-id", nexusID) | + | row:attr("data-curseforge-id", curseforgeId) |
− | row:attr("data-cf-id", chucklefishID) | + | row:attr("data-moddrop-id", moddropId) |
| + | row:attr("data-nexus-id", nexusId) |
| row:attr("data-github", github) | | row:attr("data-github", github) |
| row:attr("data-custom-source", customSource) | | row:attr("data-custom-source", customSource) |
| + | row:attr("data-url", url) |
| row:attr("data-status", compat.status) | | row:attr("data-status", compat.status) |
| row:attr("data-summary", compat.summary) | | row:attr("data-summary", compat.summary) |
Line 123: |
Line 142: |
| row:attr("data-unofficial-version", compat.unofficialVersion) | | row:attr("data-unofficial-version", compat.unofficialVersion) |
| row:attr("data-unofficial-url", compat.unofficialUrl) | | row:attr("data-unofficial-url", compat.unofficialUrl) |
− | row:attr("data-beta-status", betaCompat and betaCompat.status or nil) | + | if enableBeta then |
− | row:attr("data-beta-summary", betaCompat and betaCompat.summary or nil)
| + | row:attr("data-beta-status", betaCompat and betaCompat.status) |
− | row:attr("data-beta-broke-in", betaCompat and betaCompat.brokeIn or nil)
| + | row:attr("data-beta-summary", betaCompat and betaCompat.summary) |
− | row:attr("data-beta-unofficial-version", betaCompat and betaCompat.unofficialVersion or nil)
| + | row:attr("data-beta-broke-in", betaCompat and betaCompat.brokeIn) |
− | row:attr("data-beta-unofficial-url", betaCompat and betaCompat.unofficialUrl or nil)
| + | row:attr("data-beta-unofficial-version", betaCompat and betaCompat.unofficialVersion) |
| + | row:attr("data-beta-unofficial-url", betaCompat and betaCompat.unofficialUrl) |
| + | end |
| row:attr("data-warnings", private.emptyToNil(table.concat(warnings, ","))) | | row:attr("data-warnings", private.emptyToNil(table.concat(warnings, ","))) |
− | row:attr("style", "line-height: 1em; background: " .. background .. ";") | + | row:attr("data-content-pack-for", contentPackFor) |
| + | row:attr("data-dev-note", devNote) |
| row:newline() | | row:newline() |
| | | |
Line 135: |
Line 157: |
| do | | do |
| local field = mw.html.create("td") | | local field = mw.html.create("td") |
| + | |
| field:wikitext("[" .. (url or '') .. " " .. (names[1] or '') .. "]") | | field:wikitext("[" .. (url or '') .. " " .. (names[1] or '') .. "]") |
| | | |
− | if #names > 1 then | + | local nameCount = #names |
− | local altNames = mw.html.create("small"):wikitext("(aka ") | + | if nameCount > 1 then |
− | for k, v in pairs(names) do | + | field:wikitext("<br /><small>(aka ") |
− | if k > 1 then | + | for i = 1, nameCount do |
− | altNames:wikitext(v) | + | if i > 1 then |
| + | field:wikitext(names[i]) |
| + | if i < nameCount then |
| + | field:wikitext(", ") |
| + | end |
| end | | end |
| end | | end |
− | altNames:wikitext(")") | + | field:wikitext(")</small>") |
− | field:node(mw.html.create("br"))
| |
− | field:node(altNames)
| |
| end | | end |
| | | |
Line 158: |
Line 183: |
| | | |
| field:wikitext(authors[1]) | | field:wikitext(authors[1]) |
− | if #authors > 1 then | + | |
− | local altNames = mw.html.create("small"):wikitext("(aka ") | + | local authorCount = #authors |
− | for k, v in pairs(authors) do | + | if authorCount > 1 then |
− | if k > 1 then | + | field:wikitext("<br /><small>(aka ") |
− | altNames:wikitext(v) | + | for i = 1, authorCount do |
| + | if i > 1 then |
| + | field:wikitext(authors[i]) |
| + | if i < authorCount then |
| + | field:wikitext(", ") |
| + | end |
| end | | end |
| end | | end |
− | altNames:wikitext(")") | + | field:wikitext(")</small>") |
− | field:node(mw.html.create("br"))
| |
− | field:node(altNames)
| |
| end | | end |
| | | |
Line 179: |
Line 207: |
| | | |
| -- stable status | | -- stable status |
− | field:wikitext(compat.summaryIcon .. " " .. compat.summary) | + | field:wikitext("<span class=\"mod-summary\">" .. compat.summaryIcon .. " " .. compat.summary .. "</span>") |
− | if compat.status == statuses.optional then | + | if compat.status == "optional" then |
| field:wikitext("<ref name=\"optional-update\" />") | | field:wikitext("<ref name=\"optional-update\" />") |
| end | | end |
| | | |
| -- beta status | | -- beta status |
− | if betaCompat ~= nill then | + | if betaCompat ~= nil then |
− | field:node(mw.html.create("br")) | + | field:wikitext("<br />") |
− | field:wikitext("'''SDV beta only:''' " .. betaCompat.summaryIcon .. " " .. betaCompat.summary) | + | field:wikitext("'''SDV 1.6 beta only:''' <span class=\"mod-beta-summary\">" .. betaCompat.summaryIcon .. " " .. betaCompat.summary .. "</span>") |
− | if betaCompat.status == statuses.optional then | + | if betaCompat.status == "optional" then |
| field:wikitext("<ref name=\"optional-update\" />") | | field:wikitext("<ref name=\"optional-update\" />") |
| end | | end |
Line 194: |
Line 222: |
| | | |
| -- warnings | | -- warnings |
− | if #warnings > 0 then | + | do |
− | for k, v in pairs(warnings) do
| + | local warningCount = #warnings |
− | field:node(mw.html.create("br"))
| + | if warningCount > 0 then |
− | field:wikitext("⚠ " .. v)
| + | for i = 1, warningCount do |
| + | field:wikitext("<br />⚠ " .. warnings[i]) |
| + | end |
| end | | end |
| end | | end |
Line 221: |
Line 251: |
| -- add 'source' field | | -- add 'source' field |
| do | | do |
− | local field = mw.html.create("td")
| |
− |
| |
| if sourceUrl then | | if sourceUrl then |
− | field:wikitext("[" .. sourceUrl .. " source]") | + | row:wikitext("<td class=\"mod-source\">[" .. sourceUrl .. " source]</td>") |
| else | | else |
− | field:wikitext("<span style=\"color: red; font-size: 0.85em; opacity: 0.5;\">closed source</span>") | + | row:wikitext("<td class=\"mod-source\"><span>closed source</span></td>") |
| end | | end |
− |
| |
− | row:node(field)
| |
| row:newline() | | row:newline() |
| end | | end |
Line 236: |
Line 262: |
| do | | do |
| local field = mw.html.create("td") | | local field = mw.html.create("td") |
− | field:attr("style", "font-size: 0.8em") | + | field:attr("class", "mod-metadata") |
| | | |
| -- anchor | | -- anchor |
| field:wikitext("[[#" .. (names[1] or '') .. "|#]] ") | | field:wikitext("[[#" .. (names[1] or '') .. "|#]] ") |
| | | |
− | -- reference links | + | -- dev note |
− | for k, v in pairs(links) do | + | if devNote then |
− | field:wikitext("[" .. v .. " " .. k .. "] ") | + | local devNoteField = mw.html.create("abbr") |
| + | devNoteField:attr("title", devNote) |
| + | devNoteField:wikitext("[dev note]") |
| + | |
| + | field:node(devNoteField) |
| end | | end |
| | | |
− | -- 'no id' warning | + | -- validation |
| if #ids == 0 then | | if #ids == 0 then |
− | field:wikitext("⚠ no id") | + | field:wikitext("[⚠ no id] ") |
| end | | end |
| | | |
− | -- backwards-compatible metadata (temporary)
| |
− | local metadata = mw.html.create("div")
| |
− | metadata:addClass("mod-metadata")
| |
− | metadata:attr("style", "display: none;")
| |
− | metadata:node(mw.html.create("div"):addClass("mod-anchor"):wikitext(names[1] and mw.uri.anchorEncode(names[1])))
| |
− | metadata:node(mw.html.create("div"):addClass("mod-id"):wikitext(table.concat(ids, ",")))
| |
− | metadata:node(mw.html.create("div"):addClass("mod-url"):wikitext(url))
| |
− | if nexusID ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-nexus-id"):wikitext(nexusID))
| |
− | end
| |
− | if chucklefishID ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-cf-id"):wikitext(chucklefishID))
| |
− | end
| |
− | if github ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-github"):wikitext(github))
| |
− | end
| |
− | if customSource ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-custom-source"):wikitext(customSource))
| |
− | end
| |
− | metadata:node(mw.html.create("div"):addClass("mod-status"):wikitext(compat.status))
| |
− | if compat.brokeIn ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-broke-in"):wikitext(compat.brokeIn))
| |
− | end
| |
− | if compat.unofficialVersion ~= nil and compat.unofficialUrl ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-unofficial-version"):wikitext(compat.unofficialVersion))
| |
− | metadata:node(mw.html.create("div"):addClass("mod-unofficial-url"):wikitext(compat.unofficialUrl))
| |
− | end
| |
− | if betaCompat ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-beta-status"):wikitext(betaCompat.status))
| |
− | if betaCompat.brokeIn ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-beta-broke-in"):wikitext(betaCompat.brokeIn))
| |
− | end
| |
− | if betaCompat.unofficialVersion ~= nil and betaCompat.unofficialUrl ~= nil then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-beta-unofficial-version"):wikitext(betaCompat.unofficialVersion))
| |
− | metadata:node(mw.html.create("div"):addClass("mod-beta-unofficial-url"):wikitext(betaCompat.unofficialUrl))
| |
− | end
| |
− | end
| |
− | if #warnings > 0 then
| |
− | metadata:node(mw.html.create("div"):addClass("mod-warnings"):wikitext(table.concat(warnings, ",")))
| |
− | end
| |
− |
| |
− | field:node(metadata)
| |
| row:node(field) | | row:node(field) |
| end | | end |
Line 303: |
Line 291: |
| --## Private functions | | --## Private functions |
| --########## | | --########## |
| + | -- Get the <templatestyles> tag for the module's stylesheet. |
| + | -- @param frame The arguments passed to the script. |
| + | function private.style(frame) |
| + | if frame.extensionTag ~= nil then |
| + | return frame:extensionTag('templatestyles', '', {src = 'Module:SMAPI compatibility/styles.css'}) |
| + | else |
| + | return "" -- called from the debug console |
| + | end |
| + | end |
| + | |
| -- Get the normalised compatibility info for a mod. | | -- Get the normalised compatibility info for a mod. |
− | -- @param status The specified status code (one of the `statuses` values). If nil or blank, it'll be derived from the other fields. | + | -- @param status The specified status code. If nil or blank, it'll be derived from the other fields. |
| -- @param summary A human-readable summary of the compatibility info. If nil or blank, it'll be derived from the other fields. | | -- @param summary A human-readable summary of the compatibility info. If nil or blank, it'll be derived from the other fields. |
| -- @param brokeIn The SMAPI or Stardew Valley version which broke the mod, if applicable. | | -- @param brokeIn The SMAPI or Stardew Valley version which broke the mod, if applicable. |
Line 311: |
Line 309: |
| -- @param hasSource Whether the mod has public source code available. | | -- @param hasSource Whether the mod has public source code available. |
| function private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl, hasSource) | | function private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl, hasSource) |
− | -- normalise values
| |
− | status = private.emptyToNil(private.trim(status))
| |
− | summary = private.emptyToNil(private.trim(summary))
| |
− | brokeIn = private.emptyToNil(private.trim(brokeIn))
| |
− | unofficialVersion = private.emptyToNil(private.trim(unofficialVersion))
| |
− | unofficialUrl = private.emptyToNil(private.trim(unofficialUrl))
| |
− |
| |
| -- derive status | | -- derive status |
| if status == nil then | | if status == nil then |
| if unofficialVersion ~= nil then | | if unofficialVersion ~= nil then |
− | status = statuses.unofficial | + | status = "unofficial" |
| elseif brokeIn ~= nil then | | elseif brokeIn ~= nil then |
− | status = statuses.broken | + | status = "broken" |
| else | | else |
− | status = statuses.ok | + | status = "ok" |
| end | | end |
| end | | end |
Line 331: |
Line 322: |
| -- derive summary icon | | -- derive summary icon |
| local summaryIcon = "✓" | | local summaryIcon = "✓" |
− | if status == statuses.unofficial or status == statuses.workaround then | + | if status == "unofficial" or status == "workaround" then |
| summaryIcon = "⚠" | | summaryIcon = "⚠" |
− | elseif status == statuses.broken and hasSource then | + | elseif status == "broken" and hasSource then |
| summaryIcon = "↻" | | summaryIcon = "↻" |
− | elseif status == statuses.broken or status == statuses.obsolete or status == statuses.abandoned then | + | elseif status == "broken" or status == "obsolete" or status == "abandoned" then |
| summaryIcon = "✖" | | summaryIcon = "✖" |
| end | | end |
| | | |
| -- derive summary | | -- derive summary |
− | if summary == nil then | + | if not summary then |
− | if status == statuses.ok then | + | if status == "ok" then |
| summary = "use latest version." | | summary = "use latest version." |
− | elseif status == statuses.optional then | + | elseif status == "optional" then |
| summary = "use optional download." | | summary = "use optional download." |
− | elseif status == statuses.unofficial then | + | elseif status == "unofficial" then |
| summary = "broken, use [" .. (unofficialUrl or "") .. " " .. "unofficial version]" | | summary = "broken, use [" .. (unofficialUrl or "") .. " " .. "unofficial version]" |
| if unofficialVersion ~= nil then | | if unofficialVersion ~= nil then |
Line 351: |
Line 342: |
| end | | end |
| summary = summary .. "." | | summary = summary .. "." |
− | elseif status == statuses.workaround then | + | elseif status == "workaround" then |
| summary = "broken. '''error:''' should specify summary." | | summary = "broken. '''error:''' should specify summary." |
− | elseif status == statuses.broken then | + | elseif status == "broken" then |
| if hasSource then | | if hasSource then |
| summary = "broken, not updated yet." | | summary = "broken, not updated yet." |
Line 359: |
Line 350: |
| summary = "broken, not open-source." | | summary = "broken, not open-source." |
| end | | end |
− | elseif status == statuses.obsolete then | + | elseif status == "obsolete" then |
− | summary = "obsolete." | + | summary = "remove this mod (obsolete)." |
− | elseif status == statuses.abandoned then | + | elseif status == "abandoned" then |
− | summary = "no longer maintained." | + | summary = "remove this mod (no longer maintained)." |
| else | | else |
| summary = "'''error:''' unknown status '" .. status .. "'." | | summary = "'''error:''' unknown status '" .. status .. "'." |
Line 378: |
Line 369: |
| end | | end |
| | | |
− | -- Trim a string value. | + | -- Call tostring() on the value if it's not nil, else return the value as-is. |
− | -- @param value The string to trim. | + | -- @param value The value to format. |
− | function private.trim(value) | + | function private.toSafeString(value) |
− | if value ~= nil then | + | if value then |
− | return mw.text.trim(value) | + | return tostring(value) |
| else | | else |
− | return value | + | return nil |
| end | | end |
| end | | end |
| | | |
| -- Get a nil value if the specified value is an empty string, else return the value unchanged. | | -- Get a nil value if the specified value is an empty string, else return the value unchanged. |
− | -- @param value The string to check. | + | -- @param value The string to format. |
| function private.emptyToNil(value) | | function private.emptyToNil(value) |
| if value ~= "" then | | if value ~= "" then |
Line 404: |
Line 395: |
| | | |
| if value ~= nil then | | if value ~= nil then |
− | for k, v in pairs(mw.text.split(value, ",", true)) do | + | local values = mw.text.split(value, ",", true) |
− | v = mw.text.trim(v) | + | for i = 1, #values do |
| + | v = mw.text.trim(values[i]) |
| if v ~= "" then | | if v ~= "" then |
| table.insert(result, v) | | table.insert(result, v) |