Module:Tnavbar

From RuneRealm Wiki

This is an old revision of this page, as edited by Alex (talk | contribs) at 23:27, 11 October 2024 (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 -- require('strict') local p = {} local yesno = require( 'Module:Yesno' ) function p._navbar( args ) local navbarstyle = args.style or '' local fontstyle = args.fontstyle or '' local view, talk, edit = (args.view or true), (args.talk or true), (args.edit or true) local desc = { view = 'view', talk = 'talk', e..."). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Tnavbar/doc. [edit] [history] [purge]
Module:Tnavbar requires Module:Yesno.
Module:Tnavbar requires strict.

Generates {{Navbar}}. Most prominently used by Module:Navbox.


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

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

function p._navbar( args )
	local navbarstyle = args.style or ''
	local fontstyle = args.fontstyle or ''
	local view, talk, edit = (args.view or true), (args.talk or true), (args.edit or true)

	local desc = {
		view = 'view',
		talk = 'talk',
		edit = 'edit'
	}

	local tag = mw.html.create( 'div' )
		:addClass( 'navbar' )
		:addClass( 'plainlinks' )
		:addClass( 'noprint' )
		:css( {
			['white-space'] = 'nowrap',
			['font-weight'] = 'normal',
			['font-size'] = 'x-small'
		} )
		:cssText( navbarstyle )

	if yesno( args.mini ) then
		desc = {
			view = 'v',
			talk = 't',
			edit = 'e'
		}
		tag:addClass( 'navbar-mini' )
	end

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

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

	local editSpan = mw.html.create( 'span' )
		:attr( 'title', 'Edit this template' )
		:cssText( fontstyle )
		:wikitext( desc.edit )

	local title = args[1] and mw.text.trim( args[1] ) or error('No page title given')
	local ns, titleTbl, pagelink, talklink

	if mw.ustring.sub( title, 1, 1 ) == ':' then
		-- mainspace
		title = mw.ustring.sub( title, 2 )
		pagelink = title
		talklink = '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
			pagelink = ns.name .. ':' .. table.concat( titleTbl, '', 2 )

			if ns.isTalk then
				talklink = page
			else
				talklink = 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 pagelink then
		pagelink = 'Template:' .. title
		talklink = 'Template talk:' .. title
	end

	tag:wikitext( '[[' .. pagelink .. '|' .. tostring( viewSpan ) .. ']]' )
		:wikitext( '&nbsp;' )
		:tag( 'span' )
			:css( 'font-size', '80%' )
			:wikitext( '&bull;' )
			:done()
		:wikitext( '&nbsp;' )

	if talk == 'autoconfirmed' then
		tag
			:tag( 'span' )
				:addClass( 'autoconfirmed-show' )
				:css( 'display', 'none' )
				:wikitext( '[' .. tostring( mw.uri.fullUrl( talklink ) ) .. ' ' .. tostring( talkSpan ) .. ']' )
				:wikitext( '&nbsp;' )
				:tag( 'span' )
					:css( 'font-size', '80%' )
					:wikitext( '&bull;' )
					:done()
				:wikitext( '&nbsp;' )
				:done()
	elseif yesno(talk) then
		tag:wikitext( '[' .. tostring( mw.uri.fullUrl( talklink ) ) .. ' ' .. tostring( talkSpan ) .. ']' )
			:wikitext( '&nbsp;' )
			:tag( 'span' )
				:css( 'font-size', '80%' )
				:wikitext( '&bull;' )
				:done()
			:wikitext( '&nbsp;' )
			:done()
	end

	tag:wikitext( '[' .. tostring( mw.uri.fullUrl( pagelink, 'action=edit' ) ) .. ' ' .. tostring( editSpan ) .. ']' )

	return tostring( tag )
end

function p.navbar( frame )
	return p._navbar( frame:getParent().args )
end

return p