Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 229: Line 229:
ul:css('margin', '0'):css('padding-left', '1.5em')
ul:css('margin', '0'):css('padding-left', '1.5em')
-- Get list of document pages
-- Use #ask with array format to get raw values
local docPagesWikitext =
local docsQueryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[Category:Documents]]\n' ..
' [[Category:Documents]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' |limit=100\n' ..
' |?Has document type\n' ..
' |?Has document URL\n' ..
' |format=array\n' ..
' |propsep=@@\n' ..
' |valuesep=##\n' ..
' |sep=|||\n' ..
' |link=none\n' ..
' |link=none\n' ..
'}}'
'}}'
local docPages = frame:preprocess(docPagesWikitext)
local docsResult = frame:preprocess(docsQueryWikitext)
-- Process each document page
-- Parse the array format: each document separated by |||, properties by @@
if docPages and trim(docPages) then
if docsResult and trim(docsResult) then
for docPage in docPages:gmatch('[^,\n]+') do
for docData in docsResult:gmatch('[^|]+') do
docPage = trim(docPage)
-- Split by @@ to get page name, type, and URL
if docPage and docPage ~= '' then
local parts = {}
-- Get type and URL - use + to get raw values without formatting
for part in (docData .. '@@'):gmatch('([^@]*)@@') do
local typeQuery = '{{#show:' .. docPage .. '|?Has document type|+sep=,}}'
table.insert(parts, trim(part))
local urlQuery = '{{#show:' .. docPage .. '|?Has document URL|+sep=,}}'
end
-- parts[1] = page name, parts[2] = document type, parts[3] = URL
local docType = parts[2]
local docUrl = parts[3]
if docUrl and docUrl ~= '' then
local displayText = (docType and docType ~= '') and docType or 'Document'
local docType = trim(frame:preprocess(typeQuery))
-- Create list item with link
local docUrl = trim(frame:preprocess(urlQuery))
local li = ul:tag('li')
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']')
if docUrl and docUrl ~= '' then
local displayText = (docType and docType ~= '') and docType or 'Document'
-- Create list item with link using bracket syntax
local li = ul:tag('li')
li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']')
end
end
end
end
end
MediaWiki Appliance - Powered by TurnKey Linux