Module:CRTModel: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 209: Line 209:
)
)
-- Query documents using template format (same pattern as Inputs section)
-- Query for document count
local docsQueryWikitext =
local documentsCountWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[Category:Documents]]\n' ..
' [[Category:Documents]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' |?Has document type=type\n' ..
' |format=count\n' ..
' |?Has document URL=url\n' ..
' |format=ul\n' ..
' |template=Document link inline\n' ..
' |named args=yes\n' ..
' |searchlabel=\n' ..
'}}'
'}}'
local docsHtml = frame:preprocess(docsQueryWikitext)
local documentCount = frame:preprocess(documentsCountWikitext)
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0
-- Check if we have documents
local hasDocuments = docsHtml and trim(docsHtml) and not docsHtml:match('^%s*$')
-- Create the content row
-- Create the content row
Line 232: Line 225:
if hasDocuments then
if hasDocuments then
-- Add the documents list HTML directly
-- Use #ask - it returns an HTML table
td:wikitext(docsHtml)
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
MediaWiki Appliance - Powered by TurnKey Linux