This module was made as a sandbox for the user DarthKitty. This documentation is kept to prevent redlinks.
-- <nowiki>
--------------------------------------------------------------------------------
-- 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 <http://stackoverflow.com/a/1091953>
local xmlEscapePattern = "[\"'<>&]"
local xmlEscapeTable = {
["&"] = "&",
['"'] = """,
["'"] = "'",
["<"] = "<",
[">"] = ">"
}
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
-- </nowiki>
-- (Add categories here.)