Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 195: Line 195:
end
end


-- Documents section
    -- Documents section
addSectionRow(tbl, 'Documents')
addSectionRow(tbl, 'Documents')
Line 209: Line 209:
)
)
-- Query for documents - use plainlist format which gives us clean text
-- Query for document count
local documentsListWikitext =
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\n' ..
' |format=count\n' ..
' |?Has document URL\n' ..
' |format=plainlist\n' ..
' |limit=100\n' ..
'}}'
'}}'
local documentsList = frame:preprocess(documentsListWikitext)
local documentCount = frame:preprocess(documentsCountWikitext)
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0
-- Check if we have documents
-- Create the content row
local hasDocuments = documentsList and trim(documentsList) and trim(documentsList) ~= ''
local tr = tbl:tag('tr')
local td = tr:tag('td'):attr('colspan', '2')
css(td, 'padding:0.2em 0.4em;')
if hasDocuments then
if hasDocuments then
-- Build list by extracting document data using a simpler query approach
-- Create UL element
-- Query each property separately to avoid parsing issues
local ul = mw.html.create('ul')
local docListWikitext = '<ul style="margin:0; padding-left:1.5em;">'
ul:css('margin', '0'):css('padding-left', '1.5em')
-- Get list of document pages
-- Get list of document pages
Line 241: Line 241:
-- Process each document page
-- Process each document page
if docPages and trim(docPages) then
if docPages and trim(docPages) then
-- Split by comma or newline
for docPage in docPages:gmatch('[^,\n]+') do
for docPage in docPages:gmatch('[^,\n]+') do
docPage = trim(docPage)
docPage = trim(docPage)
if docPage and docPage ~= '' then
if docPage and docPage ~= '' then
-- Get type and URL using #show
-- Get type and URL
local typeQuery = '{{#show:' .. docPage .. '|?Has document type}}'
local typeQuery = '{{#show:' .. docPage .. '|?Has document type}}'
local urlQuery = '{{#show:' .. docPage .. '|?Has document URL}}'
local urlQuery = '{{#show:' .. docPage .. '|?Has document URL}}'
local docType = frame:preprocess(typeQuery)
local docType = trim(frame:preprocess(typeQuery))
local docUrl = frame:preprocess(urlQuery)
local docUrl = trim(frame:preprocess(urlQuery))
docType = trim(docType)
docUrl = trim(docUrl)
if docUrl and docUrl ~= '' then
if docUrl and docUrl ~= '' then
local displayText = (docType and docType ~= '') and docType or 'Document'
local displayText = (docType and docType ~= '') and docType or 'Document'
docListWikitext = docListWikitext .. '<li><a href="' .. docUrl .. '" class="external">' .. displayText .. '</a></li>'
-- Create list item with link
local li = ul:tag('li')
local a = li:tag('a')
a:attr('href', docUrl)
a:attr('class', 'external')
a:wikitext(displayText)
end
end
end
end
Line 263: Line 265:
end
end
docListWikitext = docListWikitext .. '</ul>'
-- Add the UL to the td
td:node(ul)
-- Create upload link
-- Add upload link
local uploadLinkWikitext = '<div style="margin-top:0.5em; font-style:italic;"><a href="' .. tostring(uploadUrl) .. '" class="external">Upload a document</a></div>'
local uploadDiv = mw.html.create('div')
uploadDiv:css('margin-top', '0.5em'):css('font-style', 'italic')
local uploadLink = uploadDiv:tag('a')
uploadLink:attr('href', tostring(uploadUrl))
uploadLink:attr('class', 'external')
uploadLink:wikitext('Upload a document')
-- Combine and add to table - use wikitext so it gets rendered properly
td:node(uploadDiv)
local combinedWikitext = docListWikitext .. uploadLinkWikitext
addFullRow(tbl, combinedWikitext, 'padding:0.2em 0.4em;', true)
else
else
-- Just show the upload link
-- Just show the upload link
local uploadLinkWikitext = '<div style="font-style:italic;"><a href="' .. tostring(uploadUrl) .. '" class="external">Upload a document</a></div>'
local uploadDiv = mw.html.create('div')
addFullRow(tbl, uploadLinkWikitext, 'padding:0.2em 0.4em;', true)
uploadDiv:css('font-style', 'italic')
local uploadLink = uploadDiv:tag('a')
uploadLink:attr('href', tostring(uploadUrl))
uploadLink:attr('class', 'external')
uploadLink:wikitext('Upload a document')
td:node(uploadDiv)
end
end


MediaWiki Appliance - Powered by TurnKey Linux