FANDOM


-- <pre> Creates standard help for mentoring... 
-- Probably could make this more general to cover many types
local docs = {}
local getArgs = require("Module:Arguments").getArgs
local i18n = require("Module:Help/i18n")
local html = mw.html
local contentLanguage = mw.getContentLanguage():getCode()
 
-- Entry point
function docs.main(frame)
    local args = getArgs(frame)
    local source = args.source
    local uselang = args.uselang
 
    return docs.createDocs( source, uselang)
end
 
--Creates docs
--@parameters 
--source (string) : custom code to use modules
--uselang (string): localization for the module text stored in /i18n subpage
function docs.createDocs(source, uselang)
    contentLanguage = uselang or contentLanguage 
 
    local moduleName = tostring(mw.title.getCurrentTitle().subpageText or "")
    local nodeInstructions = mw.html.create("div")
    local messages, messageType, messageLang, nodeContent,
         headerNode, code, heading, lang, instruction,uncollapsedNode
    local messages = {
        "main",
        "explanation",
        "infobox",
        "mainpage",
        "styling"
    }
    local isCollapsed = false
 
    for key, messageName in ipairs(messages) do
 
        if messageName == "main" then
            headerNode = createHeader(getMessage(messageName, "header" , contentLanguage))
        else 
            instruction =  getMessage(messageName, "instruction", contentLanguage)
            code = getMessage(messageName, "code", contentLanguage)
            heading = getMessage(messageName, "header", contentLanguage)
            lang = getMessage(messageName, "codelang", contentLanguage)
            nodeContent = createInstructions(instruction, code, heading, lang)
 
            if not isCollapsed then
                uncollapsedNode = nodeContent
                isCollapsed = true
            else
                nodeInstructions:node(nodeContent)
            end
        end
    end
 
    if source then
        local nodeOtherDocs = createInstructions("Other instructions",source, "Other information")
 
        nodeInstructions:node(nodeOtherDocs)
    end
 
    local fullInstructions = createCollapse(tostring(headerNode) .. tostring(uncollapsedNode), nodeInstructions)
 
    return fullInstructions
end
 
function getMessage(msg,msgType, lang)
    return i18n["docs_"..msg .. "_" .. msgType .. "_" .. (lang or "en")]
end
-- creates a simple header (makes it easier to understand code and style differently)
function createHeader(text)
    local styles = {
        clear = "both", margin= "1em auto", ["border-left"]= "10px solid #228b22", 
        ["border-right"]= "10px solid #228b22", ["border-radius"] ="10px", 
        ["background-color"] = "#228b22",
        ["color"] = "white",
        ["text-align"] = "center"
    }
    local header = html.create("h2")
        :addClass("help-docs")
 
    for style,attribute in pairs(styles) do
        header:css(style,attribute)
    end
 
    return tostring(header:wikitext(text))
end
-- Creates instructions along with the code and heading
function createInstructions(instruction, code, heading, lang)
    local createTag = mw.html.create
    local nodeContainer = createTag("div")
    local nodeHeader =  createTag("h3")
    local nodeCode = createTag("div")
    local nodeInstruction = createTag("div")
    local styles = {
        clear = "both", margin= "1em auto", ["border-left"]= "10px solid #228b22", 
        ["border-right"]= "10px solid #228b22", ["border-radius"] ="10px", 
        ["background-color"] = "rgb(242, 242, 242)"
    }
 
    for style,attribute in pairs(styles) do
        nodeContainer:css(style,attribute)
    end
 
    if instruction and  heading then
        instruction = replaceVariables(instruction)
        code = replaceVariables(code or "")
        heading = replaceVariables(heading)
 
        nodeHeader:css("text-align","center")
        nodeHeader:wikitext(heading)
        nodeInstruction:wikitext(instruction)
        nodeContainer:node(nodeHeader)
        nodeContainer:node(nodeInstruction)
 
        if code ~= "" then
            nodeCode:wikitext(preprocess(
                [[<source lang="]]..(lang or "xml")..[[">]].. code .."</source>"))
            nodeContainer:node(nodeCode)
        end
    else
        mw.log("Missing messages (instruction, code, heading):\ninstruction:".. (instruction or " nil")
            .. "\ncode: ".. (code or " nil") .. "\nheading:" .. (heading or " nil"))
    end
 
    return nodeContainer
end
 
function replaceVariables(text)
    local pageName = tostring(mw.title.getCurrentTitle().subpageText or "")
    text = text:gsub("$1", pageName)
 
    return text
end
 
function createCollapse(displayed, collapsed)
    local collapsedDiv = mw.html.create("div")
 
    collapsedDiv:addClass("mw-collapsible mw-collapsed")
        :wikitext(tostring(displayed))
    collapsedDiv:tag("div")
        :addClass("mw-collapsible-content")
        :wikitext(tostring(collapsed))
 
    return collapsedDiv
end
-- useful for debugging and testing in console.
function preprocess(text)
    if mw.getCurrentFrame() then
        return mw.getCurrentFrame():preprocess(text)
    end
 
    return text
end
return docs

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.