Module:TemplateStarter: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 88: | Line 88: | ||
local content = p.generateTemplate(templateType) | local content = p.generateTemplate(templateType) | ||
-- | -- Check if content is an error | ||
if content:match("^Error:") then | |||
return content | |||
end | |||
-- Create edit URL with | -- Create a simple edit URL with the content in the URL | ||
-- MediaWiki has limits on URL length, so we'll use a simpler approach | |||
local editUrl = mw.uri.fullUrl(articleName, { | local editUrl = mw.uri.fullUrl(articleName, { | ||
action = 'edit', | action = 'edit', | ||
summary = 'Creating new ' .. templateType .. ' page', | |||
preloadtext = content | |||
summary = 'Creating new ' .. templateType .. ' page' | |||
}) | }) | ||
| Line 105: | Line 106: | ||
'<p>Ready to create <b>%s</b> as a %s page.</p>' .. | '<p>Ready to create <b>%s</b> as a %s page.</p>' .. | ||
'<span class="plainlinks">[%s <span class="mw-ui-button mw-ui-progressive">Create Page</span>]</span>' .. | '<span class="plainlinks">[%s <span class="mw-ui-button mw-ui-progressive">Create Page</span>]</span>' .. | ||
'<div style="margin-top: 10px; padding: 10px; background: #f8f9fa; border: 1px solid #a2a9b1;">' .. | |||
'<small><b>Preview:</b></small>' .. | |||
'<pre style="margin-top: 5px;">%s</pre>' .. | |||
'</div>' .. | |||
'</div>', | '</div>', | ||
articleName, | articleName, | ||
templateType, | templateType, | ||
tostring(editUrl) | tostring(editUrl), | ||
mw.text.nowiki(content) | |||
) | ) | ||
end | |||
-- Create an InputBox-style form | |||
function p.createForm(frame) | |||
local args = frame.args | |||
local templateType = args.templateType or args[1] or "Person" | |||
-- Generate a unique ID for this form instance | |||
local formId = "templatestarter-" .. os.time() | |||
return string.format([[ | |||
<div class="template-starter-form"> | |||
<inputbox> | |||
type=create | |||
default=%s/ | |||
buttonlabel=Create %s Page | |||
placeholder=Enter page name... | |||
width=40 | |||
preload=Template:TemplateStarter/%s | |||
editintro=Template:TemplateStarter/EditIntro | |||
</inputbox> | |||
</div> | |||
]], templateType, templateType, templateType) | |||
end | end | ||