Editing Module:Navbar

From MINR.ORG WIKI

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
local getArgs
+
local HtmlBuilder = require('Module:HtmlBuilder')
  
function p._navbar(args)
+
function trim(s)
local titleArg = 1
+
    return mw.ustring.match( s, "^%s*(.-)%s*$" )
 +
end
  
if args.collapsible then
+
function error(s)
titleArg = 2
+
    local span = HtmlBuilder.create('span')
if not args.plain then
 
args.mini = 1
 
end
 
if args.fontcolor then
 
args.fontstyle = 'color:' .. args.fontcolor .. ';'
 
end
 
args.style = 'float:left; text-align:left'
 
end
 
  
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
+
    span
local title = mw.title.new(mw.text.trim(titleText), 'Template');
+
        .addClass('error')
 +
        .css('float', 'left')
 +
        .css('white-space', 'nowrap')
 +
        .wikitext('Error: ' .. s)
  
if not title then
+
    return tostring(span)
error('Invalid title ' .. titleText)
+
end
end
 
 
 
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
 
  
local div = mw.html.create():tag('div')
+
function _navbar( args )
div
+
    if not args[1] then
:addClass('plainlinks')
+
        return error('No name provided')
:addClass('hlist')
+
    end
:addClass('navbar')
+
:cssText(args.style)
+
    local title;
 
+
    local pageName = trim(args[1])
if args.mini then div:addClass('mini') end
+
    if mw.ustring.sub(pageName, 1, 1) == ':' then
 
+
        title = mw.title.new( mw.ustring.sub(pageName, 2) );
if not (args.mini or args.plain) then
+
    else
div
+
        title = mw.title.new( pageName, 'Template' );
:tag('span')
+
    end 
:css('word-spacing', 0)
+
    if not title then
:cssText(args.fontstyle)
+
        return error('Page does not exist')
:wikitext(args.text or 'This box:')
+
    end
:wikitext(' ')
+
end
+
    local mainpage = title.fullText;
 
+
    local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
if args.brackets then
+
    local editurl = title:fullUrl( 'action=edit' );
div
+
:tag('span')
+
    local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
:css('margin-right', '-0.125em')
+
    if args.mini then
:cssText(args.fontstyle)
+
        viewLink, talkLink, editLink = 'v', 't', 'e'
:wikitext('[ ')
+
    end
end
+
 
+
    local div = HtmlBuilder.create( 'div' )
local ul = div:tag('ul');
+
    div
 
+
        .addClass( 'noprint' )
ul
+
        .addClass( 'plainlinks' )
:tag('li')
+
        .addClass( 'hlist' )
:addClass('nv-view')
+
        .addClass( 'navbar')
:wikitext('[[' .. title.fullText .. '|')
+
        .cssText( args.style )
:tag(args.mini and 'abbr' or 'span')
+
:attr('title', 'View this template')
+
    if args.mini then div.addClass('mini') end
:cssText(args.fontstyle)
+
:wikitext(args.mini and 'v' or 'view')
+
    if not (args.mini or args.plain) then
:done()
+
        div
:wikitext(']]')
+
            .tag( 'span' )
:done()
+
                .css( 'word-spacing', 0 )
:tag('li')
+
                .cssText( args.fontstyle )
:addClass('nv-talk')
+
                .wikitext( args.text or 'This box:' )
:wikitext('[[' .. talkpage .. '|')
+
                .wikitext( ' ' )
:tag(args.mini and 'abbr' or 'span')
+
    end
:attr('title', 'Discuss this template')
+
:cssText(args.fontstyle)
+
    if args.brackets then
:wikitext(args.mini and 't' or 'talk')
+
        div
:done()
+
            .tag('span')
:wikitext(']]');
+
                .css('margin-right', '-0.125em')
 
+
                .cssText( args.fontstyle )
if not args.noedit then
+
                .wikitext( '[' )
ul
+
                .newline();
:tag('li')
+
    end
:addClass('nv-edit')
+
:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
+
    local ul = div.tag('ul');
:tag(args.mini and 'abbr' or 'span')
+
:attr('title', 'Edit this template')
+
    ul
:cssText(args.fontstyle)
+
        .tag( 'li' )
:wikitext(args.mini and 'e' or 'edit')
+
            .addClass( 'nv-view' )
:done()
+
            .wikitext( '[[' .. mainpage .. '|' )
:wikitext(']');
+
            .tag( 'span ' )
end
+
                .attr( 'title', 'View this template' )
 
+
                .cssText( args.fontstyle or '' )
if args.brackets then
+
                .wikitext( viewLink )
div
+
                .done()
:tag('span')
+
            .wikitext( ']]' )
:css('margin-left', '-0.125em')
+
            .done()
:cssText(args.fontstyle)
+
        .tag( 'li' )
:wikitext(' ]')
+
            .addClass( 'nv-talk' )
end
+
            .wikitext( '[[' .. talkpage .. '|' )
 
+
            .tag( 'span ' )
if args.collapsible then
+
                .attr( 'title', 'Discuss this template' )
div
+
                .cssText( args.fontstyle or '' )
:done()
+
                .wikitext( talkLink )
:tag('div')
+
                .done()
:css('font-size', '114%')
+
            .wikitext( ']]' );
:css('margin', args.mini and '0 4em' or '0 7em')
+
:cssText(args.fontstyle)
+
    if not args.noedit then  
:wikitext(args[1])
+
        ul
end
+
            .tag( 'li' )
 
+
                .addClass( 'nv-edit' )
return tostring(div:done())
+
                .wikitext( '[' .. editurl .. ' ' )
 +
                .tag( 'span ' )
 +
                    .attr( 'title', 'Edit this template' )
 +
                    .cssText( args.fontstyle or '' )
 +
                    .wikitext( editLink )
 +
                    .done()
 +
                .wikitext( ']' );
 +
    end
 +
 +
    if args.brackets then
 +
        div
 +
            .tag('span')
 +
                .css('margin-left', '-0.125em')
 +
                .cssText( args.fontstyle or '' )
 +
                .wikitext( ']' )
 +
                .newline();
 +
    end
 +
 +
    return tostring(div)
 
end
 
end
  
 
function p.navbar(frame)
 
function p.navbar(frame)
if not getArgs then
+
    local origArgs
getArgs = require('Module:Arguments').getArgs
+
    -- If called via #invoke, use the args passed into the invoking template.
end
+
    -- Otherwise, for testing purposes, assume args are being passed directly in.
return p._navbar(getArgs(frame))
+
    if frame == mw.getCurrentFrame() then
 +
        origArgs = frame:getParent().args
 +
    else
 +
        origArgs = frame
 +
    end
 +
 +
    -- ParserFunctions considers the empty string to be false, so to preserve the previous
 +
    -- behavior of {{navbar}}, change any empty arguments to nil, so Lua will consider
 +
    -- them false too.
 +
    args = {}
 +
    for k, v in pairs(origArgs) do
 +
        if v ~= '' then
 +
            args[k] = v
 +
        end
 +
    end
 +
 +
    return _navbar(args)
 
end
 
end
 
+
 
return p
 
return p

Please note that all contributions to MINR.ORG WIKI may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see MINR.ORG WIKI:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)