|
|
| Line 209: |
Line 209: |
| ) | | ) |
| | | |
| -- Query for document count | | -- Query documents using template format (same pattern as Inputs section) |
| local documentsCountWikitext = | | local docsQueryWikitext = |
| '{{#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' .. |
| | ' |format=ul\n' .. |
| | ' |template=Document link inline\n' .. |
| | ' |searchlabel=\n' .. |
| '}}' | | '}}' |
| local documentCount = frame:preprocess(documentsCountWikitext) | | local docsHtml = frame:preprocess(docsQueryWikitext) |
| local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0 | | |
| | -- Check if we have documents |
| | local hasDocuments = docsHtml and trim(docsHtml) and not docsHtml:match('^%s*$') |
| | | |
| -- Create the content row | | -- Create the content row |
| Line 225: |
Line 231: |
| | | |
| if hasDocuments then | | if hasDocuments then |
| -- Use #ask - it returns an HTML table | | -- Add the documents list HTML directly |
| local docsQueryWikitext =
| | td:wikitext(docsHtml) |
| '{{#ask:\n' ..
| |
| ' [[Category:Documents]]\n' ..
| |
| ' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
| |
| ' |?Has document type\n' ..
| |
| ' |?Has document URL\n' ..
| |
| ' |format=broadtable\n' ..
| |
| ' |headers=hide\n' ..
| |
| ' |link=none\n' ..
| |
| '}}'
| |
| local docsResult = frame:preprocess(docsQueryWikitext)
| |
|
| |
| -- Create UL element
| |
| local ul = mw.html.create('ul')
| |
| ul:css('margin', '0'):css('padding-left', '1.5em')
| |
|
| |
| -- Parse the HTML table - extract data from <td> tags
| |
| -- Pattern: <td ...>page</td><td ...>type</td><td ...>URL</td> | |
| if docsResult then
| |
| -- Match each table row
| |
| for rowContent in docsResult:gmatch('<tr[^>]*>(.-)</tr>') do
| |
| local cells = {}
| |
| -- Extract content from each <td>
| |
| for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do
| |
| -- Strip any remaining HTML tags and get just the text
| |
| local cleanContent = cellContent:gsub('<[^>]+>', '')
| |
| table.insert(cells, trim(cleanContent))
| |
| end
| |
|
| |
| -- cells[1] = page name, cells[2] = type, cells[3] = URL
| |
| if #cells >= 3 then
| |
| local docType = cells[2]
| |
| local docUrl = cells[3]
| |
|
| |
| if docUrl and docUrl ~= '' then
| |
| local displayText = (docType and docType ~= '') and docType or 'Document'
| |
|
| |
| -- Create list item with link
| |
| local li = ul:tag('li')
| |
| li:wikitext('[' .. docUrl .. ' ' .. displayText .. ']')
| |
| end
| |
| end
| |
| end
| |
| end
| |
|
| |
| td:node(ul)
| |
| | | |
| -- Add upload link | | -- Add upload link |