Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 194: Line 194:
end
end


-- Documents section
    -- Documents section
-- Check if there are any documents first
addSectionRow(tbl, 'Documents')
local documentsCheckWikitext =
-- Query for documents
local documentsQueryWikitext =
'{{#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' ..
' |?Has document type\n' ..
' |?Has document URL\n' ..
' |mainlabel=-\n' ..
'}}'
'}}'
local documentCount = frame:preprocess(documentsCheckWikitext)
local documentsResult = frame:preprocess(documentsQueryWikitext)
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0
-- Build the upload link
-- Build the upload link
Line 216: Line 219:
)
)
-- Always show Documents section
-- Check if we have any documents
addSectionRow(tbl, 'Documents')
local hasDocuments = documentsResult and trim(documentsResult) and not documentsResult:match('^%s*$')
if hasDocuments then
if hasDocuments then
-- Build bulleted list of documents using the template
-- Parse the results and build HTML list manually
local docListWikitext =
local docLinks = {}
-- The #ask result returns results in a table-like format
-- We need to query each document individually to get clean data
local docListQueryWikitext =
'{{#ask:\n' ..
' [[Category:Documents]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' |?Has document type=Type\n' ..
' |?Has document URL=URL\n' ..
' |format=list\n' ..
'}}'
-- Actually, let's use a simpler approach with custom format
local docBuildWikitext = ''
local askDocsWikitext =
'{{#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' ..
' |?Has document type\n' ..
' |?Has document URL=url\n' ..
' |?Has document URL\n' ..
' |format=ul\n' ..
' |format=template\n' ..
' |template=Document link inline\n' ..
' |template=Document link inline\n' ..
' |named args=yes\n' ..
' |named args=yes\n' ..
' |searchlabel=\n' ..
' |introtemplate=Document list intro\n' ..
'}}'
'}}'
-- Preprocess the #ask query to execute it
local docsHtml = frame:preprocess(askDocsWikitext)
local docListHtml = frame:preprocess(docListWikitext)
-- Combine with upload link
-- Combine with upload link
local combinedHtml = docListHtml .. '\n\n<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
local combinedContent = docsHtml .. '<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
addFullRow(tbl, combinedContent, 'padding:0.2em 0.4em;', true)
-- Use isRawHtml=true since we've already preprocessed and have HTML
addFullRow(tbl, combinedHtml, 'padding:0.2em 0.4em;', true)
else
else
-- Just show the upload link styled as italic
-- Just show the upload link
local uploadLinkWikitext = '<div style="font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
local uploadLinkHtml = '<div style="font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
-- Use isRawHtml=false so the link gets parsed
addFullRow(tbl, uploadLinkHtml, 'padding:0.2em 0.4em;', true)
addFullRow(tbl, uploadLinkWikitext, 'padding:0.2em 0.4em;', false)
end
end


MediaWiki Appliance - Powered by TurnKey Linux