Module:CRTModel: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Manual revert |
||
| Line 209: | Line 209: | ||
) | ) | ||
-- Query | -- Query for document count | ||
local | local documentsCountWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:Documents]]\n' .. | ' [[Category:Documents]]\n' .. | ||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | ||
' |format=count\n' .. | |||
' |format= | |||
'}}' | '}}' | ||
local | local documentCount = frame:preprocess(documentsCountWikitext) | ||
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | |||
local hasDocuments = | |||
-- Create the content row | -- Create the content row | ||
| Line 232: | Line 225: | ||
if hasDocuments then | if hasDocuments then | ||
-- | -- Use #ask - it returns an HTML table | ||
td:wikitext( | local docsQueryWikitext = | ||
'{{#ask:\n' .. | |||
' [[Category:Documents]]\n' .. | |||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | |||
' |?Has document type\n' .. | |||
' |?Has document URL\n' .. | |||
' |format=broadtable\n' .. | |||
' |headers=hide\n' .. | |||
' |link=none\n' .. | |||
'}}' | |||
local docsResult = frame:preprocess(docsQueryWikitext) | |||
-- Create UL element | |||
local ul = mw.html.create('ul') | |||
ul:css('margin', '0'):css('padding-left', '1.5em') | |||
-- Parse the HTML table - extract data from <td> tags | |||
-- Pattern: <td ...>page</td><td ...>type</td><td ...>URL</td> | |||
if docsResult then | |||
-- Match each table row | |||
for rowContent in docsResult:gmatch('<tr[^>]*>(.-)</tr>') do | |||
local cells = {} | |||
-- Extract content from each <td> | |||
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do | |||
-- Strip any remaining HTML tags and get just the text | |||
local cleanContent = cellContent:gsub('<[^>]+>', '') | |||
table.insert(cells, trim(cleanContent)) | |||
end | |||
-- cells[1] = page name, cells[2] = type, cells[3] = URL | |||
if #cells >= 3 then | |||
local docType = cells[2] | |||
local docUrl = cells[3] | |||
if docUrl and docUrl ~= '' then | |||
local displayText = (docType and docType ~= '') and docType or 'Document' | |||
-- Create list item with link | |||
local li = ul:tag('li') | |||
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']') | |||
end | |||
end | |||
end | |||
end | |||
td:node(ul) | |||
-- Add upload link | -- Add upload link | ||