Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 194: | Line 194: | ||
end | end | ||
-- Documents section | |||
addSectionRow(container, 'Documents') | addSectionRow(container, 'Documents') | ||
-- Build the upload link | -- Build the upload link with UUID-like unique identifier | ||
local target = pageName .. " - document" | local timestamp = os.time() | ||
local random = math.random(1000, 9999) | |||
local target = pageName .. " - document " .. timestamp .. "-" .. random | |||
local uploadUrl = mw.uri.fullUrl( | local uploadUrl = mw.uri.fullUrl( | ||
"Special:FormEdit", | "Special:FormEdit", | ||
| Line 204: | Line 206: | ||
form = "Document", | form = "Document", | ||
target = target, | target = target, | ||
["Document[ | ["Document[crt_models]"] = pageName | ||
} | } | ||
) | ) | ||
| Line 223: | Line 225: | ||
if hasDocuments then | if hasDocuments then | ||
-- Use #ask | -- Use #ask to get documents | ||
local docsQueryWikitext = | local docsQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 230: | Line 232: | ||
' |?Has document type\n' .. | ' |?Has document type\n' .. | ||
' |?Has document URL\n' .. | ' |?Has document URL\n' .. | ||
' |?Has document file\n' .. | |||
' |?Has document title\n' .. | |||
' |format=broadtable\n' .. | ' |format=broadtable\n' .. | ||
' |headers=hide\n' .. | ' |headers=hide\n' .. | ||
| Line 252: | Line 256: | ||
end | end | ||
-- cells[1] = page name, cells[2] = type, cells[3] = URL | -- cells[1] = page name, cells[2] = type, cells[3] = URL, cells[4] = file, cells[5] = title | ||
if #cells >= | if #cells >= 5 then | ||
local docType = cells[2] | local docType = cells[2] | ||
local docUrl = cells[3] | local docUrl = cells[3] | ||
local docFile = cells[4] | |||
local docTitle = cells[5] | |||
-- Determine what to link to (URL or file) | |||
local linkTarget = nil | |||
if docUrl and docUrl ~= '' then | if docUrl and docUrl ~= '' then | ||
local displayText = | linkTarget = docUrl | ||
elseif docFile and docFile ~= '' then | |||
-- Extract filename from "File:..." format | |||
local filename = docFile:match('File:(.+)') or docFile | |||
linkTarget = mw.uri.fullUrl('File:' .. filename) | |||
end | |||
if linkTarget then | |||
-- Determine display text priority: custom title > type | |||
local displayText = 'Document' | |||
if docTitle and docTitle ~= '' then | |||
displayText = docTitle | |||
elseif docType and docType ~= '' then | |||
displayText = docType | |||
end | |||
-- Create list item with link | -- Create list item with link | ||
local li = ul:tag('li') | local li = ul:tag('li') | ||
li:wikitext('[' .. | li:wikitext('[' .. linkTarget .. ' ' .. displayText .. ']') | ||
end | end | ||
end | end | ||