FANDOM


-- <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 = {
        ["&"] = "&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
-- </nowiki>
-- (Add categories here.)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.