Jump to content

Module:Navigation header: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
local p = {}
local p = {}


function p.main(frame)
-- Import the standard icons and shortcut modules
local parent = frame:getParent()
local standardIcons = require('Module:Standard icons')
local pages = {}
local shortcut = require('Module:Shortcut')
local index = 1


while parent.args['page' .. index] or parent.args['content' .. index] do
function p.getIcon(key)
local iconTable = standardIcons.getIconTable()
local pageName = parent.args['page' .. index]
local content = parent.args['content' .. index]
return iconTable[key] or key
local sectionName = parent.args['section' .. index]
end
local pageDiv = mw.html.create('div'):addClass('blocks-block')


if sectionName then
function p.navigationHeader(frame)
local editLink
local parentFrame = frame:getParent()
if pageName then
local icon = {}
editLink = mw.uri.makeFullUrl(pageName, {action = 'edit', section = tostring(index)})
local label = {}
elseif content then
local itemType = {}
editLink = mw.uri.makeFullUrl(mw.title.getCurrentTitle().prefixedText, {action = 'edit', section = tostring(index)})
local i = 1
end
local editButton = mw.html.create('span')
:addClass('mw-editsection')
:wikitext('[' .. editLink .. ' edit]')
pageDiv:wikitext('\n==' .. sectionName .. '== ' .. tostring(editButton))
end


if pageName then
while parentFrame.args["icon" .. i] or parentFrame.args["type" .. i] or parentFrame.args["label" .. i] do
local transcludedContent = frame:expandTemplate{title = pageName}
icon[i] = parentFrame.args["icon" .. i] or p.getIcon(parentFrame.args["type" .. i])
label[i] = parentFrame.args["label" .. i] or ""
pageDiv:wikitext('\n' .. transcludedContent)
elseif content then
itemType[i] = parentFrame.args["type" .. i] or ""
i = i + 1
pageDiv:wikitext('\n' .. content)
end
end


table.insert(pages, pageDiv)
local theme = parentFrame.args["theme"] or "blue-theme"
index = index + 1
if theme ~= "gray-theme" and theme ~= "blue-theme" then
theme = "blue-theme"
end
end


local output = {}
if #pages == 0 then
return ''
output[#output + 1] = string.format('<div class="navigation-header %s"><div role="navigation" class="navigation-header-tabs">', theme)

-- Add shortcut box if shortcut parameter is provided
local shortcutParam = parentFrame.args["shortcut"]
if shortcutParam then
local shortcutBox = shortcut._main({shortcutParam})
output[#output + 1] = string.format('<div class="navigation-header-shortcut">%s</div>', shortcutBox)
end
end


local mainDiv = mw.html.create('div')
output[#output + 1] = '<ul>'
for _, pageDiv in ipairs(pages) do

mainDiv:node(pageDiv)
-- Add leadtab if leadtab-label is defined
local leadtabLabel = parentFrame.args["leadtab-label"]
if leadtabLabel then
local leadtabIcon = parentFrame.args["leadtab-icon"]
if leadtabIcon then
output[#output + 1] = string.format(
'<li id="leadtab"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
leadtabIcon,
leadtabLabel
)
else
output[#output + 1] = string.format(
'<li id="leadtab">%s</li>',
leadtabLabel
)
end
end
end


return tostring(mainDiv)
for j = 1, #icon do
output[#output + 1] = string.format(
'<li id="%s"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
itemType[j],
icon[j],
label[j]
)
end

output[#output + 1] = '</ul>'
output[#output + 1] = '</div></div>'

return table.concat(output, '\n')
end
end



Revision as of 23:07, 9 May 2023

local p = {}

function p.main(frame)
    local parent = frame:getParent()
    local pages = {}
    local index = 1

    while parent.args['page' .. index] or parent.args['content' .. index] do
        local pageName = parent.args['page' .. index]
        local content = parent.args['content' .. index]
        local sectionName = parent.args['section' .. index]
        local pageDiv = mw.html.create('div'):addClass('blocks-block')

        if sectionName then
            local editLink
            if pageName then
                editLink = mw.uri.makeFullUrl(pageName, {action = 'edit', section = tostring(index)})
            elseif content then
                editLink = mw.uri.makeFullUrl(mw.title.getCurrentTitle().prefixedText, {action = 'edit', section = tostring(index)})
            end
            local editButton = mw.html.create('span')
                :addClass('mw-editsection')
                :wikitext('[' .. editLink .. ' edit]')
            pageDiv:wikitext('\n==' .. sectionName .. '== ' .. tostring(editButton))
        end

        if pageName then
            local transcludedContent = frame:expandTemplate{title = pageName}
            pageDiv:wikitext('\n' .. transcludedContent)
        elseif content then
            pageDiv:wikitext('\n' .. content)
        end

        table.insert(pages, pageDiv)
        index = index + 1
    end

    if #pages == 0 then
        return ''
    end

    local mainDiv = mw.html.create('div')
    for _, pageDiv in ipairs(pages) do
        mainDiv:node(pageDiv)
    end

    return tostring(mainDiv)
end

return p