Toggle menu
15
236
70
27.5K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 20:24, 26 May 2025 by Prd (talk | contribs) (Created page with "-- <nowiki> -- -- Implements {{tnavbar}} and variants -- -- @todo move the hardcoded css to MediaWiki:Common.css given how many pages it's found on -- local p = {} local yesno = require( 'Module:Yesno' ) function p._navbar( args ) local tag tag = mw.html.create( 'div' ) :css( { ['background-color'] = 'transparent', padding = '0' } ) tag :addClass( 'plainlinks' ) :addClass( 'noprint' ) :...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


From https://kenshi.fandom.com/wiki/Module:Tnavbar


-- <nowiki>
--
-- Implements {{tnavbar}} and variants
--
-- @todo move the hardcoded css to [[MediaWiki:Common.css]] given how many pages it's found on
--

local p = {}
local yesno = require( 'Module:Yesno' )

function p._navbar( args )

    local tag


    tag = mw.html.create( 'div' )
        :css( {
            ['background-color'] = 'transparent',
            padding = '0'
        } )

    tag
        :addClass( 'plainlinks' )
        :addClass( 'noprint' )
        :css( {
            ['white-space'] = 'nowrap',
            ['font-weight'] = 'normal',
            ['font-size'] = 'xx-small'
        } )

    viewSpan = mw.html.create( 'span' )
        :attr( 'title', 'View this template' )
        :cssText( fontstyle )
        :wikitext( 'v' )

    talkSpan = mw.html.create( 'span' )
        :attr( 'title', 'Discussion about this template' )
        :cssText( fontstyle )
        :wikitext( 'd' )

    editSpan = mw.html.create( 'span' )
        :attr( 'title', 'You can edit this template. Please use the preview button before saving.' )
        :cssText( fontstyle )
        :wikitext( 'e' )

    

    local title = mw.text.trim( args[1] )
    local ns, titleTbl, page, talk

    if mw.ustring.sub( title, 1, 1 ) == ':' then
        -- mainspace
        title = mw.ustring.sub( title, 2 )
        page = title
        talk = 'Talk:' .. title

    elseif mw.ustring.match( title, ':' ) then
        -- split title to see if it has a valid namespace
        titleTbl = mw.text.split( title, ':' )
        ns = mw.site.namespaces[titleTbl[1]]

        if ns ~= nil then
            page = ns.name .. ':' .. table.concat( titleTbl, '', 2 )

            if ns.isTalk then
                talk = page
            else
                talk = ns.talk.name .. ':' .. table.concat( titleTbl, '', 2 )
            end
        end
    end

    -- this happens if there's no semi-colons in title
    -- or if there is semi-colons but it didn't have valid ns name
    if not page then
        page = 'Template:' .. title
        talk = 'Template talk:' .. title
    end

    tag
        :wikitext( '[[' .. page .. '|' .. tostring( viewSpan ) .. ']]' )
        :wikitext( '&nbsp;' )
        :tag( 'span' )
            :css( 'font-size', '80%' )
            :wikitext( '&bull;' )
            :done()
        :wikitext( '&nbsp;' )
        :wikitext( '[' .. tostring( mw.uri.fullUrl( talk ) ) .. ' ' .. tostring( talkSpan ) .. ']' )
        :wikitext( '&nbsp;' )
        :tag( 'span' )
            :css( 'font-size', '80%' )
            :wikitext( '&bull;' )
            :done()
        :wikitext( '&nbsp;' )
        :wikitext( '[' .. tostring( mw.uri.fullUrl( page, 'action=edit' ) ) .. ' ' .. tostring( editSpan ) .. ']' )

    return tostring( tag )
end


function p._collapsible( args )
    local nav_args = {
        [1] = args[2]
    }

    local div = mw.html.create( 'div' )
        :css( {
            float = 'left',
            ['text-align'] = 'left',
            width = '6em'
        } )
        :wikitext(p._navbar(nav_args))

    local span = mw.html.create('span'):wikitext(args[1])

    return tostring( div ) .. tostring( span )

end

return p