Module:Accessory: Difference between revisions
Arclight changed the content model of the page Module:Accessory from "wikitext" to "Scribunto module" |
Add Archival Links section to infobox, querying Accessory link subobjects (via update-page on MediaWiki MCP Server) |
||
| Line 266: | Line 266: | ||
local target = "Document:" .. timestamp .. "-" .. random | local target = "Document:" .. timestamp .. "-" .. random | ||
local uploadUrl = mw.uri.fullUrl( | local uploadUrl = mw.uri.fullUrl( | ||
"Special:FormEdit", | "Special:FormEdit", | ||
| Line 279: | Line 277: | ||
css(docsDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em; text-align:center;') | css(docsDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em; text-align:center;') | ||
docsDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span class="infobox-button infobox-button-secondary">Add a document</span>]') | docsDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span class="infobox-button infobox-button-secondary">Add a document</span>]') | ||
-- Archival Links section: Query for link subobjects and display by type | |||
local linksQueryWikitext = | |||
'{{#ask:\n' .. | |||
' [[Accessory::' .. fullPageName .. ']]\n' .. | |||
' |?Model link type\n' .. | |||
' |?Model link source\n' .. | |||
' |?Model link URL\n' .. | |||
' |format=broadtable\n' .. | |||
' |headers=hide\n' .. | |||
' |link=none\n' .. | |||
'}}' | |||
local linksResult = frame:preprocess(linksQueryWikitext) | |||
-- Parse links and organize by type | |||
local linksByType = { | |||
Manufacturer = {}, | |||
Retailer = {}, | |||
Database = {} | |||
} | |||
local hasLinks = false | |||
if linksResult then | |||
for rowContent in linksResult:gmatch('<tr[^>]*>(.-)</tr>') do | |||
local cells = {} | |||
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do | |||
local cleanContent = cellContent:gsub('<[^>]+>', '') | |||
table.insert(cells, trim(cleanContent)) | |||
end | |||
-- cells[1] = page/subobject, cells[2] = type, cells[3] = source, cells[4] = URL | |||
if #cells >= 4 then | |||
local linkType = cells[2] | |||
local linkSource = cells[3] | |||
local linkUrl = cells[4] | |||
if linkType and linkSource and linkUrl and linkUrl ~= '' then | |||
if linksByType[linkType] then | |||
table.insert(linksByType[linkType], {source = linkSource, url = linkUrl}) | |||
hasLinks = true | |||
end | |||
end | |||
end | |||
end | |||
end | |||
if hasLinks then | |||
addSectionRow(container, 'Archival Links') | |||
local typeOrder = {'Database', 'Manufacturer', 'Retailer'} | |||
for _, linkType in ipairs(typeOrder) do | |||
if #linksByType[linkType] > 0 then | |||
local linksHtml = {} | |||
for _, link in ipairs(linksByType[linkType]) do | |||
table.insert(linksHtml, '[' .. link.url .. ' ' .. link.source .. ']') | |||
end | |||
addRow(container, linkType, table.concat(linksHtml, '<br>'), true) | |||
end | |||
end | |||
end | |||
-- Contribute section | -- Contribute section | ||