Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 196: Line 196:
     -- Documents section
     -- Documents section
addSectionRow(tbl, 'Documents')
addSectionRow(tbl, 'Documents')
-- Query for documents
local documentsQueryWikitext =
'{{#ask:\n' ..
' [[Category:Documents]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' |?Has document type\n' ..
' |?Has document URL\n' ..
' |mainlabel=-\n' ..
'}}'
local documentsResult = frame:preprocess(documentsQueryWikitext)
-- Build the upload link
-- Build the upload link
Line 219: Line 208:
)
)
-- Check if we have any documents
-- Query for documents and build the list in Lua
local hasDocuments = documentsResult and trim(documentsResult) and not documentsResult:match('^%s*$')
local documentsQueryWikitext =
'{{#ask:\n' ..
' [[Category:Documents]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' |?Has document type\n' ..
' |?Has document URL\n' ..
' |format=count\n' ..
'}}'
local documentCount = frame:preprocess(documentsQueryWikitext)
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0
if hasDocuments then
if hasDocuments then
-- Parse the results and build HTML list manually
-- Get the actual document data using #show for each document
local docLinks = {}
-- First, get the list of document page names
local docPagesQueryWikitext =
-- 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' ..
'{{#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' ..
' |limit=100\n' ..
' |?Has document URL=URL\n' ..
' |format=list\n' ..
'}}'
'}}'
local docPagesResult = frame:preprocess(docPagesQueryWikitext)
-- Build links manually - use #show to get properties for each document
local docListHtml = '<ul style="margin:0; padding-left:1.5em;">'
-- Actually, let's use a simpler approach with custom format
-- Parse document page names from the result
local docBuildWikitext = ''
-- The result format is typically "PageName1, PageName2, ..." or line-separated
local askDocsWikitext =
for docPage in docPagesResult:gmatch('[^\n,]+') do
'{{#ask:\n' ..
docPage = trim(docPage)
' [[Category:Documents]]\n' ..
if docPage and docPage ~= '' then
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
-- Get document type and URL for this page
' |?Has document type\n' ..
local docTypeWikitext = '{{#show:' .. docPage .. '|?Has document type}}'
' |?Has document URL\n' ..
local docUrlWikitext = '{{#show:' .. docPage .. '|?Has document URL}}'
' |format=template\n' ..
' |template=Document link inline\n' ..
local docType = trim(frame:preprocess(docTypeWikitext))
' |named args=yes\n' ..
local docUrl = trim(frame:preprocess(docUrlWikitext))
' |introtemplate=Document list intro\n' ..
'}}'
if docUrl and docUrl ~= '' then
local linkText = docType or 'Document'
docListHtml = docListHtml .. '<li>[' .. docUrl .. ' ' .. linkText .. ']</li>'
end
end
end
local docsHtml = frame:preprocess(askDocsWikitext)
docListHtml = docListHtml .. '</ul>'
-- Combine with upload link
-- Add the documents list and upload link
local combinedContent = docsHtml .. '<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
local combinedHtml = docListHtml .. '<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
addFullRow(tbl, combinedContent, 'padding:0.2em 0.4em;', true)
addFullRow(tbl, combinedHtml, 'padding:0.2em 0.4em;', false)
else
else
-- Just show the upload link
-- Just show the upload link
local uploadLinkHtml = '<div style="font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
local uploadLinkWikitext = '<div style="font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
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