Jump to content

Module:Blocks: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Section edit links. If an external page is transcluded, the edit link goes to that page. If the content is on this page, it goes to the page-wide edit view. Not perfect but better than no links at all
the "[ edit ]" links should no longer be part of the heading itself
Line 23: Line 23:
:addClass('mw-editsection plainlinks')
:addClass('mw-editsection plainlinks')
:wikitext('[ [' .. encodedEditLink .. ' edit] ]')
:wikitext('[ [' .. encodedEditLink .. ' edit] ]')

local heading = mw.html.create('h2')
local heading = mw.html.create('h2')
:wikitext(sectionName .. ' ')
:wikitext(sectionName)
local headingContainer = mw.html.create('div')
:addClass('heading-container')
:node(heading)
:node(editButton)
:node(editButton)
pageDiv:node(heading)
pageDiv:node(headingContainer)
end
end



Revision as of 21:26, 11 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.fullUrl(pageName, {action = 'edit'})
            elseif content then
                editLink = mw.uri.fullUrl(mw.title.getCurrentTitle().prefixedText, {action = 'edit'})
            end
            local encodedEditLink = mw.text.encode(tostring(editLink))
            local editButton = mw.html.create('span')
                :addClass('mw-editsection plainlinks')
                :wikitext('[ [' .. encodedEditLink .. ' edit] ]')

            local heading = mw.html.create('h2')
                :wikitext(sectionName)
            
            local headingContainer = mw.html.create('div')
                :addClass('heading-container')
                :node(heading)
                :node(editButton)
                
            pageDiv:node(headingContainer)
        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