Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 197: | Line 197: | ||
addSectionRow(tbl, 'Documents') | addSectionRow(tbl, 'Documents') | ||
-- Build the upload link | -- Build the upload link | ||
local target = pageName .. " - document" | local target = pageName .. " - document" | ||
local uploadUrl = mw.uri.fullUrl( | local uploadUrl = mw.uri.fullUrl( | ||
| Line 208: | Line 208: | ||
) | ) | ||
-- Query for documents | -- Query for documents - use plainlist format which gives us clean text | ||
local | local documentsListWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:Documents]]\n' .. | ' [[Category:Documents]]\n' .. | ||
| Line 215: | Line 215: | ||
' |?Has document type\n' .. | ' |?Has document type\n' .. | ||
' |?Has document URL\n' .. | ' |?Has document URL\n' .. | ||
' |format= | ' |format=plainlist\n' .. | ||
' | | ' |limit=100\n' .. | ||
'}}' | '}}' | ||
local | local documentsList = frame:preprocess(documentsListWikitext) | ||
-- Check if we have | -- Check if we have documents | ||
local hasDocuments = | local hasDocuments = documentsList and trim(documentsList) and trim(documentsList) ~= '' | ||
if hasDocuments then | if hasDocuments then | ||
-- | -- Build list by extracting document data using a simpler query approach | ||
local | -- Query each property separately to avoid parsing issues | ||
local docListWikitext = '<ul style="margin:0; padding-left:1.5em;">' | |||
-- | -- Get list of document pages | ||
for | local docPagesWikitext = | ||
'{{#ask:\n' .. | |||
' [[Category:Documents]]\n' .. | |||
' [[Has related CRT model::' .. fullPageName .. ']]\n' .. | |||
' |limit=100\n' .. | |||
' |link=none\n' .. | |||
'}}' | |||
local docPages = frame:preprocess(docPagesWikitext) | |||
-- Process each document page | |||
if docPages and trim(docPages) then | |||
-- Split by comma or newline | |||
for docPage in docPages:gmatch('[^,\n]+') do | |||
docPage = trim(docPage) | |||
if docPage and docPage ~= '' then | |||
-- Get type and URL using #show | |||
local typeQuery = '{{#show:' .. docPage .. '|?Has document type}}' | |||
local urlQuery = '{{#show:' .. docPage .. '|?Has document URL}}' | |||
local docType = frame:preprocess(typeQuery) | |||
local docUrl = frame:preprocess(urlQuery) | |||
docType = trim(docType) | |||
docUrl = trim(docUrl) | |||
if docUrl and docUrl ~= '' then | |||
local displayText = (docType and docType ~= '') and docType or 'Document' | |||
docListWikitext = docListWikitext .. '<li><a href="' .. docUrl .. '" class="external">' .. displayText .. '</a></li>' | |||
end | |||
end | |||
end | end | ||
end | end | ||
docListWikitext = docListWikitext .. '</ul>' | |||
-- Create upload link | |||
local uploadLinkWikitext = '<div style="margin-top:0.5em; font-style:italic;"><a href="' .. tostring(uploadUrl) .. '" class="external">Upload a document</a></div>' | |||
-- | -- Combine and add to table - use wikitext so it gets rendered properly | ||
local | local combinedWikitext = docListWikitext .. uploadLinkWikitext | ||
addFullRow(tbl, | addFullRow(tbl, combinedWikitext, 'padding:0.2em 0.4em;', false) | ||
else | else | ||
-- Just show the upload link | -- Just show the upload link | ||
local | local uploadLinkWikitext = '<div style="font-style:italic;"><a href="' .. tostring(uploadUrl) .. '" class="external">Upload a document</a></div>' | ||
addFullRow(tbl, | addFullRow(tbl, uploadLinkWikitext, 'padding:0.2em 0.4em;', false) | ||
end | end | ||