Module:TemplateStarter: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 66: | Line 66: | ||
end | end | ||
-- Generate a | -- Generate a form with copy-paste content | ||
function p.createLink(frame) | function p.createLink(frame) | ||
local args = frame.args | local args = frame.args | ||
| Line 93: | Line 93: | ||
end | end | ||
-- Create | -- Create edit URL (without preload since that doesn't work via URL) | ||
local editUrl = mw.uri.fullUrl(articleName, { | local editUrl = mw.uri.fullUrl(articleName, { | ||
action = 'edit', | action = 'edit', | ||
summary = 'Creating new ' .. templateType .. ' page' | summary = 'Creating new ' .. templateType .. ' page' | ||
}) | }) | ||
-- Return a button | -- Generate a unique ID for the textarea | ||
local textareaId = "template-content-" .. mw.hash.hashValue('md5', articleName .. templateType) | |||
-- Return a form with the content and a button | |||
return string.format( | return string.format( | ||
'<div class="template-starter-create">' .. | '<div class="template-starter-create" style="border: 1px solid #a2a9b1; padding: 15px; margin: 10px 0; background: #f8f9fa;">' .. | ||
'< | '<h4 style="margin-top: 0;">Create: %s</h4>' .. | ||
'< | '<p>Template type: <b>%s</b></p>' .. | ||
'<div style="margin | '<div style="margin: 10px 0;">' .. | ||
'< | '<label for="%s" style="display: block; margin-bottom: 5px;"><b>Step 1:</b> Copy this template code:</label>' .. | ||
'< | '<textarea id="%s" readonly style="width: 100%%; height: 200px; font-family: monospace; font-size: 12px;">%s</textarea>' .. | ||
'</div>' .. | '</div>' .. | ||
'<p><b>Step 2:</b> Click the button below to create the page, then paste the template code:</p>' .. | |||
'<span class="plainlinks">[%s <span class="mw-ui-button mw-ui-progressive">Create Page "%s"</span>]</span>' .. | |||
'</div>', | '</div>', | ||
articleName, | mw.text.nowiki(articleName), | ||
templateType, | templateType, | ||
textareaId, | |||
textareaId, | |||
mw.text.nowiki(content), | |||
tostring(editUrl), | tostring(editUrl), | ||
mw.text.nowiki( | mw.text.nowiki(articleName) | ||
) | ) | ||
end | |||
-- Generate a dynamic preload template | |||
function p.preload(frame) | |||
local args = frame.args | |||
local templateType = args.templateType or args[1] | |||
if not templateType then | |||
return "<!-- No template type specified -->" | |||
end | |||
return p.generateTemplate(templateType) | |||
end | end | ||