Module:CRTModel: Difference between revisions

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


-- Documents section
-- Documents section
local documentsAskWikitext =
-- Check if there are any documents first
local documentsCheckWikitext =
'{{#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=list\n' ..
' |link=none\n' ..
'}}'
'}}'
local documentsAskResult = frame:preprocess(documentsAskWikitext)
local documentCount = frame:preprocess(documentsCheckWikitext)
local hasDocuments = documentCount and tonumber(trim(documentCount)) and tonumber(trim(documentCount)) > 0
-- Build the upload link
-- Build the upload link
Line 217: Line 216:
)
)
-- Check if there are any documents
-- Always show Documents section
local hasDocuments = documentsAskResult and trim(documentsAskResult) and not documentsAskResult:match('^%s*$')
-- Always show Documents section if there are documents OR if we want to show the upload link
addSectionRow(tbl, 'Documents')
addSectionRow(tbl, 'Documents')
if hasDocuments then
if hasDocuments then
-- Parse the ask results and build bulleted list
-- Build bulleted list of documents using the template
local docListWikitext =
local docListWikitext =
'{{#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' ..
' |?Has document type=type\n' ..
' |?Has document URL=URL\n' ..
' |?Has document URL=url\n' ..
' |format=ul\n' ..
' |format=ul\n' ..
' |template=Document link inline\n' ..
' |template=Document link inline\n' ..
Line 238: Line 234:
local docListHtml = frame:preprocess(docListWikitext)
local docListHtml = frame:preprocess(docListWikitext)
-- Add the documents list plus upload link
-- Add the documents list, then the upload link on a new line with different styling
local combinedHtml = docListHtml .. '\n* [' .. tostring(uploadUrl) .. ' Upload a document]'
local combinedHtml = docListHtml .. '\n\n<div style="margin-top:0.5em; font-style:italic;">[' .. tostring(uploadUrl) .. ' Upload a document]</div>'
addFullRow(tbl, combinedHtml, 'padding:0.2em 0.4em;', true)
addFullRow(tbl, combinedHtml, 'padding:0.2em 0.4em;', true)
else
else
-- Just show the upload link
-- Just show the upload link styled as italic
local uploadLinkHtml = '* [' .. tostring(uploadUrl) .. ' Upload a document]'
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;', true)
end
end


MediaWiki Appliance - Powered by TurnKey Linux