Module:CategoryAudit: Difference between revisions

Create module to find brands/types missing category pages (via create-page on MediaWiki MCP Server)
 
Fix category links (add colon prefix) and use Lua URL builder instead of unprocessed wikitext (via update-page on MediaWiki MCP Server)
 
Line 13: Line 13:
end
end


local function extractValues(queryResult)
-- Helper to build a "create category" URL
local valuesSet = {}
local function createCategoryUrl(categoryTitle, preloadTemplate, brandOrType)
local valuesList = {}
return tostring(mw.uri.fullUrl(categoryTitle, {
action = 'edit',
if queryResult then
preload = preloadTemplate,
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
['preloadparams[]'] = brandOrType
local value = trim(cellContent:gsub('<[^>]+>', ''))
}))
if value and value ~= '' and not valuesSet[value] then
valuesSet[value] = true
table.insert(valuesList, value)
end
end
end
table.sort(valuesList)
return valuesList, valuesSet
end
end


Line 54: Line 45:
local result = frame:preprocess(queryWikitext)
local result = frame:preprocess(queryWikitext)
local countBefore = 0
for _ in pairs(usedBrandsSet) do countBefore = countBefore + 1 end
if result then
if result then
Line 118: Line 107:
for _, brand in ipairs(missing) do
for _, brand in ipairs(missing) do
local count = frame:preprocess('{{#ask:[[Category:CRT models]][[Has brand::' .. brand .. ']]|format=count}}')
local count = frame:preprocess('{{#ask:[[Category:CRT models]][[Has brand::' .. brand .. ']]|format=count}}')
table.insert(output, '* [[Category:' .. brand .. ' CRTs|' .. brand .. ']] (' .. count .. ' CRTs) — <span class="plainlinks">[{{fullurl:Category:' .. brand .. ' CRTs|action=edit&preload=Template:CRT_brand_category/preload&preloadparams%5B%5D=' .. mw.uri.encode(brand) .. '}} create]</span>')
local categoryTitle = 'Category:' .. brand .. ' CRTs'
local createUrl = createCategoryUrl(categoryTitle, 'Template:CRT brand category/preload', brand)
-- Use [[:Category:...]] with colon to make it a LINK not a category assignment
table.insert(output, '* <strong>' .. brand .. '</strong> — ' .. count .. ' CRTs need [[:' .. categoryTitle .. ']] — [' .. createUrl .. ' create it]')
end
end
Line 207: Line 199:
for _, crtType in ipairs(missing) do
for _, crtType in ipairs(missing) do
local count = frame:preprocess('{{#ask:[[Category:CRT models]][[Has CRT type::' .. crtType .. ']]|format=count}}')
local count = frame:preprocess('{{#ask:[[Category:CRT models]][[Has CRT type::' .. crtType .. ']]|format=count}}')
table.insert(output, '* [[Category:' .. crtType .. '|' .. crtType .. ']] (' .. count .. ' CRTs)')
local categoryTitle = 'Category:' .. crtType
local createUrl = createCategoryUrl(categoryTitle, 'Template:CRT type category/preload', crtType)
table.insert(output, '* <strong>' .. crtType .. '</strong> — ' .. count .. ' CRTs need [[:' .. categoryTitle .. ']] — [' .. createUrl .. ' create it]')
end
end
Line 296: Line 290:
for _, brand in ipairs(missing) do
for _, brand in ipairs(missing) do
local count = frame:preprocess('{{#ask:[[Category:AV devices]][[Has brand::' .. brand .. ']]|format=count}}')
local count = frame:preprocess('{{#ask:[[Category:AV devices]][[Has brand::' .. brand .. ']]|format=count}}')
table.insert(output, '* [[Category:' .. brand .. ' AV devices|' .. brand .. ']] (' .. count .. ' devices)')
local categoryTitle = 'Category:' .. brand .. ' AV devices'
local createUrl = createCategoryUrl(categoryTitle, 'Template:AV brand category/preload', brand)
table.insert(output, '* <strong>' .. brand .. '</strong> — ' .. count .. ' devices need [[:' .. categoryTitle .. ']] — [' .. createUrl .. ' create it]')
end
end
Line 385: Line 381:
for _, deviceType in ipairs(missing) do
for _, deviceType in ipairs(missing) do
local count = frame:preprocess('{{#ask:[[Category:AV devices]][[Has device type::' .. deviceType .. ']]|format=count}}')
local count = frame:preprocess('{{#ask:[[Category:AV devices]][[Has device type::' .. deviceType .. ']]|format=count}}')
table.insert(output, '* [[Category:' .. deviceType .. 's|' .. deviceType .. ']] (' .. count .. ' devices)')
local categoryTitle = 'Category:' .. deviceType .. 's'
local createUrl = createCategoryUrl(categoryTitle, 'Template:AV device type category/preload', deviceType)
table.insert(output, '* <strong>' .. deviceType .. '</strong> — ' .. count .. ' devices need [[:' .. categoryTitle .. ']] — [' .. createUrl .. ' create it]')
end
end
MediaWiki Appliance - Powered by TurnKey Linux