Module:Sandbox/DarthKitty/Automation

--

-- Describe the following module here.

local p = {}

-- Admins can create a large number of pages simultaneously by "importing" some -- bare-bones XML. This function makes the process easier by checking for -- invalid title characters and escaping text when necessary. -- -- @example -- mw.html.create("mediawiki"):node(p.makePage("title", "content")) -- -- @example (@TODO) -- p.xml:page("title", "content")

function p.makePage(title, content) -- Warn users about problematic chatacters in titles -- @see Wikipedia:Wikipedia:Naming conventions (technical restrictions) -- @TODO: improve this local badTitleChar = title:match("[#<>[%]|{}]")

if badTitleChar then error('the character "' .. badTitleChar .. '" is not allowed in page titles') end

-- Escape characters for XML when necessary -- @see  local xmlEscapePattern = "[\"'<>&]"   local xmlEscapeTable = {        ["&"] = "&amp;",        ['"'] = "&quot;", ["'"] = "&apos;", ["<"] = "&lt;", [">"] = "&gt;" }

local escapedTitle = title:gsub(xmlEscapePattern, xmlEscapeTable) local escapedContent = content:gsub(xmlEscapePattern, xmlEscapeTable)

return mw.html.create("page") :tag("title") :wikitext(escapedTitle) :done :tag("revision") :tag("text") :attr("xml:space", "preserve") :wikitext(escapedContent) :done :done :done end

return p -- -- (Add categories here.)