|
|
Line 77: |
Line 77: |
| function h.invalidColor(colorId) | | function h.invalidColor(colorId) |
| h.warn(string.format("<code>%s</code> is not a valid color name. See [[Template:Color]] for a list of supported colors.", colorId)) | | h.warn(string.format("<code>%s</code> is not a valid color name. See [[Template:Color]] for a list of supported colors.", colorId)) |
| | -- We only store invalid colors for performance reasons |
| | -- Storing all template usages seems to break pages that use the template a lot |
| _Arguments().store({ | | _Arguments().store({ |
| module = "Module:Color", | | module = "Module:Color", |
Line 172: |
Line 174: |
| end | | end |
| end | | end |
| end
| |
|
| |
| -- [[:Category:Articles Using Invalid Color Names#Summary]]
| |
| function p.ReportInvalidColors(frame)
| |
| local utilsLayout = require("Module:UtilsLayout")
| |
| local utilsMarkup = require("Module:UtilsMarkup")
| |
| local utilsTable = require("Module:UtilsTable")
| |
|
| |
| local invalidColors = _Arguments().query({
| |
| module = "Module:Color",
| |
| parameter = 1,
| |
| isValid = false,
| |
| })
| |
| invalidColors = utilsTable.uniqueBy(invalidColors, "_pageName")
| |
| invalidColors = utilsTable.groupBy(invalidColors, "argument")
| |
| invalidColors = utilsTable.mapValues(invalidColors, utilsTable._map("_pageName"))
| |
|
| |
| local rows = {}
| |
| for colorName, pages in pairs(invalidColors) do
| |
| colorName = "<code>"..colorName.."</code>"
| |
| local pageLinks = utilsTable.map(pages, utilsMarkup.link)
| |
| local pageList = table.concat(pageLinks, " • ")
| |
| table.insert(rows, {colorName, #pages, pageList})
| |
| end
| |
| -- sort descending by # of pages then ascending by color name
| |
| table.sort(rows, function(a, b)
| |
| if a[2] == b[2] then
| |
| return a[1] < b[1]
| |
| else
| |
| return a[2] > b[2]
| |
| end
| |
| end)
| |
|
| |
| local wikitable = utilsLayout.table({
| |
| headers = {"Invalid Color Name", "Page Count", "Pages"},
| |
| rows = rows,
| |
| sortable = true,
| |
| })
| |
| return wikitable
| |
| end | | end |
|
| |
|