Module:CRTModel: Difference between revisions

Undo revision 559 by Arclight (talk)
Tag: Undo
No edit summary
Tag: Reverted
Line 196: Line 196:
-- Documents section
-- Documents section
addSectionRow(container, 'Documents')
addSectionRow(container, 'Documents')
-- Build the upload link with UUID-like unique identifier
local timestamp = os.time()
local random = math.random(1000, 9999)
local target = pageName .. " - document " .. timestamp .. "-" .. random
local uploadUrl = mw.uri.fullUrl(
"Special:FormEdit",
{
form = "Document",
target = target,
["Document[crt_models]"] = pageName
}
)
-- Query for document count
-- Query for document count
Line 292: Line 279:
docsDiv:node(ul)
docsDiv:node(ul)
-- Add upload link as a button
-- Add upload link as a button with JavaScript UUID generation
local uploadDiv = mw.html.create('div')
local uploadDiv = mw.html.create('div')
uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center')
uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center')
uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]')
-- Use raw HTML with proper escaping
local jsCode = string.format(
[[javascript:(function(){var u='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(c){var r=Math.random()*16|0,v=c=='x'?r:(r&0x3|0x8);return v.toString(16);});window.location.href='/wiki/Special:FormEdit?form=Document&target=Document:'+u+'&Document[crt_models]=%s';})();]],
mw.uri.encode(pageName, 'PATH')
)
uploadDiv:wikitext(string.format(
'<a href="%s" style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;cursor:pointer;">Upload a document</a>',
jsCode
))
docsDiv:node(uploadDiv)
docsDiv:node(uploadDiv)
else
else
-- Just show the upload link as a button
-- Just show the upload link as a button with JavaScript UUID generation
local uploadDiv = mw.html.create('div')
local uploadDiv = mw.html.create('div')
uploadDiv:css('text-align', 'center')
uploadDiv:css('text-align', 'center')
uploadDiv:wikitext('[' .. tostring(uploadUrl) .. ' <span style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;">Upload a document</span>]')
-- Use raw HTML with proper escaping
local jsCode = string.format(
[[javascript:(function(){var u='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(c){var r=Math.random()*16|0,v=c=='x'?r:(r&0x3|0x8);return v.toString(16);});window.location.href='/wiki/Special:FormEdit?form=Document&target=Document:'+u+'&Document[crt_models]=%s';})();]],
mw.uri.encode(pageName, 'PATH')
)
uploadDiv:wikitext(string.format(
'<a href="%s" style="display:inline-block;padding:0.5rem 1rem;background-color:#eff6ff;color:#1d4ed8;border:1px solid #bfdbfe;border-radius:0.375rem;font-size:0.875rem;font-weight:500;text-decoration:none;cursor:pointer;">Upload a document</a>',
jsCode
))
docsDiv:node(uploadDiv)
docsDiv:node(uploadDiv)
MediaWiki Appliance - Powered by TurnKey Linux